/
oil-runtime-errors.sh
executable file
·72 lines (54 loc) · 1.2 KB
/
oil-runtime-errors.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
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
#
# Usage:
# ./oil-runtime-errors.sh <function name>
# NOTE: No set -o errexit, etc.
source test/common.sh
OIL=${OIL:-bin/oil}
_error-case() {
$OIL -c "$@"
# NOTE: This works with osh, not others.
local status=$?
if test $status != 1; then
die "Expected status 1, got $status"
fi
}
regex_literals() {
var sq = / 'foo'+ /
var dq = / "foo"+ /
var literal = 'foo'
var svs = / $literal+ /
var bvs = / ${literal}+ /
# All of these fail individually.
# NOTE: They are fatal failures so we can't catch them? It would be nicer to
# catch them.
#echo $sq
#echo $dq
#echo $svs
echo $bvs
}
undefined_vars() {
set +o errexit
_error-case 'echo hi; y = 2 + x + 3'
_error-case 'if (x) { echo hello }'
_error-case 'if ($x) { echo hi }'
_error-case 'if (${x}) { echo hi }'
_error-case 'x = / @yo /'
}
_run-test() {
local name=$1
bin/osh -O oil:basic -- $0 $name
local status=$?
if test $status -ne 1; then
die "Expected status 1, got $status"
fi
}
run-all-with-osh() {
_run-test regex_literals
_run-test undefined_vars
return 0 # success
}
run-for-release() {
run-other-suite-for-release oil-runtime-errors run-all-with-osh
}
"$@"