Skip to content

Commit e4942bf

Browse files
committed
contrib/completion: add a test for bash completion
At least one test per tool, plus some others for special cases. Not perfect because we're not inside an actual completion context, but still good. Only runs during make check on Linux, since we already assume bash is available elsewhere. This will also likely fail with bash<4 but even Debian 6 and Redhat 6 had bash 4 already. Refs #673 Signed-off-by: Brice Goglin <[email protected]>
1 parent 52d5db3 commit e4942bf

File tree

3 files changed

+170
-3
lines changed

3 files changed

+170
-3
lines changed

config/hwloc_internal.m4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dnl -*- Autoconf -*-
22
dnl
3-
dnl Copyright © 2010-2023 Inria. All rights reserved.
3+
dnl Copyright © 2010-2024 Inria. All rights reserved.
44
dnl Copyright © 2009, 2011 Université Bordeaux
55
dnl Copyright © 2004-2005 The Trustees of Indiana University and Indiana
66
dnl University Research and Technology
@@ -514,6 +514,7 @@ int foo(void) {
514514
hwloc_config_prefix[contrib/hwloc-ps.www/Makefile]
515515
hwloc_config_prefix[contrib/systemd/Makefile]
516516
hwloc_config_prefix[contrib/completion/Makefile]
517+
hwloc_config_prefix[contrib/completion/test-bash-completion.sh]
517518
hwloc_config_prefix[contrib/misc/Makefile]
518519
hwloc_config_prefix[contrib/windows/Makefile]
519520
)
@@ -539,7 +540,8 @@ int foo(void) {
539540
hwloc_config_prefix[utils/hwloc/test-parsing-flags.sh] \
540541
hwloc_config_prefix[utils/hwloc/test-hwloc-dump-hwdata/test-hwloc-dump-hwdata.sh] \
541542
hwloc_config_prefix[utils/lstopo/test-lstopo.sh] \
542-
hwloc_config_prefix[utils/lstopo/test-lstopo-shmem.sh])
543+
hwloc_config_prefix[utils/lstopo/test-lstopo-shmem.sh] \
544+
hwloc_config_prefix[contrib/completion/test-bash-completion.sh])
543545
544546
# These links are only needed in standalone mode. It would
545547
# be nice to m4 foreach this somehow, but whenever I tried

contrib/completion/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Copyright © 2009-2020 Inria. All rights reserved.
1+
# Copyright © 2009-2024 Inria. All rights reserved.
22
#
33
# See COPYING in top-level directory.
44

55
# This makefile is only reached when building in standalone mode
66

