-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_standards
executable file
·72 lines (59 loc) · 2.16 KB
/
check_standards
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# This script exists to save and exhibit the results of several
# command line programs with proper and improper arguments.
#
# The purpose of these tests is to see how well-known commands
# handle ambiguous situations so I can respond in familiar ways
# to similar inputs.
#
# If new experiences suggest new pitfalls, it should be easy to
# add new tests to confirm the responses of well-known programs.
# enum colors: { black=0, red, green, brown, blue, magenta, cyan, white }
colargs="[36;1m" # cyan
colerr="[31;1m" # bold red
colerr2="[31;2m" # normal red
colsuccess="[32;1m" # green
colannounce="[34;1m" # blue
coloff="[m"
announce_test()
{
echo -n "[2J[0;0d"
echo
echo "${colannounce}${1}[m"
}
intertest_pause()
{
local dummy
echo
read -n1 -pPress\ ENTER\ for\ the\ next\ test. dummy
}
run_test()
{
local -a args=( "$@" )
echo "Running test with ${colargs}${args[0]}${coloff}. (${#args[@]})"
echo "${colargs}${args[@]}${coloff}"
echo
"${args[@]}" 2> >(while read line; do echo -e "${colerr}stderr:${colerr2} $line${coloff}" >&2; done)
if [ "$?" -eq 0 ]; then
echo "${colsuccess}Program \"${args[0]}\" ran successfully.[m"
else
echo "${colerr}Program \"${args[0]}\" returned an error.[m"
fi
}
announce_test "Run test, expecting no errors."
run_test tar --exclude=.git --exclude=*.tar -cvf a.tar .
intertest_pause
announce_test "Test passing a non-number to a number option."
run_test less -bten "$0"
intertest_pause
announce_test "Run test, expecting error for passing a string value to a number option."
run_test tar --exclude=.git --exclude=*.tar --level=ten -cvf a.tar .
intertest_pause
announce_test "Run test, see what happens with unknown option, B."
run_test tar --exclude=.git --exclude=*.tar -Bcvf a.tar .
intertest_pause
announce_test "Run test, see what happens with argument-taking option, f, followed by other characters."
run_test tar --exclude=.git --exclude=*.tar -fcv a.tar .
announce_test "Running grep as an example of exception to --long_option=value rule (grep also accepts --long_option value)."
run_test grep --file=bogus
run_test grep --file bogus