bc: lexer debugging, added some failing test cases
[oweals/busybox.git] / testsuite / bc.tests
1 #!/bin/sh
2 # Copyright 2018 by Denys Vlasenko
3 # Licensed under GPLv2 or later, see file LICENSE in this source tree.
4
5 . ./testing.sh
6
7 # testing "test name" "command" "expected result" "file input" "stdin"
8
9 testing "bc comment 1" \
10         "bc" \
11         "3\n" \
12         "" "1 /* comment */ + 2"
13
14 testing "bc comment 2: /*/ is not a closed comment" \
15         "bc" \
16         "4\n" \
17         "" "1 /*/ + 2 */ + 3"
18
19 testing "bc backslash 1" \
20         "bc" \
21         "3\n" \
22         "" "1 \\\\\n + 2"
23
24 testing "bc string 1" \
25         "bc" \
26         "STR\n" \
27         "" "\"STR\n\""
28
29 testing "bc if 0 else" \
30         "bc" \
31         "2\n9\n" \
32         "" "if (0) 1 else 2; 9"
33
34 testing "bc if 1 else" \
35         "bc" \
36         "1\n9\n" \
37         "" "if (1) 1 else 2; 9"
38
39 testing "bc if 1 if 1 else else" \
40         "bc" \
41         "1\n9\n" \
42         "" "if (1) if (1) 1 else 2 else 3; 9"
43
44 testing "bc if 0 else if 1" \
45         "bc" \
46         "2\n9\n" \
47         "" "if (0) 1 else if (1) 2; 9"
48
49 tar xJf bc_large.tar.xz
50
51 for f in bc*.bc; do
52         r="`basename "$f" .bc`_results.txt"
53         test -f "$r" || continue
54         # testing "test name" "command" "expected result" "file input" "stdin"
55         testing "bc -lq $f" \
56                 "{ { bc -lq $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
57                 "E:0\nE:0\n" \
58                 "" ""
59 done
60
61 exit $FAILCOUNT