Skip to content

Commit 2270f73

Browse files
committed
Check completeness of help output in CI
This commit adds a new script to run post-build that assesses the completeness of --help for all binaries except for goto-cc.
1 parent ec66d39 commit 2270f73

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
make -C jbmc/unit -j2 CXX="ccache g++" LIBS="$PWD/riss.git/release/lib/libriss-coprocessor.a -lpthread" IPASIR=$PWD/riss.git/riss
5656
- name: Print ccache stats
5757
run: ccache -s
58+
- name: Checking completeness of help output
59+
run: scripts/check_help.sh
5860
- name: Run unit tests
5961
run: |
6062
make -C unit test IPASIR=$PWD/riss.git/riss
@@ -233,6 +235,8 @@ jobs:
233235
run: cd build; ninja -j2
234236
- name: Print ccache stats
235237
run: ccache -s
238+
- name: Checking completeness of help output
239+
run: scripts/check_help.sh build/bin
236240
- name: Check if package building works
237241
run: |
238242
cd build

scripts/check_help.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# if a command-line argument is provided, use it as a path to built binaries
6+
# (CMake-style build); otherwise assume we use Makefile-based in-tree build
7+
if [ $# -eq 1 ] ; then
8+
bin_dir=$(cd $1 ; pwd)
9+
else
10+
unset bin_dir
11+
fi
12+
echo $bin_dir
13+
14+
# make sure we execute the remainder in the directory containing this script
15+
cd `dirname $0`
16+
17+
missing_options=0
18+
19+
# we don't check goto-cc for now
20+
# we omit crangler for it doesn't take options other than help or a file name
21+
for t in \
22+
../jbmc/src/janalyzer \
23+
../jbmc/src/jbmc \
24+
../jbmc/src/jdiff \
25+
../src/cbmc \
26+
../src/goto-analyzer \
27+
../src/goto-diff \
28+
../src/goto-harness \
29+
../src/goto-instrument \
30+
../src/memory-analyzer \
31+
../src/symtab2gb \
32+
; do
33+
tool_name=$(basename $t)
34+
opt_name=$(echo $tool_name | tr 'a-z-' 'A-Z_')
35+
echo "Extracting the raw list of parameters from $tool_name"
36+
g++ -E -dM -std=c++11 -I../src -I../jbmc/src $t/*_parse_options.cpp -o macros.c
37+
# goto-analyzer partly uses the spelling "analyser" within the code base
38+
echo ${opt_name}_OPTIONS | sed 's/GOTO_ANALYZER/GOTO_ANALYSER/' >> macros.c
39+
rawstring="`gcc -E -P -w macros.c` \"?h(help)\""
40+
rm macros.c
41+
42+
# now the main bit, convert from raw format to a proper list of switches
43+
cleanstring=`(
44+
# extract 2-hyphen switches, such as --foo
45+
# grep for '(foo)' expressions, and then use sed to remove parantheses and
46+
# put '-' at the start (we accept both --X and -X)
47+
(echo $rawstring | grep -o "([^)]*)" | sed "s/^.\(.*\).$/-\1/") ;
48+
# extract 1-hyphen switches, such as -F
49+
# use sed to remove all (foo) expressions, then you're left with switches
50+
# and ':', so grep the colons out and then use sed to include the '-'
51+
(echo $rawstring | sed "s/([^)]*)//g" | grep -o "[a-zA-Z0-9?]" | sed "s/\(.*\)/-\1/")
52+
) | sed 's/" "//g'`
53+
54+
if [ "x$bin_dir" = "x" ] ; then
55+
if [ ! -x $t/$tool_name ] ; then
56+
echo "$t/$tool_name is not an executable"
57+
exit 1
58+
fi
59+
$t/$tool_name --help > help_string
60+
else
61+
if [ ! -x $bin_dir/$tool_name ] ; then
62+
echo "$bin_dir/$tool_name is not an executable"
63+
exit 1
64+
fi
65+
$bin_dir/$tool_name --help > help_string
66+
fi
67+
for opt in $cleanstring ; do
68+
if ! grep -q -- $opt help_string ; then
69+
echo "Option $opt of $tool_name is undocumented"
70+
missing_options=1
71+
fi
72+
done
73+
rm help_string
74+
done
75+
76+
if [ $missing_options -eq 1 ] ; then
77+
echo "Undocumented options found"
78+
exit 1
79+
else
80+
echo "All options are documented"
81+
exit 0
82+
fi

0 commit comments

Comments
 (0)