/
test.sh
61 lines (47 loc) · 1.52 KB
/
test.sh
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
#!/bin/bash
pushd shell
header1 "Test #5: Path handling and misc. outputs."
## Shell - $C_CACHE_SIZE
header2 "Shell - \$C_CACHE_SIZE warnings"
# cache=-10
line=$(eval "C_CACHE_SIZE=-10 $c" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "\$C_CACHE_SIZE=-10"\
"'$fline' =~ warning:\\ \\\$C_CACHE_SIZE\\ should\\ be\\ a\\ positive\\ integer.*"
assert "return" "$ret -eq 2"
# cache=0
line=$(eval "C_CACHE_SIZE=0 $c" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "\$C_CACHE_SIZE=0" "'$fline' =~ Usage:.*"
assert "return" "$ret -eq 2"
# cache=10
line=$(eval "C_CACHE_SIZE=10 $c" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "\$C_CACHE_SIZE=10" "'$fline' =~ Usage:.*"
assert "return" "$ret -eq 2"
## Shell - help flags
header2 "Shell - help flags"
# gives usage without any args
line=$(eval "$c" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "c" "'$fline' =~ Usage:.*"
assert "return" "$ret -eq 2"
# gives usage with --help
line=$(eval "$c --help" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "c --help" "'$fline' =~ Usage:.*"
assert "return" "$ret -eq 0"
# gives usage with -h
line=$(eval "$c -h" 2>&1); ret=$?
fline="$(echo "$line" | head -n1)"
assert "c -h" "'$fline' =~ Usage:.*"
assert "return" "$ret -eq 0"
## Shell - Compiles with spaces
header2 "Shell - Compiles with spaces"
# one file
out=$($c 'with spaces/a b.c' a 'b c' d 2>&1)
assert "one file" "'$out' == '(a) (b c) (d)'"
# shebang
out=$(with\ spaces/a\ b.c a 'b c' d 2>&1)
assert " shebang" "'$out' == '(a) (b c) (d)'"
popd; echo