From 28603b02b784a0c16840ad9fe0e3752d0eeb6f36 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 19 Jul 2022 11:45:31 -0500 Subject: [PATCH] Add skeleton.tests for lib/args.c test coverage. --- tests/skeleton.test | 27 +++++++++++++++++++++++++++ toys/example/skeleton.c | 3 --- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 tests/skeleton.test diff --git a/tests/skeleton.test b/tests/skeleton.test new file mode 100755 index 00000000..c4df95e8 --- /dev/null +++ b/tests/skeleton.test @@ -0,0 +1,27 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# This is basically a test of lib/args.c argument parsing + +out() { printf 'Ran skeleton\n%sOther globals should start zeroed: ' "$@";} +testcmd "baseline " "" "$(out '')0\n" "" "" +testcmd "unknown" "-z |& grep -o Unknown" "Unknown\n" "" "" +testcmd "passthrough args" "bingeley bongeley beep" \ + "$(out 'optarg=bingeley\noptarg=bongeley\noptarg=beep\n')0\n" "" "" +testcmd "" "-a" "$(out 'flags=1\nSaw a\n')0\n" "" "" +testcmd "" "-b |& grep -o Missing" "Missing\n" "" "" +testcmd "" "-b abc" "$(out 'flags=2\nb=abc\n')0\n" "" "" +testcmd "" "-c nondigit |& grep -o integer" "integer\n" "" "" +testcmd "" "-c 123" "$(out 'flags=4\nc=123\n')0\n" "" "" +testcmd "" "-c 1m" "$(out 'flags=4\nc=1048576\n')0\n" "" "" +testcmd "" "-d one -d two -d 3,4" "$(out 'flags=8\nd=one\nd=two\nd=3,4\n')0\n" \ + "" "" +testcmd "" "-e" "$(out 'flags=10\ne was seen 1 times\n')0\n" "" "" +testcmd "" "-ee -e -ae" "$(out 'flags=11\nSaw a\ne was seen 4 times\n')0\n" \ + "" "" +testcmd "mixed" "123 -c 456 789" \ + "$(out 'flags=4\nc=456\noptarg=123\noptarg=789\n')0\n" "" "" + diff --git a/toys/example/skeleton.c b/toys/example/skeleton.c index 54080686..9282ea5e 100644 --- a/toys/example/skeleton.c +++ b/toys/example/skeleton.c @@ -61,9 +61,6 @@ GLOBALS( int more_globals; ) -// Don't blindly build allyesconfig. The maximum _sane_ config is defconfig. -#warning skeleton.c is just an example, not something to deploy. - // Parse many different kinds of command line argument: void skeleton_main(void) { -- 2.39.2