-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·41 lines (34 loc) · 858 Bytes
/
test.sh
File metadata and controls
executable file
·41 lines (34 loc) · 858 Bytes
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
#! /bin/bash
calc () {
./calc --parser=${PARSER:=opp} 2>/dev/null
}
test_expect_success () {
r=$(calc <<<$1) || {
echo >&2 "'$PARSER' parser failed to parse '$1' expression"
exit 1
}
[ $r = $2 ] || {
echo >&2 "'$PARSER' produced incorrect result with expr: '$1'"
echo >&2 "expecting '$2', but got '$r'"
exit 2
}
}
test_expect_failure () {
calc <<<$1 && {
echo >&2 "'$PARSER' should have failed to parse '$1'"
exit 3
}
}
test_expect_success "1" 1
test_expect_success "1+2" 3
test_expect_success "2*3" 6
test_expect_failure "1+"
test_expect_failure "2 3"
test_expect_success "(((100)))" 100
test_expect_success "1 + 2 * 3 + 4" 11
test_expect_success "(2+3)*4" 20
test_expect_success "(2+3) * (1+3)" 20
test_expect_success "(1 + (2 + (3 + (4 + 5))))" 15
test_expect_failure "(1 + (2 + (3 + (4 + 5))"
echo "All tests passed."
exit 0