From 92acff884be516491269a1624db9cae4ec0c5e67 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 5 May 2019 13:25:39 +1000 Subject: [PATCH] oceani-tests: add tests for bad command line args. Ensuring the correct behaviour with bad command line args helps increase coverage. Signed-off-by: NeilBrown --- csrc/oceani-tests.mdc | 52 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index dc5a706..78986fc 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -34,6 +34,7 @@ arguments separated from the name by commas. For each test, there is a section ###### File: oceani-tests.mk oceani_tests := + ## test list tests:: oceani_test_suite oceani_test_suite: oceani coverage_oceani @@ -60,6 +61,9 @@ arguments separated from the name by commas. For each test, there is a section ./coverage_oceani --print --section "test: $$t" oceani-tests.mdc $${1+"$$@"} > /dev/null ; \ ./coverage_oceani -tpbn --section "test: $$t" oceani-tests.mdc > /dev/null 2>&1; \ done + + ## test code + @gcov -o coverage oceani.mdc > /dev/null 2> /dev/null @mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage @ awk '/^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \ @@ -71,8 +75,6 @@ arguments separated from the name by commas. For each test, there is a section coverage_oceani: oceani.c $(CC) $(CFLAGS) --coverage -fprofile-dir=coverage -o coverage_oceani oceani.c $(LDLIBS) - ## test list - ## Values and variables The first test stores values in variables and performs various @@ -391,3 +393,49 @@ Here I break it into two parts, keeping the array code separate. list[ 53 ]= 9040 list[ 54 ]= 9768 +## Test erroneous command line args + +To improve coverage, we want to test correct handling of strange command +line arguments. These tests won't use code, so the exiting test types +won't work. So we need to be able to explicitly give the command line, +and the expected output, and have that tested and the coverage assessed. +Rather than having to spell out the whole command name, just give "cmd", +and discard that. Requiring but discarding the command make an empty +command list possible. + +###### test code + @for t in $(oceani_special_tests); do \ + echo -n "Test $$t ... ";\ + i="$$IFS"; IFS=,; set $$t; IFS="$$i"; shift ;\ + ./md2c oceani-tests.mdc "output: $$t" | grep -v '^#' > .tmp.want; \ + ./oceani $${1+"$$@"} > .tmp.have 2>&1 ;\ + if ! cmp -s .tmp.want .tmp.have; then \ + echo "FAILED"; diff -u .tmp.want .tmp.have ; exit 1; fi ;\ + echo "passed"; \ + ./coverage_oceani $${1+"$$@"} > /dev/null 2>&1 ;\ + done || true + + +###### test list + oceani_special_tests += "cmd" + oceani_special_tests += "cmd,-zyx" + oceani_special_tests += "cmd,nofile" + oceani_special_tests += "cmd,/dev/null" + oceani_special_tests += "cmd,--section,toast:nothing,oceani-tests.mdc" + +###### output: cmd + oceani: no input file given + +###### output: cmd,-zyx + ./oceani: invalid option -- 'z' + Usage: oceani --trace --print --noexec --brackets--section=SectionName prog.ocn + +###### output: cmd,nofile + oceani: cannot open nofile + +###### output: cmd,/dev/null + oceani: could not find any code in /dev/null + +###### output: cmd,--section,toast:nothing,oceani-tests.mdc + oceani: cannot find section toast:nothing + -- 2.43.0