Denys Vlasenko | 9a23b07 | 2018-12-12 21:41:40 +0100 | [diff] [blame] | 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 | |
Denys Vlasenko | 766f672 | 2018-12-13 17:23:24 +0100 | [diff] [blame] | 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 | |
Denys Vlasenko | 818b602 | 2018-12-13 17:56:35 +0100 | [diff] [blame] | 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 | |
Denys Vlasenko | 99b3762 | 2018-12-15 20:06:59 +0100 | [diff] [blame] | 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 | |
Denys Vlasenko | d1d29b4 | 2018-12-16 16:03:03 +0100 | [diff] [blame] | 49 | testing "bc define auto" \ |
| 50 | "bc" \ |
| 51 | "8\n9\n" \ |
| 52 | "" "define w() { auto z; return 8; }; w(); 9" |
| 53 | |
Denys Vlasenko | e9519e4 | 2018-12-16 17:06:07 +0100 | [diff] [blame^] | 54 | testing "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 Vlasenko | 9a23b07 | 2018-12-12 21:41:40 +0100 | [diff] [blame] | 59 | tar xJf bc_large.tar.xz |
| 60 | |
| 61 | for 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 | "" "" |
| 69 | done |
| 70 | |
| 71 | exit $FAILCOUNT |