blob: 093b3950e15f79553b595b141dadf0f256cc69ff [file] [log] [blame]
Denys Vlasenko9a23b072018-12-12 21:41:40 +01001#!/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
Denys Vlasenko766f6722018-12-13 17:23:24 +01007# testing "test name" "command" "expected result" "file input" "stdin"
8
9testing "bc comment 1" \
10 "bc" \
11 "3\n" \
12 "" "1 /* comment */ + 2"
13
14testing "bc comment 2: /*/ is not a closed comment" \
15 "bc" \
16 "4\n" \
17 "" "1 /*/ + 2 */ + 3"
18
Denys Vlasenko818b6022018-12-13 17:56:35 +010019testing "bc backslash 1" \
20 "bc" \
21 "3\n" \
22 "" "1 \\\\\n + 2"
23
24testing "bc string 1" \
25 "bc" \
26 "STR\n" \
27 "" "\"STR\n\""
28
Denys Vlasenko99b37622018-12-15 20:06:59 +010029testing "bc if 0 else" \
30 "bc" \
31 "2\n9\n" \
32 "" "if (0) 1 else 2; 9"
33
34testing "bc if 1 else" \
35 "bc" \
36 "1\n9\n" \
37 "" "if (1) 1 else 2; 9"
38
39testing "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
44testing "bc if 0 else if 1" \
45 "bc" \
46 "2\n9\n" \
47 "" "if (0) 1 else if (1) 2; 9"
48
Denys Vlasenkod1d29b42018-12-16 16:03:03 +010049testing "bc define auto" \
50 "bc" \
51 "8\n9\n" \
52 "" "define w() { auto z; return 8; }; w(); 9"
53
Denys Vlasenkoe9519e42018-12-16 17:06:07 +010054testing "bc define with body on next line" \
55 "bc" \
56 "8\n9\n" \
57 "" "define w()\n{ auto z; return 8; }\nw()\n9"
58
Denys Vlasenko9a23b072018-12-12 21:41:40 +010059tar xJf bc_large.tar.xz
60
61for f in bc*.bc; do
62 r="`basename "$f" .bc`_results.txt"
63 test -f "$r" || continue
64 # testing "test name" "command" "expected result" "file input" "stdin"
65 testing "bc -lq $f" \
66 "{ { bc -lq $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
67 "E:0\nE:0\n" \
68 "" ""
69done
70
71exit $FAILCOUNT