2 # Copyright 2018 by Denys Vlasenko
3 # Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 # testing "test name" "command" "expected result" "file input" "stdin"
12 "" "1 /* comment */ + 2"
14 testing "bc /*/ is not a closed comment" \
19 # this needs interactive testing
20 testing "bc comment with \"" \
25 # this needs interactive testing
26 testing "bc \"string/*\" is not a comment" \
31 testing "bc comment 3: unterminated #comment" \
34 "" "#foo" # no trailing newline
36 testing "bc backslash 1" \
41 testing "bc string 1" \
46 testing "bc read() 4<EOF>" \
51 testing "bc read()^2" \
56 testing "bc read()*read()" \
59 "read()*read();halt" "4\n5"
61 testing "bc if 0 else" \
64 "" "if (0) 1 else 2; 9"
66 testing "bc if 1 else" \
69 "" "if (1) 1 else 2; 9"
71 testing "bc if 1 if 1 else else" \
74 "" "if (1) if (1) 1 else 2 else 3; 9"
76 testing "bc if 0 else if 1" \
79 "" "if (0) 1 else if (1) 2; 9"
81 testing "bc for (;;)" \
84 "" "i=2; for (;;) { 2; if(--i==0) break; 3; }; 9"
86 testing "bc for (;cond;)" \
89 "" "i=0; for(;i<3;)++i; 9"
91 testing "bc for (;cond;upd)" \
94 "" "i=1; for(;i<4;i++)i; 9"
96 testing "bc for (init;cond;upd)" \
99 "" "for(i=1;i<4;i++)i; 9"
101 testing "bc for (;;) {break}" \
104 "" "for (;;) {2;break}; 9"
106 testing "bc define {return}" \
109 "" "define w() {return}\nw();9"
111 testing "bc define auto" \
114 "" "define w() { auto z; return 8; }; w(); 9"
116 testing "bc define auto array same name" \
119 "" "define w(x) { auto x[]; return x; }; w(8); 9"
121 testing "bc define with body on next line" \
124 "" "define w()\n{ auto z; return 8; }\nw()\n9"
126 testing "bc void function" \
129 "" "define void w() {print \"void\"}\nw()\n9"
131 # Extra POSIX compat - GNU bc does not allow this
132 testing "bc function named 'void'" \
135 "" "define void() {print \"void\"}\nvoid()\n9"
137 # Extra POSIX compat - GNU bc does not allow this
138 testing "bc variable named 'void'" \
143 testing "bc if(cond)<NL>" \
148 testing "bc if(cond) stmt else<NL>" \
151 "" "if(0)3 else\n4\n9"
153 testing "bc while(cond)<NL>" \
155 "8\n7\n6\n5\n4\n3\n2\n1\n9\n" \
156 "" "i=9;while(--i)\ni\n9"
158 testing "bc ifz does not match if keyword" \
161 "" "ifz=1;ifz\n++ifz;ifz++\nifz"
163 # had parse error on "f()-N"
164 testing "bc -l 'e(0)-2'" \
166 "-1.00000000000000000000\n" \
169 testing "bc (!a&&b)" \
174 # check that dc code is not messing this up (no NUL printing!)
175 testing "bc print \"\"" \
180 testing "bc print 1,2,3" \
185 testing "bc { print 1 }" \
190 testing "bc nested loops and breaks" \
221 testing "bc continue in if" \
248 testing "bc continue in for" \
268 "" "a=ZZ;a;ibase=36;a=ZZ;a;ibase=Z;a=ZZ;a"
270 testing "bc parsing of numbers" \
271 "bc 2>&1 | bc 2>&1 | md5sum 2>&1" \
272 "465d8c01308d0863b6f5669e8a1c69fb -\n" \
274 for (b = 2; b <= 16; ++b) {
275 if (b == 10) continue
277 print "ibase = A; ibase = ", b, "\n"
279 for (i = 0; i <= 65536; ++i) {
283 print i, ".", i, "\n"
287 testing "bc printing of numbers" \
288 "bc 2>&1 | bc 2>&1 | md5sum 2>&1" \
289 "d884b35d251ca096410712743aeafb9e -\n" \
291 for (b = 2; b <= 101; ++b) {
292 if (b == 10) continue
294 print "obase = ", b, "\n"
295 for (i = 0; i <= s; ++i) {
299 print i, ".", i, "\n"
301 2189432174861923048671023498128347619023487610234689172304.192748960128745108927461089237469018723460
305 r="`basename "$f" .bc`_results.txt"
306 test -f "$r" || continue
307 # testing "test name" "command" "expected result" "file input" "stdin"
308 testing "bc -lq $f" \
309 "{ { bc -lq $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \