bc: partially rewrite parser, tests pass, ^C might be broken now
[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 testing "bc define auto" \
50         "bc" \
51         "8\n9\n" \
52         "" "define w() { auto z; return 8; }; w(); 9"
53
54 tar xJf bc_large.tar.xz
55
56 for f in bc*.bc; do
57         r="`basename "$f" .bc`_results.txt"
58         test -f "$r" || continue
59         # testing "test name" "command" "expected result" "file input" "stdin"
60         testing "bc -lq $f" \
61                 "{ { bc -lq $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
62                 "E:0\nE:0\n" \
63                 "" ""
64 done
65
66 exit $FAILCOUNT