summaryrefslogtreecommitdiff
path: root/test/command-parsing.sh
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2019-06-05 09:56:13 +0300
committerTimo Teräs <timo.teras@iki.fi>2019-06-05 09:56:13 +0300
commit366d0ee371ac6fc00617324c122e058dc8e5bea3 (patch)
tree025e37a043e65ef06575a599f610e2079651124b /test/command-parsing.sh
parentc3a93a4aa588f237690953fc74011c3bd00ed2ae (diff)
downloadapk-tools-366d0ee371ac6fc00617324c122e058dc8e5bea3.tar.gz
apk-tools-366d0ee371ac6fc00617324c122e058dc8e5bea3.tar.bz2
apk-tools-366d0ee371ac6fc00617324c122e058dc8e5bea3.tar.xz
apk-tools-366d0ee371ac6fc00617324c122e058dc8e5bea3.zip
print usage and exit with error on invalid arguments
Add also some testing to make sure help, long help and handling of invalid arguments works as expected. Based on pull request #19 originally by Laurent Arnoud (@spk).
Diffstat (limited to 'test/command-parsing.sh')
-rwxr-xr-xtest/command-parsing.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/command-parsing.sh b/test/command-parsing.sh
new file mode 100755
index 0000000..008cb77
--- /dev/null
+++ b/test/command-parsing.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+fail=0
+
+help_output=$(../src/apk version --help 2>/dev/null)
+invalid_option_output="$(../src/apk --invalid-option version 2>/dev/null)"
+if [ "$help_output" != "$invalid_option_output" ]; then
+ echo "FAIL: invalid option does not trigger help"
+ fail=$((fail+1))
+fi
+
+if ! ../src/apk --help 2>/dev/null | grep -q "^Use apk --help --verbose for a full command listing."; then
+ echo "FAIL: brief help gives long help"
+ fail=$((fail+1))
+fi
+
+if ../src/apk --help --verbose 2>/dev/null | grep -q "^Use apk --help --verbose for a full command listing."; then
+ echo "FAIL: long help does not work"
+ fail=$((fail+1))
+fi
+
+if [ $fail -eq 0 ]; then
+ echo "OK: command parsing works"
+fi
+
+exit $fail