diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-23 10:34:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-23 10:34:01 +0900 |
| commit | d83647f390d2910547ada2854eee6189e8552cb8 (patch) | |
| tree | aa52933f9993e7b13390ab0bd7a54e56b4af513b /tests | |
| parent | 22cd700370d5d548a0cbd347bf1dc9cb9baad8e2 (diff) | |
| download | ducc-d83647f390d2910547ada2854eee6189e8552cb8.tar.gz ducc-d83647f390d2910547ada2854eee6189e8552cb8.tar.zst ducc-d83647f390d2910547ada2854eee6189e8552cb8.zip | |
refactor: test helpers
Diffstat (limited to 'tests')
106 files changed, 216 insertions, 383 deletions
diff --git a/tests/001.sh b/tests/001.sh index 00e0aca..9337ec5 100644 --- a/tests/001.sh +++ b/tests/001.sh @@ -1,4 +1,4 @@ -bash ../../test_exit_code.sh 42 <<'EOF' +test_exit_code 42 <<'EOF' int main() { return 42; } diff --git a/tests/002.sh b/tests/002.sh index ee54213..c3fdcc9 100644 --- a/tests/002.sh +++ b/tests/002.sh @@ -1,4 +1,4 @@ -bash ../../test_exit_code.sh 21 <<'EOF' +test_exit_code 21 <<'EOF' int main() { return 5+20-4; } diff --git a/tests/003.sh b/tests/003.sh index 4fa0b42..61ea83f 100644 --- a/tests/003.sh +++ b/tests/003.sh @@ -1,4 +1,4 @@ -bash ../../test_exit_code.sh 26 <<'EOF' +test_exit_code 26 <<'EOF' int main() { return 2*3+4*5; } diff --git a/tests/004.sh b/tests/004.sh index b5ceb16..028ef90 100644 --- a/tests/004.sh +++ b/tests/004.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 197 <<'EOF' +test_exit_code 197 <<'EOF' int main() { return (((3+5)/2) + (5*(9-6)) * (5+6*7)) % 256; } diff --git a/tests/005.sh b/tests/005.sh index 1b4611a..ffcd0a5 100644 --- a/tests/005.sh +++ b/tests/005.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 30 <<'EOF' +test_exit_code 30 <<'EOF' int main() { return (-10 + 20 * -3) + 100; } diff --git a/tests/006.sh b/tests/006.sh index 2ae85ec..ee88013 100644 --- a/tests/006.sh +++ b/tests/006.sh @@ -1,48 +1,46 @@ -set -e - -bash ../../test_exit_code.sh 1 <<'EOF' +test_exit_code 1 <<'EOF' int main() { return 0 == 0; } EOF -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { return 123 != 123; } EOF -bash ../../test_exit_code.sh 1 <<'EOF' +test_exit_code 1 <<'EOF' int main() { return 123 != 456; } EOF -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { return 123 == 124; } EOF -bash ../../test_exit_code.sh 1 <<'EOF' +test_exit_code 1 <<'EOF' int main() { return 123 < 567; } EOF -bash ../../test_exit_code.sh 1 <<'EOF' +test_exit_code 1 <<'EOF' int main() { return 123 <= 567; } EOF -bash ../../test_exit_code.sh 1 <<'EOF' +test_exit_code 1 <<'EOF' int main() { return 123 <= 123; } EOF -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { return 123 < 123; } diff --git a/tests/007.sh b/tests/007.sh index 6f043b7..d780993 100644 --- a/tests/007.sh +++ b/tests/007.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 42 <<'EOF' +test_exit_code 42 <<'EOF' int main() { int foo; foo = 42; diff --git a/tests/008.sh b/tests/008.sh index 94936cd..6de3a99 100644 --- a/tests/008.sh +++ b/tests/008.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 70 <<'EOF' +test_exit_code 70 <<'EOF' int main() { int foo; int bar; diff --git a/tests/009.sh b/tests/009.sh index 5ebcd0a..821d330 100644 --- a/tests/009.sh +++ b/tests/009.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 45 <<'EOF' +test_exit_code 45 <<'EOF' int main() { int a1; int a2; diff --git a/tests/010.sh b/tests/010.sh index df6601c..4ddf39c 100644 --- a/tests/010.sh +++ b/tests/010.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 12 <<'EOF' +test_exit_code 12 <<'EOF' int main() { if (1) { return 12; @@ -10,7 +8,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 34 <<'EOF' +test_exit_code 34 <<'EOF' int main() { if (1 + 1 != 2) { return 12; diff --git a/tests/011.sh b/tests/011.sh index f9ee216..877b8d1 100644 --- a/tests/011.sh +++ b/tests/011.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 45 <<'EOF' +test_exit_code 45 <<'EOF' int main() { int i; int ret; diff --git a/tests/012.sh b/tests/012.sh index 279e3c2..bee4e69 100644 --- a/tests/012.sh +++ b/tests/012.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 25 <<'EOF' +test_exit_code 25 <<'EOF' int main() { int i; int ret; diff --git a/tests/013.sh b/tests/013.sh index 8381d0e..e8e4b13 100644 --- a/tests/013.sh +++ b/tests/013.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 66 <<'EOF' +test_exit_code 66 <<'EOF' int main() { int i; int ret; diff --git a/tests/014.sh b/tests/014.sh index ba32d1f..7e5573a 100644 --- a/tests/014.sh +++ b/tests/014.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 66 <<'EOF' +test_exit_code 66 <<'EOF' int foo() { int i; int ret; diff --git a/tests/015.sh b/tests/015.sh index 6b084e8..e1964b8 100644 --- a/tests/015.sh +++ b/tests/015.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 10 <<'EOF' +test_exit_code 10 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return a; } @@ -10,7 +8,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 20 <<'EOF' +test_exit_code 20 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return b; } @@ -20,7 +18,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 30 <<'EOF' +test_exit_code 30 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return c; } @@ -30,7 +28,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 40 <<'EOF' +test_exit_code 40 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return d; } @@ -40,7 +38,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 50 <<'EOF' +test_exit_code 50 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return e; } @@ -50,7 +48,7 @@ int main() { } EOF -bash ../../test_exit_code.sh 60 <<'EOF' +test_exit_code 60 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return f; } diff --git a/tests/016.sh b/tests/016.sh index 02d3357..82c433d 100644 --- a/tests/016.sh +++ b/tests/016.sh @@ -1,6 +1,4 @@ -set -e - -bash ../../test_exit_code.sh 89 <<'EOF' +test_exit_code 89 <<'EOF' int fib(int n) { if (n <= 1) { return 1; diff --git a/tests/017.sh b/tests/017.sh index dd6edeb..552fbf4 100644 --- a/tests/017.sh +++ b/tests/017.sh @@ -1,7 +1,5 @@ -set -e - touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { return 0; } diff --git a/tests/018.sh b/tests/018.sh index cc02105..a9d4e1d 100644 --- a/tests/018.sh +++ b/tests/018.sh @@ -1,7 +1,5 @@ -set -e - touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { ""; return 0; @@ -9,7 +7,7 @@ int main() { EOF touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { "abc"; return 0; @@ -17,7 +15,7 @@ int main() { EOF touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { "\"foo\"bar\\\n\""; return 0; diff --git a/tests/019.sh b/tests/019.sh index b776285..33b2e7d 100644 --- a/tests/019.sh +++ b/tests/019.sh @@ -1,7 +1,5 @@ -set -e - touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { @@ -13,7 +11,7 @@ EOF cat <<'EOF' > expected Hello, World! EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { @@ -25,7 +23,7 @@ EOF cat <<'EOF' > expected "Hello, World!" EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/020.sh b/tests/020.sh index 146f725..abc3f8e 100644 --- a/tests/020.sh +++ b/tests/020.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 1 2 @@ -102,7 +100,7 @@ Fizz Fizz Buzz EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/021.sh b/tests/021.sh index 2f225e1..d51057f 100644 --- a/tests/021.sh +++ b/tests/021.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { int a1; int* a2; diff --git a/tests/022.sh b/tests/022.sh index e5749f2..93efe9b 100644 --- a/tests/022.sh +++ b/tests/022.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/023.sh b/tests/023.sh index cb77c22..8346e3a 100644 --- a/tests/023.sh +++ b/tests/023.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected sizeof(int) = 4 sizeof(int*) = 8 @@ -17,7 +15,7 @@ sizeof(char***) = 8 sizeof(long***) = 8 sizeof(void***) = 8 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/024.sh b/tests/024.sh index 20453a0..9b3c484 100644 --- a/tests/024.sh +++ b/tests/024.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 3 3 3 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/025.sh b/tests/025.sh index 1f673a1..54fd905 100644 --- a/tests/025.sh +++ b/tests/025.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); void foo_bar(int hoge_piyo) { diff --git a/tests/026.sh b/tests/026.sh index cd4500e..093adf0 100644 --- a/tests/026.sh +++ b/tests/026.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #define A 1 int main() { return 0; @@ -12,7 +10,7 @@ EOF cat <<'EOF' > expected 1,2,3 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A 1 @@ -28,7 +26,7 @@ EOF cat <<'EOF' > expected 0,0,0,0 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define NULL 0 diff --git a/tests/027.sh b/tests/027.sh index ee10aa3..167d398 100644 --- a/tests/027.sh +++ b/tests/027.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct Token { int kind; char* value; diff --git a/tests/028.sh b/tests/028.sh index f5f7a6d..a3babed 100644 --- a/tests/028.sh +++ b/tests/028.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected sizeof(struct Token) = 16 sizeof(struct Define) = 16 @@ -10,7 +8,7 @@ sizeof(struct Func) = 16 sizeof(struct Parser) = 64 sizeof(struct CodeGen) = 16 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct Token { int kind; char* value; diff --git a/tests/029.sh b/tests/029.sh index 7904c17..81cc5b4 100644 --- a/tests/029.sh +++ b/tests/029.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 42 123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct S { int a; int b; diff --git a/tests/030.sh b/tests/030.sh index e444938..fda5dc8 100644 --- a/tests/030.sh +++ b/tests/030.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected foo EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int foo() { @@ -30,7 +28,7 @@ foo bar baz EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int foo() { diff --git a/tests/031.sh b/tests/031.sh index 7747f84..a2b3832 100644 --- a/tests/031.sh +++ b/tests/031.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/032.sh b/tests/032.sh index 5e55b2a..b5812dd 100644 --- a/tests/032.sh +++ b/tests/032.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 97 48 92 39 10 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/033.sh b/tests/033.sh index 1fb92ac..fd43548 100644 --- a/tests/033.sh +++ b/tests/033.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); void* calloc(); @@ -28,7 +26,7 @@ cat <<'EOF' > expected 8 8 9 9 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); void* calloc(); diff --git a/tests/034.sh b/tests/034.sh index 12391f4..ebf0a4e 100644 --- a/tests/034.sh +++ b/tests/034.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct S { int a; }; diff --git a/tests/035.sh b/tests/035.sh index a32709e..f411a27 100644 --- a/tests/035.sh +++ b/tests/035.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 0 1 0 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/036.sh b/tests/036.sh index 2a60cf9..0975bcf 100644 --- a/tests/036.sh +++ b/tests/036.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' void* calloc(); int printf(); diff --git a/tests/037.sh b/tests/037.sh index bc6867b..bef69a5 100644 --- a/tests/037.sh +++ b/tests/037.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected hi EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); void f() { diff --git a/tests/038.sh b/tests/038.sh index 66ab0ed..465108e 100644 --- a/tests/038.sh +++ b/tests/038.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > input abc EOF @@ -7,7 +5,7 @@ cat <<'EOF' > expected 4 abc EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' void* calloc(); int getchar(); int printf(); diff --git a/tests/039.sh b/tests/039.sh index fb9dbdb..f00d024 100644 --- a/tests/039.sh +++ b/tests/039.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 65 65 @@ -7,7 +5,7 @@ cat <<'EOF' > expected 67 68 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' void* calloc(); int printf(); diff --git a/tests/040.sh b/tests/040.sh index 647a0e7..88ba93f 100644 --- a/tests/040.sh +++ b/tests/040.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 1 @@ -18,7 +16,7 @@ cat <<'EOF' > expected 24 25 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/041.sh b/tests/041.sh index d409158..a867cac 100644 --- a/tests/041.sh +++ b/tests/041.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 1 @@ -20,7 +18,7 @@ cat <<'EOF' > expected 3 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/042.sh b/tests/042.sh index b9f1749..8e2c85b 100644 --- a/tests/042.sh +++ b/tests/042.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42,123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A foo_a diff --git a/tests/043.sh b/tests/043.sh index a343918..ae00bd3 100644 --- a/tests/043.sh +++ b/tests/043.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42,123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/044.sh b/tests/044.sh index c6f0b06..a460ae4 100644 --- a/tests/044.sh +++ b/tests/044.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 4 0,1,2 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); enum E { diff --git a/tests/045.sh b/tests/045.sh index f788b62..efd6a30 100644 --- a/tests/045.sh +++ b/tests/045.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' typedef long size_t; int atoi(const char*); diff --git a/tests/046.sh b/tests/046.sh index 3011ff3..240d969 100644 --- a/tests/046.sh +++ b/tests/046.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' void* calloc(); int printf(); diff --git a/tests/047.sh b/tests/047.sh index f50ee69..57d0d8f 100644 --- a/tests/047.sh +++ b/tests/047.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected body 0 foo 1 @@ -12,7 +10,7 @@ foo 4 body 4 foo 5 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int foo(int i) { @@ -38,7 +36,7 @@ body 1 foo 2 body 2 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int foo(int i) { @@ -70,7 +68,7 @@ foo 4 body 5 foo 5 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int foo(int i) { diff --git a/tests/048.sh b/tests/048.sh index 76b500f..7286815 100644 --- a/tests/048.sh +++ b/tests/048.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected argc = 4 argv[1] = hoge argv[2] = piyo argv[3] = fuga EOF -bash ../../test_diff.sh hoge piyo fuga<<'EOF' +test_diff hoge piyo fuga<<'EOF' int printf(); int main(int argc, char** argv) { diff --git a/tests/049.sh b/tests/049.sh index 114bdb9..4484324 100644 --- a/tests/049.sh +++ b/tests/049.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > input foo bar @@ -13,7 +11,7 @@ bar baz baz EOF -bash ../../test_diff.sh hoge piyo fuga<<'EOF' +test_diff hoge piyo fuga<<'EOF' struct FILE; typedef struct FILE FILE; extern FILE* stdin; diff --git a/tests/050.sh b/tests/050.sh index 96f28fe..1d3fe2d 100644 --- a/tests/050.sh +++ b/tests/050.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected hello, world EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { printf("hello, world\n"); diff --git a/tests/051.sh b/tests/051.sh index 74a7327..f504664 100644 --- a/tests/051.sh +++ b/tests/051.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected undefined function: f EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' int main() { f(); } diff --git a/tests/052.sh b/tests/052.sh index df479d3..73bcd5d 100644 --- a/tests/052.sh +++ b/tests/052.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' // TODO: check if the token is at the beginning of line. // TODO: check if skipped whitespaces do not contain line breaks. int main() { diff --git a/tests/053.sh b/tests/053.sh index c4350b8..f97a17d 100644 --- a/tests/053.sh +++ b/tests/053.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 39 34 @@ -13,7 +11,7 @@ cat <<'EOF' > expected 9 11 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/054.sh b/tests/054.sh index 06252b9..4990b89 100644 --- a/tests/054.sh +++ b/tests/054.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 0 1 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); void* calloc(); diff --git a/tests/055.sh b/tests/055.sh index d5e65f3..6fc3608 100644 --- a/tests/055.sh +++ b/tests/055.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 8 EOF @@ -12,7 +10,7 @@ int add(int a, int b) { int printf(const char*, ...); EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include "header.h" int main() { diff --git a/tests/056.sh b/tests/056.sh index 7bad4c0..ff2ad18 100644 --- a/tests/056.sh +++ b/tests/056.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 12 EOF @@ -20,7 +18,7 @@ int calculate(int x) { int printf(const char*, ...); EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include "calc.h" int main() { diff --git a/tests/057.sh b/tests/057.sh index 6d1265f..8850e55 100644 --- a/tests/057.sh +++ b/tests/057.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected cannot open include file: nonexistent.h EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' #include "nonexistent.h" int main() { diff --git a/tests/058.sh b/tests/058.sh index 3be7ad1..b491ad4 100644 --- a/tests/058.sh +++ b/tests/058.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected include depth limit exceeded EOF @@ -15,7 +13,7 @@ cat <<'EOF' > b.h int b() { return 2; } EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' #include "a.h" int main() { diff --git a/tests/059.sh b/tests/059.sh index 80a6e10..189ff5e 100644 --- a/tests/059.sh +++ b/tests/059.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected main.c:1: expected '{', but got '}' EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' int main() } EOF @@ -12,6 +10,6 @@ cat <<'EOF' > expected main.c:1: expected '{', but got '123 (<integer>)' EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' int main() 123 EOF diff --git a/tests/060.sh b/tests/060.sh index 03d65b7..7f80fcf 100644 --- a/tests/060.sh +++ b/tests/060.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 42 EOF @@ -8,7 +6,7 @@ cat <<'EOF' > header.h #define A 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include "header.h" int printf(); diff --git a/tests/061.sh b/tests/061.sh index 17c5f6a..019aac2 100644 --- a/tests/061.sh +++ b/tests/061.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 1 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/062.sh b/tests/062.sh index d50ecc6..74ef2e1 100644 --- a/tests/062.sh +++ b/tests/062.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected __ducc__ is defined. A is defined. B is undefined. EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A 123 diff --git a/tests/063.sh b/tests/063.sh index a3095e8..4f899ee 100644 --- a/tests/063.sh +++ b/tests/063.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 123 456 789 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include <stdarg.h> int fprintf(); diff --git a/tests/064.sh b/tests/064.sh index c3b6028..20a8bed 100644 --- a/tests/064.sh +++ b/tests/064.sh @@ -1,18 +1,16 @@ -set -e - # C99: 5.1.2.2.3 -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { } EOF -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { 1 + 2 + 3; } EOF -bash ../../test_exit_code.sh 0 <<'EOF' +test_exit_code 0 <<'EOF' int main() { if (1); else return 1; diff --git a/tests/065.sh b/tests/065.sh index b644bed..8588944 100644 --- a/tests/065.sh +++ b/tests/065.sh @@ -1,8 +1,6 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int main() { ; } EOF diff --git a/tests/066.sh b/tests/066.sh index 7ff5ed5..21ef9c6 100644 --- a/tests/066.sh +++ b/tests/066.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 8 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include <stdarg.h> int printf(); diff --git a/tests/067.sh b/tests/067.sh index 0abac88..fa8510f 100644 --- a/tests/067.sh +++ b/tests/067.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 123 460 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/068.sh b/tests/068.sh index 648e822..b3fc394 100644 --- a/tests/068.sh +++ b/tests/068.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 1 @@ -13,7 +11,7 @@ cat <<'EOF' > expected 81 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/069.sh b/tests/069.sh index 2a43022..6be03e5 100644 --- a/tests/069.sh +++ b/tests/069.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected h l , EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/070.sh b/tests/070.sh index 9a15499..e90f1e0 100644 --- a/tests/070.sh +++ b/tests/070.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #define foo() 123 int printf(); diff --git a/tests/071.sh b/tests/071.sh index 203ac5e..6af34ee 100644 --- a/tests/071.sh +++ b/tests/071.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 579 975 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #define foo 123 + 456 #define bar() 321 + 654 diff --git a/tests/072.sh b/tests/072.sh index 9e7ab9b..d82751c 100644 --- a/tests/072.sh +++ b/tests/072.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected 123 456 0 0 123 456 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct S { int a; int b; @@ -34,7 +32,7 @@ cat <<'EOF' > expected 123 456 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct S { long a; long b; @@ -62,7 +60,7 @@ cat <<'EOF' > expected 123 456 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' struct S { long a; long b; diff --git a/tests/073.sh b/tests/073.sh index 3bc42af..c804692 100644 --- a/tests/073.sh +++ b/tests/073.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected main.c main.c @@ -10,7 +8,7 @@ cat <<'EOF' > header.h #define A __FILE__ EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #define B __FILE__ #include "header.h" int printf(); diff --git a/tests/074.sh b/tests/074.sh index a4d42ea..f7ac0fe 100644 --- a/tests/074.sh +++ b/tests/074.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 5 6 6 @@ -10,7 +8,7 @@ cat <<'EOF' > header.h #define A __LINE__ EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #define B __LINE__ #include "header.h" int printf(); diff --git a/tests/075.sh b/tests/075.sh index 12cf004..2f15211 100644 --- a/tests/075.sh +++ b/tests/075.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' /* lorem ipsum */ /* lorem ipsum diff --git a/tests/076.sh b/tests/076.sh index 065094e..71de9d7 100644 --- a/tests/076.sh +++ b/tests/076.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected sizeof(a) = 4 sizeof(b) = 8 @@ -8,7 +6,7 @@ sizeof(d) = 16 sizeof(e) = 8 sizeof(f) = 1968 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); struct S { diff --git a/tests/077.sh b/tests/077.sh index 4a58cb8..89cfb8c 100644 --- a/tests/077.sh +++ b/tests/077.sh @@ -1,9 +1,7 @@ -set -e - cat <<'EOF' > expected 0 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/078.sh b/tests/078.sh index 3f890fd..a9ac190 100644 --- a/tests/078.sh +++ b/tests/078.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected __ducc__ is defined. A is defined. B is undefined. EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A 123 diff --git a/tests/079.sh b/tests/079.sh index 4381f45..f8f0462 100644 --- a/tests/079.sh +++ b/tests/079.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 42 EOF @@ -13,7 +11,7 @@ int f() { return 42; } #endif EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' #include "header.h" #include "header.h" #include "header.h" diff --git a/tests/080.sh b/tests/080.sh index ed649da..e7fb221 100644 --- a/tests/080.sh +++ b/tests/080.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 44 44 @@ -10,7 +8,7 @@ cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/081.sh b/tests/081.sh index 03239bc..b298a98 100644 --- a/tests/081.sh +++ b/tests/081.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 2 42 8 123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/082.sh b/tests/082.sh index 1d7727f..d1e87d6 100644 --- a/tests/082.sh +++ b/tests/082.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected 8 42 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); union U { diff --git a/tests/083.sh b/tests/083.sh index 7502cf3..64d03e5 100644 --- a/tests/083.sh +++ b/tests/083.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected main.c:1: unknown preprocessor directive (foo) EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' #foo int main() {} @@ -14,7 +12,7 @@ cat <<'EOF' > expected main.c:1: unknown preprocessor directive (bar) EOF -bash ../../test_compile_error.sh <<'EOF' +test_compile_error <<'EOF' # bar 1 2 3 int main() {} diff --git a/tests/084.sh b/tests/084.sh index 3b2fe15..8b0a900 100644 --- a/tests/084.sh +++ b/tests/084.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected A is defined A is undefined EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/085.sh b/tests/085.sh index 10ab24c..9e2f32d 100644 --- a/tests/085.sh +++ b/tests/085.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 42 @@ -19,7 +17,7 @@ cat <<'EOF' > expected 123 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int a; diff --git a/tests/086.sh b/tests/086.sh index ee440b5..93b1e14 100644 --- a/tests/086.sh +++ b/tests/086.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 105 0 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/087.sh b/tests/087.sh index e662687..57e7612 100644 --- a/tests/087.sh +++ b/tests/087.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 1 @@ -13,7 +11,7 @@ cat <<'EOF' > expected 9 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/088.sh b/tests/088.sh index 6630cf0..06c88ee 100644 --- a/tests/088.sh +++ b/tests/088.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 1 @@ -15,7 +13,7 @@ cat <<'EOF' > expected 42 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/089.sh b/tests/089.sh index d0faca3..e467a26 100644 --- a/tests/089.sh +++ b/tests/089.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 8 336 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { printf("%d\n", 1 << 3); @@ -16,7 +14,7 @@ cat <<'EOF' > expected 13 0 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { printf("%d\n", 111 >> 3); diff --git a/tests/090.sh b/tests/090.sh index 102b9ab..e5e4df8 100644 --- a/tests/090.sh +++ b/tests/090.sh @@ -1,5 +1,3 @@ -set -e - cat <<'EOF' > expected 0 0 1 1 @@ -8,7 +6,7 @@ cat <<'EOF' > expected 4 4 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/091.sh b/tests/091.sh index 9281811..a64c8ff 100644 --- a/tests/091.sh +++ b/tests/091.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 2 5 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int main() { diff --git a/tests/092.sh b/tests/092.sh index 00dcb44..20c3a1f 100644 --- a/tests/092.sh +++ b/tests/092.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 42 123 999 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); char a = 42; diff --git a/tests/093.sh b/tests/093.sh index 50e20fa..fe0bda9 100644 --- a/tests/093.sh +++ b/tests/093.sh @@ -1,12 +1,10 @@ -set -e - cat <<'EOF' > expected 42 246 221 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A(x) x diff --git a/tests/094.sh b/tests/094.sh index 2f7da73..ae622bc 100644 --- a/tests/094.sh +++ b/tests/094.sh @@ -1,7 +1,5 @@ -set -e - touch expected -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' // A keyword is treated as a normal identifier in preprocessing phase. #define auto int diff --git a/tests/095.sh b/tests/095.sh index 65cd31a..5d274d0 100644 --- a/tests/095.sh +++ b/tests/095.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 1 2 3 4 0 0 5 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); int x, y, z = 5; int main() { diff --git a/tests/096.sh b/tests/096.sh index 8bd6848..7963ed7 100644 --- a/tests/096.sh +++ b/tests/096.sh @@ -1,11 +1,9 @@ -set -e - cat <<'EOF' > expected 10 20 100 300 500 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); in\ t ma\ @@ -38,4 +36,4 @@ cat <<'EOF' > expected main.c:1: <new-line> expected, but got <eof> EOF -echo -n 'int main() {}\' | bash ../../test_compile_error.sh +echo -n 'int main() {}\' | test_compile_error diff --git a/tests/097.sh b/tests/097.sh index 00d67f2..c5b8d0d 100644 --- a/tests/097.sh +++ b/tests/097.sh @@ -1,10 +1,8 @@ -set -e - cat <<'EOF' > expected 1 EOF -bash ../../test_diff.sh <<'EOF' +test_diff <<'EOF' int printf(); #define A diff --git a/tests/all.sh b/tests/all.sh index ce7ab6d..cb5df2b 100644 --- a/tests/all.sh +++ b/tests/all.sh @@ -11,7 +11,7 @@ for filename in tests/*.sh; do all|run|test_*) ;; *) - bash tests/run.sh "$testcase" + source tests/run.sh "$testcase" ;; esac done diff --git a/tests/ex_fizzbuzz.sh b/tests/ex_fizzbuzz.sh index 03d1078..b7a9e6b 100644 --- a/tests/ex_fizzbuzz.sh +++ b/tests/ex_fizzbuzz.sh @@ -103,4 +103,4 @@ Fizz Buzz EOF -bash ../../test_example.sh fizzbuzz +test_example fizzbuzz diff --git a/tests/ex_hello.sh b/tests/ex_hello.sh index 3c9e13b..750c14a 100644 --- a/tests/ex_hello.sh +++ b/tests/ex_hello.sh @@ -4,4 +4,4 @@ cat <<'EOF' > expected Hello, World! EOF -bash ../../test_example.sh hello +test_example hello diff --git a/tests/run.sh b/tests/run.sh index 0e28a96..27bd6d0 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -12,7 +12,10 @@ if [[ ! -f "$test_file" ]]; then exit 1 fi +source tests/test_helpers.sh + echo "$test_file" mkdir -p "$tmp_dir" cd "$tmp_dir" -bash "../../../$test_file" +source "../../../$test_file" +cd "../../.." diff --git a/tests/test_compile_error.sh b/tests/test_compile_error.sh deleted file mode 100644 index 2e3c207..0000000 --- a/tests/test_compile_error.sh +++ /dev/null @@ -1,9 +0,0 @@ -cat > main.c - -"$ducc" main.c > /dev/null 2> output -if [[ $? -eq 0 ]]; then - "expected to fail" - exit 1 -fi - -diff -u expected output diff --git a/tests/test_diff.sh b/tests/test_diff.sh deleted file mode 100644 index adc281e..0000000 --- a/tests/test_diff.sh +++ /dev/null @@ -1,19 +0,0 @@ -cat > main.c - -"$ducc" main.c > main.s -if [[ $? -ne 0 ]]; then - exit 1 -fi -gcc -o a.out main.s -if [[ ! -f input ]]; then - touch input -fi -./a.out "$@" < input > output -exit_code=$? - -if [[ $exit_code -ne 0 ]]; then - echo "invalid exit code: $exit_code" >&2 - exit 1 -fi - -diff -u expected output diff --git a/tests/test_example.sh b/tests/test_example.sh deleted file mode 100644 index f76b606..0000000 --- a/tests/test_example.sh +++ /dev/null @@ -1,19 +0,0 @@ -filename="../../../examples/$1.c" - -"$ducc" "$filename" > main.s -if [[ $? -ne 0 ]]; then - exit 1 -fi -gcc -o a.out main.s -if [[ ! -f input ]]; then - touch input -fi -./a.out "$@" < input > output -exit_code=$? - -if [[ $exit_code -ne 0 ]]; then - echo "invalid exit code: $exit_code" >&2 - exit 1 -fi - -diff -u expected output diff --git a/tests/test_exit_code.sh b/tests/test_exit_code.sh deleted file mode 100644 index 4cdee0a..0000000 --- a/tests/test_exit_code.sh +++ /dev/null @@ -1,16 +0,0 @@ -cat > main.c - -"$ducc" main.c > main.s -if [[ $? -ne 0 ]]; then - exit 1 -fi -gcc -o a.out main.s -./a.out -exit_code=$? - -expected=$1 - -if [[ $exit_code -ne $expected ]]; then - echo "invalid exit code: expected $expected, but got $exit_code" >&2 - exit 1 -fi diff --git a/tests/test_helpers.sh b/tests/test_helpers.sh new file mode 100644 index 0000000..9169c24 --- /dev/null +++ b/tests/test_helpers.sh @@ -0,0 +1,81 @@ +function test_exit_code() { + set +e + cat > main.c + + "$ducc" main.c > main.s + if [[ $? -ne 0 ]]; then + set -e + exit 1 + fi + gcc -o a.out main.s + ./a.out + exit_code=$? + + expected=$1 + + if [[ $exit_code -ne $expected ]]; then + echo "invalid exit code: expected $expected, but got $exit_code" >&2 + set -e + exit 1 + fi + set -e +} + +function test_diff() { + cat > main.c + + "$ducc" main.c > main.s + if [[ $? -ne 0 ]]; then + exit 1 + fi + gcc -o a.out main.s + if [[ ! -f input ]]; then + touch input + fi + ./a.out "$@" < input > output + exit_code=$? + + if [[ $exit_code -ne 0 ]]; then + echo "invalid exit code: $exit_code" >&2 + exit 1 + fi + + diff -u expected output +} + +function test_compile_error() { + set +e + cat > main.c + + "$ducc" main.c > /dev/null 2> output + if [[ $? -eq 0 ]]; then + "expected to fail" + set -e + exit 1 + fi + + diff -u expected output + set -e +} + +function test_example() { + filename="../../../examples/$1.c" + + "$ducc" "$filename" > main.s + if [[ $? -ne 0 ]]; then + exit 1 + fi + gcc -o a.out main.s + if [[ ! -f input ]]; then + touch input + fi + ./a.out "$@" < input > output + exit_code=$? + + if [[ $exit_code -ne 0 ]]; then + echo "invalid exit code: $exit_code" >&2 + exit 1 + fi + + diff -u expected output +} |