77
bashcompletionsdir = $(datadir)/bash-completion/completions
88
dist_bashcompletions_DATA = bash/hwloc
9+
10+
if HWLOC_HAVE_LINUX
11+
TESTS = test-bash-completion.sh
12+
endif
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!@BASH@
2+
3+
#
4+
# Copyright © 2024 Inria. All rights reserved.
5+
# See COPYING in top-level directory.
6+
#
7+
8+
set -e
9+
10+
# the real _filedir() defined in /usr/share/bash-completion/bash_completion seems to fail here,
11+
# and we won't actually test it anyway, so just redefine it to empty
12+
_filedir() {
13+
return
14+
}
15+
16+
# the real compopt doesn't work outside of actual completion
17+
compopt() {
18+
return
19+
}
20+
21+
# load completions
22+
HWLOC_top_srcdir="@HWLOC_top_srcdir@"
23+
source $HWLOC_top_srcdir/contrib/completion/bash/hwloc
24+
25+
COMP_WORDS=( "lstopo" "--o" )
26+
COMP_CWORD=${#COMP_WORDS[*]}-1
27+
echo "Completing ${COMP_WORDS[*]}<tab>"
28+
_lstopo
29+
echo "Got ${COMPREPLY[*]}"
30+
test "${COMPREPLY[*]}" == "--os-index-prefix --output-format --of --osf --obj-snprintf-flags --only"
31+
echo "OK"
32+
33+
COMP_WORDS=( "lstopo" "--palette" "" )
34+
COMP_CWORD=${#COMP_WORDS[*]}-1
35+
echo "Completing ${COMP_WORDS[*]}<tab>"
36+
_lstopo
37+
echo "Got ${COMPREPLY[*]}"
38+
test "${COMPREPLY[*]}" == "grey greyscale default colors white none"
39+
echo "OK"
40+
41+
COMP_WORDS=( "lstopo" "--filter" "i" )
42+
COMP_CWORD=${#COMP_WORDS[*]}-1
43+
echo "Completing ${COMP_WORDS[*]}<tab>"
44+
_lstopo
45+
echo "Got ${COMPREPLY[*]}"
46+
test "${COMPREPLY[*]}" == "icache: io:"
47+
echo "OK"
48+
49+
# "--filter type:kind" must be split into "--filter" "type" ":" "kind" outside of actual completion
50+
COMP_WORDS=( "lstopo" "--filter" "io" ":" "" )
51+
COMP_CWORD=${#COMP_WORDS[*]}-1
52+
echo "Completing ${COMP_WORDS[*]}<tab>"
53+
_lstopo
54+
echo "Got ${COMPREPLY[*]}"
55+
test "${COMPREPLY[*]}" == "none all structure important"
56+
echo "OK"
57+
58+
# "--foo=bar" must be split into "--foo" "=" "bar" outside of actual completion
59+
COMP_WORDS=( "lstopo" "--horiz" "=" "M" )
60+
COMP_CWORD=${#COMP_WORDS[*]}-1
61+
echo "Completing ${COMP_WORDS[*]}<tab>"
62+
_lstopo
63+
echo "Got ${COMPREPLY[*]}"
64+
test "${COMPREPLY[*]}" == "Machine Misc MemCache"
65+
echo "OK"
66+
67+
COMP_WORDS=( "hwloc-info" "--ancestor" )
68+
COMP_CWORD=${#COMP_WORDS[*]}-1
69+
echo "Completing ${COMP_WORDS[*]}<tab>"
70+
_hwloc_info
71+
echo "Got ${COMPREPLY[*]}"
72+
test "${COMPREPLY[*]}" == "--ancestors --ancestor"
73+
echo "OK"
74+
75+
COMP_WORDS=( "hwloc-info" "--ancestor" "P" )
76+
COMP_CWORD=${#COMP_WORDS[*]}-1
77+
echo "Completing ${COMP_WORDS[*]}<tab>"
78+
_hwloc_info
79+
echo "Got ${COMPREPLY[*]}"
80+
test "${COMPREPLY[*]}" == "Package PCIDev PU"
81+
echo "OK"
82+
83+
COMP_WORDS=( "hwloc-bind" "--membind" "--get" "--cof" "" )
84+
COMP_CWORD=${#COMP_WORDS[*]}-1
85+
echo "Completing ${COMP_WORDS[*]}<tab>"
86+
_hwloc_bind
87+
echo "Got ${COMPREPLY[*]}"
88+
test "${COMPREPLY[*]}" == "hwloc list taskset"
89+
echo "OK"
90+
91+
COMP_WORDS=( "hwloc-calc" "--cpukind" "" )
92+
COMP_CWORD=${#COMP_WORDS[*]}-1
93+
echo "Completing ${COMP_WORDS[*]}<tab>"
94+
_hwloc_calc
95+
echo "Got ${COMPREPLY[*]}"
96+
test "${COMPREPLY[*]}" == "<name>=<value> <n> "
97+
echo "OK"
98+
99+
COMP_WORDS=( "hwloc-annotate" "-" )
100+
COMP_CWORD=${#COMP_WORDS[*]}-1
101+
echo "Completing ${COMP_WORDS[*]}<tab>"
102+
_hwloc_annotate
103+
echo "Got ${COMPREPLY[*]}"
104+
test "${COMPREPLY[*]}" = "--ci --ri --cu --cd --version -h --help"
105+
echo "OK"
106+
107+
COMP_WORDS=( "hwloc-diff" "--re" )
108+
COMP_CWORD=${#COMP_WORDS[*]}-1
109+
echo "Completing ${COMP_WORDS[*]}<tab>"
110+
_hwloc_diff
111+
echo "Got ${COMPREPLY[*]}"
112+
test "${COMPREPLY[*]}" = "--refname"
113+
echo "OK"
114+
115+
COMP_WORDS=( "hwloc-patch" "--" )
116+
COMP_CWORD=${#COMP_WORDS[*]}-1
117+
echo "Completing ${COMP_WORDS[*]}<tab>"
118+
_hwloc_patch
119+
echo "Got ${COMPREPLY[*]}"
120+
test "${COMPREPLY[*]}" = "--reverse --version --help"
121+
echo "OK"
122+
123+
COMP_WORDS=( "hwloc-compress-dir" "--v" )
124+
COMP_CWORD=${#COMP_WORDS[*]}-1
125+
echo "Completing ${COMP_WORDS[*]}<tab>"
126+
_hwloc_compress_dir
127+
echo "Got ${COMPREPLY[*]}"
128+
test "${COMPREPLY[*]}" = "--verbose --version"
129+
echo "OK"
130+
131+
COMP_WORDS=( "hwloc-distrib" "--if" "" )
132+
COMP_CWORD=${#COMP_WORDS[*]}-1
133+
echo "Completing ${COMP_WORDS[*]}<tab>"
134+
_hwloc_distrib
135+
echo "Got ${COMPREPLY[*]}"
136+
test "${COMPREPLY[*]}" = "xml synthetic fsroot cpuid"
137+
echo "OK"
138+
139+
COMP_WORDS=( "hwloc-ps" "--children-of-pid" "" )
140+
COMP_CWORD=${#COMP_WORDS[*]}-1
141+
echo "Completing ${COMP_WORDS[*]}<tab>"
142+
_hwloc_ps
143+
echo "Got ${COMPREPLY[*]}"
144+
test "${COMPREPLY[*]}" = "<pid> "
145+
echo "OK"
146+
147+
COMP_WORDS=( "hwloc-gather-cpuid" "-c" "" )
148+
COMP_CWORD=${#COMP_WORDS[*]}-1
149+
echo "Completing ${COMP_WORDS[*]}<tab>"
150+
_hwloc_gather_cpuid
151+
echo "Got ${COMPREPLY[*]}"
152+
test "${COMPREPLY[*]}" = "<index of cpu to operate on> "
153+
echo "OK"
154+
155+
COMP_WORDS=( "hwloc-gather-topology" "-" )
156+
COMP_CWORD=${#COMP_WORDS[*]}-1
157+
echo "Completing ${COMP_WORDS[*]}<tab>"
158+
_hwloc_gather_topology
159+
echo "Got ${COMPREPLY[*]}"
160+
test "${COMPREPLY[*]}" = "--io --dmi --dt --no-cpuid --keep --version -h --help"
161+
echo "OK"

0 commit comments

Comments
 (0)