diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/001.sh | 5 | ||||
| -rw-r--r-- | tests/002.sh | 5 | ||||
| -rw-r--r-- | tests/003.sh | 5 | ||||
| -rw-r--r-- | tests/004.sh | 5 | ||||
| -rw-r--r-- | tests/005.sh | 5 | ||||
| -rw-r--r-- | tests/007.sh | 7 | ||||
| -rw-r--r-- | tests/008.sh | 9 | ||||
| -rw-r--r-- | tests/011.sh | 12 | ||||
| -rw-r--r-- | tests/012.sh | 15 | ||||
| -rw-r--r-- | tests/013.sh | 15 | ||||
| -rw-r--r-- | tests/014.sh | 19 | ||||
| -rw-r--r-- | tests/017.sh | 6 | ||||
| -rw-r--r-- | tests/018.sh | 23 | ||||
| -rw-r--r-- | tests/019.sh | 33 | ||||
| -rw-r--r-- | tests/021.sh | 22 | ||||
| -rw-r--r-- | tests/022.sh | 15 | ||||
| -rw-r--r-- | tests/023.sh | 39 | ||||
| -rw-r--r-- | tests/024.sh | 39 | ||||
| -rw-r--r-- | tests/025.sh | 15 | ||||
| -rw-r--r-- | tests/028.sh | 88 | ||||
| -rw-r--r-- | tests/029.sh | 23 | ||||
| -rw-r--r-- | tests/031.sh | 12 | ||||
| -rw-r--r-- | tests/032.sh | 15 | ||||
| -rw-r--r-- | tests/033.sh | 44 | ||||
| -rw-r--r-- | tests/034.sh | 15 | ||||
| -rw-r--r-- | tests/035.sh | 15 | ||||
| -rw-r--r-- | tests/036.sh | 25 | ||||
| -rw-r--r-- | tests/037.sh | 16 | ||||
| -rw-r--r-- | tests/039.sh | 30 | ||||
| -rw-r--r-- | tests/040.sh | 38 | ||||
| -rw-r--r-- | tests/042.sh | 18 | ||||
| -rw-r--r-- | tests/044.sh | 20 | ||||
| -rw-r--r-- | tests/046.sh | 19 | ||||
| -rw-r--r-- | tests/050.sh | 10 | ||||
| -rw-r--r-- | tests/051.sh | 8 | ||||
| -rw-r--r-- | tests/054.sh | 21 | ||||
| -rw-r--r-- | tests/056.sh | 28 | ||||
| -rw-r--r-- | tests/057.sh | 11 | ||||
| -rw-r--r-- | tests/058.sh | 23 | ||||
| -rw-r--r-- | tests/060.sh | 18 | ||||
| -rw-r--r-- | tests/061.sh | 12 | ||||
| -rw-r--r-- | tests/062.sh | 36 | ||||
| -rw-r--r-- | tests/066.sh | 13 | ||||
| -rw-r--r-- | tests/067.sh | 13 | ||||
| -rw-r--r-- | tests/068.sh | 27 | ||||
| -rw-r--r-- | tests/069.sh | 16 | ||||
| -rw-r--r-- | tests/070.sh | 13 | ||||
| -rw-r--r-- | tests/071.sh | 16 | ||||
| -rw-r--r-- | tests/073.sh | 20 | ||||
| -rw-r--r-- | tests/074.sh | 20 | ||||
| -rw-r--r-- | tests/075.sh | 14 | ||||
| -rw-r--r-- | tests/076.sh | 33 | ||||
| -rw-r--r-- | tests/077.sh | 10 | ||||
| -rw-r--r-- | tests/085.sh | 38 | ||||
| -rw-r--r-- | tests/086.sh | 15 | ||||
| -rw-r--r-- | tests/087.sh | 22 | ||||
| -rw-r--r-- | tests/088.sh | 33 | ||||
| -rw-r--r-- | tests/089.sh | 23 | ||||
| -rw-r--r-- | tests/090.sh | 19 | ||||
| -rw-r--r-- | tests/093.sh | 20 | ||||
| -rw-r--r-- | tests/096.sh | 39 | ||||
| -rw-r--r-- | tests/097.sh | 18 | ||||
| -rw-r--r-- | tests/100.sh | 44 | ||||
| -rw-r--r-- | tests/101.sh | 22 | ||||
| -rw-r--r-- | tests/104.sh | 32 | ||||
| -rw-r--r-- | tests/108.sh | 26 | ||||
| -rw-r--r-- | tests/110.sh | 15 | ||||
| -rw-r--r-- | tests/112.sh | 35 | ||||
| -rw-r--r-- | tests/114.sh | 26 | ||||
| -rw-r--r-- | tests/117.sh | 31 | ||||
| -rw-r--r-- | tests/118.sh | 19 | ||||
| -rw-r--r-- | tests/120.sh | 21 | ||||
| -rw-r--r-- | tests/all.sh | 2 | ||||
| -rw-r--r-- | tests/helpers.sh (renamed from tests/test_helpers.sh) | 0 | ||||
| -rw-r--r-- | tests/run.sh | 2 | ||||
| -rw-r--r-- | tests/test_arithmetic_operators.sh | 30 | ||||
| -rw-r--r-- | tests/test_array_basics.sh | 163 | ||||
| -rw-r--r-- | tests/test_assignment_operators.sh (renamed from tests/041.sh) | 1 | ||||
| -rw-r--r-- | tests/test_bitwise_operators.sh | 65 | ||||
| -rw-r--r-- | tests/test_bool_type.sh (renamed from tests/119.sh) | 1 | ||||
| -rw-r--r-- | tests/test_char_literals.sh (renamed from tests/053.sh) | 28 | ||||
| -rw-r--r-- | tests/test_comma_operator.sh (renamed from tests/095.sh) | 21 | ||||
| -rw-r--r-- | tests/test_command_line_args.sh (renamed from tests/048.sh) | 1 | ||||
| -rw-r--r-- | tests/test_comments.sh (renamed from tests/052.sh) | 16 | ||||
| -rw-r--r-- | tests/test_comparison_operators.sh (renamed from tests/006.sh) | 1 | ||||
| -rw-r--r-- | tests/test_compile_errors.sh (renamed from tests/059.sh) | 10 | ||||
| -rw-r--r-- | tests/test_compiler_output.sh (renamed from tests/098.sh) | 1 | ||||
| -rw-r--r-- | tests/test_compiler_version.sh (renamed from tests/111.sh) | 1 | ||||
| -rw-r--r-- | tests/test_conditional_errors.sh (renamed from tests/106.sh) | 24 | ||||
| -rw-r--r-- | tests/test_define_macros.sh | 92 | ||||
| -rw-r--r-- | tests/test_do_while.sh (renamed from tests/047.sh) | 1 | ||||
| -rw-r--r-- | tests/test_empty_preprocessor.sh (renamed from tests/099.sh) | 1 | ||||
| -rw-r--r-- | tests/test_empty_statements.sh (renamed from tests/065.sh) | 1 | ||||
| -rw-r--r-- | tests/test_enums.sh (renamed from tests/113.sh) | 22 | ||||
| -rw-r--r-- | tests/test_error_directive.sh (renamed from tests/103.sh) | 1 | ||||
| -rw-r--r-- | tests/test_example_programs.sh (renamed from tests/020.sh) | 12 | ||||
| -rw-r--r-- | tests/test_file_io.sh (renamed from tests/049.sh) | 1 | ||||
| -rw-r--r-- | tests/test_for_loops.sh | 141 | ||||
| -rw-r--r-- | tests/test_function_basics.sh (renamed from tests/015.sh) | 28 | ||||
| -rw-r--r-- | tests/test_function_macros.sh | 106 | ||||
| -rw-r--r-- | tests/test_global_variables.sh (renamed from tests/092.sh) | 1 | ||||
| -rw-r--r-- | tests/test_identifiers.sh (renamed from tests/043.sh) | 1 | ||||
| -rw-r--r-- | tests/test_if_elif_else.sh (renamed from tests/102.sh) | 65 | ||||
| -rw-r--r-- | tests/test_if_else.sh (renamed from tests/010.sh) | 1 | ||||
| -rw-r--r-- | tests/test_ifdef_ifndef.sh (renamed from tests/078.sh) | 38 | ||||
| -rw-r--r-- | tests/test_implicit_return.sh (renamed from tests/064.sh) | 1 | ||||
| -rw-r--r-- | tests/test_include_errors.sh | 52 | ||||
| -rw-r--r-- | tests/test_include_guards.sh (renamed from tests/079.sh) | 1 | ||||
| -rw-r--r-- | tests/test_include_local.sh (renamed from tests/055.sh) | 49 | ||||
| -rw-r--r-- | tests/test_increment_operators.sh (renamed from tests/080.sh) | 1 | ||||
| -rw-r--r-- | tests/test_input_operations.sh (renamed from tests/038.sh) | 1 | ||||
| -rw-r--r-- | tests/test_invalid_directives.sh (renamed from tests/083.sh) | 1 | ||||
| -rw-r--r-- | tests/test_keywords.sh (renamed from tests/094.sh) | 1 | ||||
| -rw-r--r-- | tests/test_line_continuation.sh (renamed from tests/121.sh) | 41 | ||||
| -rw-r--r-- | tests/test_local_variables.sh (renamed from tests/009.sh) | 32 | ||||
| -rw-r--r-- | tests/test_logical_operators.sh (renamed from tests/030.sh) | 17 | ||||
| -rw-r--r-- | tests/test_macro_operators.sh (renamed from tests/107.sh) | 1 | ||||
| -rw-r--r-- | tests/test_nested_conditionals.sh (renamed from tests/105.sh) | 1 | ||||
| -rw-r--r-- | tests/test_pointer_basics.sh | 79 | ||||
| -rw-r--r-- | tests/test_predefined_macros.sh | 55 | ||||
| -rw-r--r-- | tests/test_preprocessor_comments.sh (renamed from tests/109.sh) | 1 | ||||
| -rw-r--r-- | tests/test_printf.sh (renamed from tests/115.sh) | 35 | ||||
| -rw-r--r-- | tests/test_recursive_functions.sh (renamed from tests/016.sh) | 1 | ||||
| -rw-r--r-- | tests/test_short_type.sh (renamed from tests/081.sh) | 1 | ||||
| -rw-r--r-- | tests/test_sizeof_operator.sh | 177 | ||||
| -rw-r--r-- | tests/test_stdlib_declarations.sh (renamed from tests/045.sh) | 1 | ||||
| -rw-r--r-- | tests/test_string_operations.sh | 57 | ||||
| -rw-r--r-- | tests/test_struct_arrays.sh (renamed from tests/116.sh) | 1 | ||||
| -rw-r--r-- | tests/test_struct_basics.sh (renamed from tests/027.sh) | 51 | ||||
| -rw-r--r-- | tests/test_struct_initialization.sh (renamed from tests/072.sh) | 23 | ||||
| -rw-r--r-- | tests/test_ternary_operator.sh (renamed from tests/091.sh) | 1 | ||||
| -rw-r--r-- | tests/test_typedef_struct.sh | 85 | ||||
| -rw-r--r-- | tests/test_undef.sh (renamed from tests/084.sh) | 1 | ||||
| -rw-r--r-- | tests/test_unions.sh (renamed from tests/082.sh) | 1 | ||||
| -rw-r--r-- | tests/test_variadic_functions.sh (renamed from tests/063.sh) | 1 | ||||
| -rw-r--r-- | tests/test_void_functions.sh (renamed from tests/026.sh) | 34 |
136 files changed, 1668 insertions, 1547 deletions
diff --git a/tests/001.sh b/tests/001.sh deleted file mode 100644 index 9337ec5..0000000 --- a/tests/001.sh +++ /dev/null @@ -1,5 +0,0 @@ -test_exit_code 42 <<'EOF' -int main() { - return 42; -} -EOF diff --git a/tests/002.sh b/tests/002.sh deleted file mode 100644 index c3fdcc9..0000000 --- a/tests/002.sh +++ /dev/null @@ -1,5 +0,0 @@ -test_exit_code 21 <<'EOF' -int main() { - return 5+20-4; -} -EOF diff --git a/tests/003.sh b/tests/003.sh deleted file mode 100644 index 61ea83f..0000000 --- a/tests/003.sh +++ /dev/null @@ -1,5 +0,0 @@ -test_exit_code 26 <<'EOF' -int main() { - return 2*3+4*5; -} -EOF diff --git a/tests/004.sh b/tests/004.sh deleted file mode 100644 index 028ef90..0000000 --- a/tests/004.sh +++ /dev/null @@ -1,5 +0,0 @@ -test_exit_code 197 <<'EOF' -int main() { - return (((3+5)/2) + (5*(9-6)) * (5+6*7)) % 256; -} -EOF diff --git a/tests/005.sh b/tests/005.sh deleted file mode 100644 index ffcd0a5..0000000 --- a/tests/005.sh +++ /dev/null @@ -1,5 +0,0 @@ -test_exit_code 30 <<'EOF' -int main() { - return (-10 + 20 * -3) + 100; -} -EOF diff --git a/tests/007.sh b/tests/007.sh deleted file mode 100644 index d780993..0000000 --- a/tests/007.sh +++ /dev/null @@ -1,7 +0,0 @@ -test_exit_code 42 <<'EOF' -int main() { - int foo; - foo = 42; - return foo; -} -EOF diff --git a/tests/008.sh b/tests/008.sh deleted file mode 100644 index 6de3a99..0000000 --- a/tests/008.sh +++ /dev/null @@ -1,9 +0,0 @@ -test_exit_code 70 <<'EOF' -int main() { - int foo; - int bar; - foo = 42; - bar = 28; - return foo + bar; -} -EOF diff --git a/tests/011.sh b/tests/011.sh deleted file mode 100644 index 877b8d1..0000000 --- a/tests/011.sh +++ /dev/null @@ -1,12 +0,0 @@ -test_exit_code 45 <<'EOF' -int main() { - int i; - int ret; - i = 0; - ret = 0; - for (i = 0; i < 10; i = i + 1) { - ret = ret + i; - } - return ret; -} -EOF diff --git a/tests/012.sh b/tests/012.sh deleted file mode 100644 index bee4e69..0000000 --- a/tests/012.sh +++ /dev/null @@ -1,15 +0,0 @@ -test_exit_code 25 <<'EOF' -int main() { - int i; - int ret; - i = 0; - ret = 0; - for (i = 0; i < 10; i = i + 1) { - if (i % 2 == 0) { - continue; - } - ret = ret + i; - } - return ret; -} -EOF diff --git a/tests/013.sh b/tests/013.sh deleted file mode 100644 index e8e4b13..0000000 --- a/tests/013.sh +++ /dev/null @@ -1,15 +0,0 @@ -test_exit_code 66 <<'EOF' -int main() { - int i; - int ret; - i = 0; - ret = 0; - for (i = 0; i < 100; i = i + 1) { - if (i == 12) { - break; - } - ret = ret + i; - } - return ret; -} -EOF diff --git a/tests/014.sh b/tests/014.sh deleted file mode 100644 index 7e5573a..0000000 --- a/tests/014.sh +++ /dev/null @@ -1,19 +0,0 @@ -test_exit_code 66 <<'EOF' -int foo() { - int i; - int ret; - i = 0; - ret = 0; - for (i = 0; i < 100; i = i + 1) { - if (i == 12) { - break; - } - ret = ret + i; - } - return ret; -} - -int main() { - return foo(); -} -EOF diff --git a/tests/017.sh b/tests/017.sh deleted file mode 100644 index 552fbf4..0000000 --- a/tests/017.sh +++ /dev/null @@ -1,6 +0,0 @@ -touch expected -test_diff <<'EOF' -int main() { - return 0; -} -EOF diff --git a/tests/018.sh b/tests/018.sh deleted file mode 100644 index a9d4e1d..0000000 --- a/tests/018.sh +++ /dev/null @@ -1,23 +0,0 @@ -touch expected -test_diff <<'EOF' -int main() { - ""; - return 0; -} -EOF - -touch expected -test_diff <<'EOF' -int main() { - "abc"; - return 0; -} -EOF - -touch expected -test_diff <<'EOF' -int main() { - "\"foo\"bar\\\n\""; - return 0; -} -EOF diff --git a/tests/019.sh b/tests/019.sh deleted file mode 100644 index 33b2e7d..0000000 --- a/tests/019.sh +++ /dev/null @@ -1,33 +0,0 @@ -touch expected -test_diff <<'EOF' -int printf(); - -int main() { - printf(""); - return 0; -} -EOF - -cat <<'EOF' > expected -Hello, World! -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("Hello, World!\n"); - return 0; -} -EOF - -cat <<'EOF' > expected -"Hello, World!" -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("\"Hello, World!\"\n"); - return 0; -} -EOF diff --git a/tests/021.sh b/tests/021.sh deleted file mode 100644 index d51057f..0000000 --- a/tests/021.sh +++ /dev/null @@ -1,22 +0,0 @@ -cat <<'EOF' > expected -EOF -test_diff <<'EOF' -int main() { - int a1; - int* a2; - char a3; - char* a4; - long a5; - long* a6; - void* a8; - int** a10; - char** a12; - long** a14; - void** a16; - int*** a18; - char*** a20; - long*** a22; - void*** a24; - return 0; -} -EOF diff --git a/tests/022.sh b/tests/022.sh deleted file mode 100644 index 93efe9b..0000000 --- a/tests/022.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -42 42 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - int x; - int* y; - y = &x; - *y = 42; - printf("%d %d\n", x, *y); - return 0; -} -EOF diff --git a/tests/023.sh b/tests/023.sh deleted file mode 100644 index 8346e3a..0000000 --- a/tests/023.sh +++ /dev/null @@ -1,39 +0,0 @@ -cat <<'EOF' > expected -sizeof(int) = 4 -sizeof(int*) = 8 -sizeof(char) = 1 -sizeof(char*) = 8 -sizeof(long) = 8 -sizeof(long*) = 8 -sizeof(void*) = 8 -sizeof(int**) = 8 -sizeof(char**) = 8 -sizeof(long**) = 8 -sizeof(void**) = 8 -sizeof(int***) = 8 -sizeof(char***) = 8 -sizeof(long***) = 8 -sizeof(void***) = 8 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("sizeof(int) = %d\n", sizeof(int)); - printf("sizeof(int*) = %d\n", sizeof(int*)); - printf("sizeof(char) = %d\n", sizeof(char)); - printf("sizeof(char*) = %d\n", sizeof(char*)); - printf("sizeof(long) = %d\n", sizeof(long)); - printf("sizeof(long*) = %d\n", sizeof(long*)); - printf("sizeof(void*) = %d\n", sizeof(void*)); - printf("sizeof(int**) = %d\n", sizeof(int**)); - printf("sizeof(char**) = %d\n", sizeof(char**)); - printf("sizeof(long**) = %d\n", sizeof(long**)); - printf("sizeof(void**) = %d\n", sizeof(void**)); - printf("sizeof(int***) = %d\n", sizeof(int***)); - printf("sizeof(char***) = %d\n", sizeof(char***)); - printf("sizeof(long***) = %d\n", sizeof(long***)); - printf("sizeof(void***) = %d\n", sizeof(void***)); - return 0; -} -EOF diff --git a/tests/024.sh b/tests/024.sh deleted file mode 100644 index 9b3c484..0000000 --- a/tests/024.sh +++ /dev/null @@ -1,39 +0,0 @@ -cat <<'EOF' > expected -3 -3 -3 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - char c; - int i; - long l; - c = 42; - i = 42*2; - l = 42*3; - - char* cp1; - char* cp2; - int* ip1; - int* ip2; - long* lp1; - long* lp2; - - cp1 = &c; - cp2 = &c + 3; - - ip1 = &i; - ip2 = &i + 3; - - lp1 = &l; - lp2 = &l + 3; - - printf("%d\n", cp2 - cp1); - printf("%d\n", ip2 - ip1); - printf("%d\n", lp2 - lp1); - - return 0; -} -EOF diff --git a/tests/025.sh b/tests/025.sh deleted file mode 100644 index 54fd905..0000000 --- a/tests/025.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -123 -EOF -test_diff <<'EOF' -int printf(); - -void foo_bar(int hoge_piyo) { - printf("%d\n", hoge_piyo); -} - -int main() { - foo_bar(123); - return 0; -} -EOF diff --git a/tests/028.sh b/tests/028.sh deleted file mode 100644 index a3babed..0000000 --- a/tests/028.sh +++ /dev/null @@ -1,88 +0,0 @@ -cat <<'EOF' > expected -sizeof(struct Token) = 16 -sizeof(struct Define) = 16 -sizeof(struct Type) = 24 -sizeof(struct AstNode) = 128 -sizeof(struct LVar) = 16 -sizeof(struct Func) = 16 -sizeof(struct Parser) = 64 -sizeof(struct CodeGen) = 16 -EOF -test_diff <<'EOF' -struct Token { - int kind; - char* value; -}; - -struct Define { - char* from; - struct Token* to; -}; - -struct AstNode; - -struct Type { - int kind; - struct Type* to; - struct AstNode* members; -}; - -struct AstNode { - int kind; - struct AstNode* next; - struct AstNode* last; - char* name; - struct AstNode* func_params; - struct AstNode* func_body; - int int_value; - struct AstNode* expr1; - struct AstNode* expr2; - struct AstNode* expr3; - int op; - struct Type* ty; - int var_index; - struct AstNode* node1; - struct AstNode* node2; - char** str_literals; -}; - -struct LVar { - char* name; - struct Type* ty; -}; - -struct Func { - char* name; - struct Type* ty; -}; - -struct Parser { - struct Token* tokens; - int pos; - struct LVar* locals; - int n_locals; - struct Func* funcs; - int n_funcs; - char** str_literals; - int n_str_literals; -}; - -struct CodeGen { - int next_label; - int* loop_labels; -}; - -int printf(); - -int main() { - printf("sizeof(struct Token) = %d\n", sizeof(struct Token)); - printf("sizeof(struct Define) = %d\n", sizeof(struct Define)); - printf("sizeof(struct Type) = %d\n", sizeof(struct Type)); - printf("sizeof(struct AstNode) = %d\n", sizeof(struct AstNode)); - printf("sizeof(struct LVar) = %d\n", sizeof(struct LVar)); - printf("sizeof(struct Func) = %d\n", sizeof(struct Func)); - printf("sizeof(struct Parser) = %d\n", sizeof(struct Parser)); - printf("sizeof(struct CodeGen) = %d\n", sizeof(struct CodeGen)); - return 0; -} -EOF diff --git a/tests/029.sh b/tests/029.sh deleted file mode 100644 index 81cc5b4..0000000 --- a/tests/029.sh +++ /dev/null @@ -1,23 +0,0 @@ -cat <<'EOF' > expected -42 -123 -EOF -test_diff <<'EOF' -struct S { - int a; - int b; -}; - -int printf(); -void* calloc(); - -int main() { - struct S* sp; - sp = calloc(1, sizeof(struct S)); - sp->a = 42; - printf("%d\n", sp->a); - (*sp).b = 123; - printf("%d\n", (*sp).b); - return 0; -} -EOF diff --git a/tests/031.sh b/tests/031.sh deleted file mode 100644 index a2b3832..0000000 --- a/tests/031.sh +++ /dev/null @@ -1,12 +0,0 @@ -cat <<'EOF' > expected -42 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - int a = 42; - printf("%d\n", a); - return 0; -} -EOF diff --git a/tests/032.sh b/tests/032.sh deleted file mode 100644 index b5812dd..0000000 --- a/tests/032.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -97 48 -92 39 -10 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("%d %d\n", 'a', '0'); - printf("%d %d\n", '\\', '\''); - printf("%d\n", '\n'); - return 0; -} -EOF diff --git a/tests/033.sh b/tests/033.sh deleted file mode 100644 index fd43548..0000000 --- a/tests/033.sh +++ /dev/null @@ -1,44 +0,0 @@ -cat <<'EOF' > expected -42 -EOF -test_diff <<'EOF' -int printf(); -void* calloc(); - -int main() { - int b; - int* a = &b; - a[0] = 42; - printf("%d\n", *a); - return 0; -} -EOF - -cat <<'EOF' > expected -0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 -9 9 -EOF -test_diff <<'EOF' -int printf(); -void* calloc(); - -int main() { - long* a = calloc(10, sizeof(long)); - long i = 0; - for (i = 0; i < 10; i = i + 1) { - a[i] = i; - } - for (i = 0; i < 10; i = i + 1) { - printf("%d %d\n", *(a + i), a[i]); - } - return 0; -} -EOF diff --git a/tests/034.sh b/tests/034.sh deleted file mode 100644 index ebf0a4e..0000000 --- a/tests/034.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -EOF -test_diff <<'EOF' -struct S { - int a; -}; - -struct S* f(); - -struct S* g() {} - -int main() { - return 0; -} -EOF diff --git a/tests/035.sh b/tests/035.sh deleted file mode 100644 index f411a27..0000000 --- a/tests/035.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -0 -1 -0 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("%d\n", !1); - printf("%d\n", !0); - printf("%d\n", !23); - return 0; -} -EOF diff --git a/tests/036.sh b/tests/036.sh deleted file mode 100644 index 0975bcf..0000000 --- a/tests/036.sh +++ /dev/null @@ -1,25 +0,0 @@ -cat <<'EOF' > expected -42 -EOF -test_diff <<'EOF' -void* calloc(); -int printf(); - -struct T; - -struct S { - struct T* a; -}; - -struct T { - int b; -}; - -int main() { - struct S* s = calloc(1, sizeof(struct S)); - s->a = calloc(1, sizeof(struct T)); - s->a->b = 42; - printf("%d\n", s->a->b); - return 0; -} -EOF diff --git a/tests/037.sh b/tests/037.sh deleted file mode 100644 index bef69a5..0000000 --- a/tests/037.sh +++ /dev/null @@ -1,16 +0,0 @@ -cat <<'EOF' > expected -hi -EOF -test_diff <<'EOF' -int printf(); - -void f() { - printf("hi\n"); - return; -} - -int main() { - f(); - return 0; -} -EOF diff --git a/tests/039.sh b/tests/039.sh deleted file mode 100644 index f00d024..0000000 --- a/tests/039.sh +++ /dev/null @@ -1,30 +0,0 @@ -cat <<'EOF' > expected -65 -65 -66 -67 -68 -EOF -test_diff <<'EOF' -void* calloc(); -int printf(); - -int main() { - char* source = calloc(4, sizeof(char)); - - source[0] = 'A'; - source[1] = 'B'; - source[2] = 'C'; - source[3] = 'D'; - - int a = source[0]; - - printf("%d\n", a); - printf("%d\n", source[0]); - printf("%d\n", source[1]); - printf("%d\n", source[2]); - printf("%d\n", source[3]); - - return 0; -} -EOF diff --git a/tests/040.sh b/tests/040.sh deleted file mode 100644 index 88ba93f..0000000 --- a/tests/040.sh +++ /dev/null @@ -1,38 +0,0 @@ -cat <<'EOF' > expected -0 -1 -2 -3 -4 -10 -11 -12 -13 -14 -20 -21 -22 -23 -24 -25 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - int i = 0; - for (; i < 5; i = i + 1) { - printf("%d\n", i); - } - for (i = 10; i < 15; ) { - printf("%d\n", i); - i = i + 1; - } - for (i = 20; ; i = i + 1) { - printf("%d\n", i); - if (i == 25) break; - } - - return 0; -} -EOF diff --git a/tests/042.sh b/tests/042.sh deleted file mode 100644 index 8e2c85b..0000000 --- a/tests/042.sh +++ /dev/null @@ -1,18 +0,0 @@ -cat <<'EOF' > expected -42,123 -EOF -test_diff <<'EOF' -int printf(); - -#define A foo_a -#define B foo_b - -int main() { - int foo_a = 42; - int foo_b = 123; - - printf("%d,%d\n", A, B); - - return 0; -} -EOF diff --git a/tests/044.sh b/tests/044.sh deleted file mode 100644 index a460ae4..0000000 --- a/tests/044.sh +++ /dev/null @@ -1,20 +0,0 @@ -cat <<'EOF' > expected -4 -0,1,2 -EOF -test_diff <<'EOF' -int printf(); - -enum E { - A, - B, - C, -}; - -int main() { - enum E x = A; - printf("%d\n", sizeof(enum E)); - printf("%d,%d,%d\n", A, B, C); - return 0; -} -EOF diff --git a/tests/046.sh b/tests/046.sh deleted file mode 100644 index 240d969..0000000 --- a/tests/046.sh +++ /dev/null @@ -1,19 +0,0 @@ -cat <<'EOF' > expected -42 -EOF -test_diff <<'EOF' -void* calloc(); -int printf(); - -struct S { - int x; -}; -typedef struct S S; - -int main() { - S* s = calloc(1, sizeof(S)); - s->x = 42; - printf("%d\n", s->x); - return 0; -} -EOF diff --git a/tests/050.sh b/tests/050.sh deleted file mode 100644 index 1d3fe2d..0000000 --- a/tests/050.sh +++ /dev/null @@ -1,10 +0,0 @@ -cat <<'EOF' > expected -hello, world -EOF -test_diff <<'EOF' -int printf(); -int main() { - printf("hello, world\n"); - return 0; -} -EOF diff --git a/tests/051.sh b/tests/051.sh deleted file mode 100644 index f504664..0000000 --- a/tests/051.sh +++ /dev/null @@ -1,8 +0,0 @@ -cat <<'EOF' > expected -undefined function: f -EOF -test_compile_error <<'EOF' -int main() { - f(); -} -EOF diff --git a/tests/054.sh b/tests/054.sh deleted file mode 100644 index 4990b89..0000000 --- a/tests/054.sh +++ /dev/null @@ -1,21 +0,0 @@ -cat <<'EOF' > expected -0 -1 -EOF -test_diff <<'EOF' -int printf(); -void* calloc(); - -struct S { - int a; - int b; -}; - -int main() { - struct S* s = calloc(1, sizeof(struct S)); - s->b = 1; - printf("%ld\n", s->a); - printf("%ld\n", s->b); - return 0; -} -EOF diff --git a/tests/056.sh b/tests/056.sh deleted file mode 100644 index ff2ad18..0000000 --- a/tests/056.sh +++ /dev/null @@ -1,28 +0,0 @@ -cat <<'EOF' > expected -12 -EOF - -cat <<'EOF' > math.h -int multiply(int a, int b) { - return a * b; -} -EOF - -cat <<'EOF' > calc.h -#include "math.h" - -int calculate(int x) { - return multiply(x, 2); -} - -int printf(const char*, ...); -EOF - -test_diff <<'EOF' -#include "calc.h" - -int main() { - printf("%d\n", calculate(6)); - return 0; -} -EOF diff --git a/tests/057.sh b/tests/057.sh deleted file mode 100644 index 3649588..0000000 --- a/tests/057.sh +++ /dev/null @@ -1,11 +0,0 @@ -cat <<'EOF' > expected -main.c:1: cannot open include file: "nonexistent.h" -EOF - -test_compile_error <<'EOF' -#include "nonexistent.h" - -int main() { - return 0; -} -EOF diff --git a/tests/058.sh b/tests/058.sh deleted file mode 100644 index b491ad4..0000000 --- a/tests/058.sh +++ /dev/null @@ -1,23 +0,0 @@ -cat <<'EOF' > expected -include depth limit exceeded -EOF - -# Create circular include files -cat <<'EOF' > a.h -#include "b.h" -int a() { return 1; } -EOF - -cat <<'EOF' > b.h -#include "a.h" -int b() { return 2; } -EOF - -test_compile_error <<'EOF' -#include "a.h" - -int main() { - a() + b(); - return 0; -} -EOF diff --git a/tests/060.sh b/tests/060.sh deleted file mode 100644 index 7f80fcf..0000000 --- a/tests/060.sh +++ /dev/null @@ -1,18 +0,0 @@ -cat <<'EOF' > expected -42 -EOF - -cat <<'EOF' > header.h -#define A 42 -EOF - -test_diff <<'EOF' -#include "header.h" - -int printf(); - -int main() { - printf("%d\n", A); - return 0; -} -EOF diff --git a/tests/061.sh b/tests/061.sh deleted file mode 100644 index 019aac2..0000000 --- a/tests/061.sh +++ /dev/null @@ -1,12 +0,0 @@ -cat <<'EOF' > expected -1 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - printf("%d\n", __ducc__); - return 0; -} -EOF diff --git a/tests/062.sh b/tests/062.sh deleted file mode 100644 index 74ef2e1..0000000 --- a/tests/062.sh +++ /dev/null @@ -1,36 +0,0 @@ -cat <<'EOF' > expected -__ducc__ is defined. -A is defined. -B is undefined. -EOF - -test_diff <<'EOF' -int printf(); - -#define A 123 - -int main() { - -#ifdef __ducc__ - printf("__ducc__ is defined.\n"); -#else - printf("__ducc__ is undefined.\n"); -#endif - -#ifdef A - printf("A is defined.\n"); -#else - printf("A is undefined.\n"); -#endif - -#ifdef B - printf("B is defined.\n"); -#else - printf("B is undefined.\n"); -#endif - -#define B 456 - - return 0; -} -EOF diff --git a/tests/066.sh b/tests/066.sh deleted file mode 100644 index 0a5e570..0000000 --- a/tests/066.sh +++ /dev/null @@ -1,13 +0,0 @@ -cat <<'EOF' > expected -24 -EOF - -test_diff <<'EOF' -#include <stdarg.h> - -int printf(); - -int main() { - printf("%d\n", sizeof(va_list)); -} -EOF diff --git a/tests/067.sh b/tests/067.sh deleted file mode 100644 index fa8510f..0000000 --- a/tests/067.sh +++ /dev/null @@ -1,13 +0,0 @@ -cat <<'EOF' > expected -123 -460 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - printf("%d\n", 0 | 123); - printf("%d\n", 12 | 456); -} -EOF diff --git a/tests/068.sh b/tests/068.sh deleted file mode 100644 index b3fc394..0000000 --- a/tests/068.sh +++ /dev/null @@ -1,27 +0,0 @@ -cat <<'EOF' > expected -0 -1 -4 -9 -16 -25 -36 -49 -64 -81 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - int i; - int a[10]; - for (i = 0; i < 10; ++i) { - a[i] = i * i; - } - for (i = 0; i < 10; ++i) { - printf("%d\n", a[i]); - } -} -EOF diff --git a/tests/069.sh b/tests/069.sh deleted file mode 100644 index 6be03e5..0000000 --- a/tests/069.sh +++ /dev/null @@ -1,16 +0,0 @@ -cat <<'EOF' > expected -h -l -, -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - char* h = " hello,world" + 1; - printf("%c\n", *h); - printf("%c\n", h[2]); - printf("%c\n", *(h + 5)); -} -EOF diff --git a/tests/070.sh b/tests/070.sh deleted file mode 100644 index e90f1e0..0000000 --- a/tests/070.sh +++ /dev/null @@ -1,13 +0,0 @@ -cat <<'EOF' > expected -123 -EOF - -test_diff <<'EOF' -#define foo() 123 - -int printf(); - -int main() { - printf("%d\n", foo()); -} -EOF diff --git a/tests/071.sh b/tests/071.sh deleted file mode 100644 index 6af34ee..0000000 --- a/tests/071.sh +++ /dev/null @@ -1,16 +0,0 @@ -cat <<'EOF' > expected -579 -975 -EOF - -test_diff <<'EOF' -#define foo 123 + 456 -#define bar() 321 + 654 - -int printf(); - -int main() { - printf("%d\n", foo); - printf("%d\n", bar()); -} -EOF diff --git a/tests/073.sh b/tests/073.sh deleted file mode 100644 index c804692..0000000 --- a/tests/073.sh +++ /dev/null @@ -1,20 +0,0 @@ -cat <<'EOF' > expected -main.c -main.c -main.c -EOF - -cat <<'EOF' > header.h -#define A __FILE__ -EOF - -test_diff <<'EOF' -#define B __FILE__ -#include "header.h" -int printf(); -int main() { - printf("%s\n", __FILE__); - printf("%s\n", B); - printf("%s\n", A); -} -EOF diff --git a/tests/074.sh b/tests/074.sh deleted file mode 100644 index f7ac0fe..0000000 --- a/tests/074.sh +++ /dev/null @@ -1,20 +0,0 @@ -cat <<'EOF' > expected -5 -6 6 -7 7 -EOF - -cat <<'EOF' > header.h -#define A __LINE__ -EOF - -test_diff <<'EOF' -#define B __LINE__ -#include "header.h" -int printf(); -int main() { - printf("%d\n", __LINE__); - printf("%d %d\n", B, B); - printf("%d %d\n", A, A); -} -EOF diff --git a/tests/075.sh b/tests/075.sh deleted file mode 100644 index 2f15211..0000000 --- a/tests/075.sh +++ /dev/null @@ -1,14 +0,0 @@ -cat <<'EOF' > expected -EOF - -test_diff <<'EOF' -/* lorem ipsum */ -/* -lorem ipsum -*/ -// /* -/* /* - */ -int/**/main() { -} -EOF diff --git a/tests/076.sh b/tests/076.sh deleted file mode 100644 index 71de9d7..0000000 --- a/tests/076.sh +++ /dev/null @@ -1,33 +0,0 @@ -cat <<'EOF' > expected -sizeof(a) = 4 -sizeof(b) = 8 -sizeof(c) = 123 -sizeof(d) = 16 -sizeof(e) = 8 -sizeof(f) = 1968 -EOF -test_diff <<'EOF' -int printf(); - -struct S { - long x; - long y; -}; - -int main() { - int a; - long b; - char c[123]; - struct S d; - void* e; - struct S f[123]; - - printf("sizeof(a) = %d\n", sizeof(a)); - printf("sizeof(b) = %d\n", sizeof(b)); - printf("sizeof(c) = %d\n", sizeof(c)); - printf("sizeof(d) = %d\n", sizeof(d)); - printf("sizeof(e) = %d\n", sizeof(e)); - printf("sizeof(f) = %d\n", sizeof(f)); - return 0; -} -EOF diff --git a/tests/077.sh b/tests/077.sh deleted file mode 100644 index 89cfb8c..0000000 --- a/tests/077.sh +++ /dev/null @@ -1,10 +0,0 @@ -cat <<'EOF' > expected -0 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - printf("%d\n", '\0'); -} -EOF diff --git a/tests/085.sh b/tests/085.sh deleted file mode 100644 index 9e2f32d..0000000 --- a/tests/085.sh +++ /dev/null @@ -1,38 +0,0 @@ -cat <<'EOF' > expected -0 -42 -48 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -0 -123 -EOF - -test_diff <<'EOF' -int printf(); - -int a; -int b[12]; - -int main() { - printf("%d\n", a); - a = 42; - printf("%d\n", a); - printf("%zu\n", sizeof(b)); - int i; - for (i = 0; i < 12; ++i) { - printf("%d\n", b[i]); - } - b[11] = 123; - printf("%d\n", b[11]); -} -EOF diff --git a/tests/086.sh b/tests/086.sh deleted file mode 100644 index 93b1e14..0000000 --- a/tests/086.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -105 -0 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - char* s = "hi"; - while (*s++) { - printf("%d\n", *s); - } -} -EOF diff --git a/tests/087.sh b/tests/087.sh deleted file mode 100644 index 57e7612..0000000 --- a/tests/087.sh +++ /dev/null @@ -1,22 +0,0 @@ -cat <<'EOF' > expected -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - for (int i = 0; i < 10; i++) { - printf("%d\n", i); - } -} -EOF diff --git a/tests/088.sh b/tests/088.sh deleted file mode 100644 index 06c88ee..0000000 --- a/tests/088.sh +++ /dev/null @@ -1,33 +0,0 @@ -cat <<'EOF' > expected -0 -1 -2 -3 -4 -0 -1 -2 -3 -4 -43 -42 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - for (int i = 0; i < 5; i++) { - printf("%d\n", i); - } - for (int i = 0; i < 5; i++) { - printf("%d\n", i); - } - int x = 42; - { - int x = 43; - printf("%d\n", x); - } - printf("%d\n", x); -} -EOF diff --git a/tests/089.sh b/tests/089.sh deleted file mode 100644 index e467a26..0000000 --- a/tests/089.sh +++ /dev/null @@ -1,23 +0,0 @@ -cat <<'EOF' > expected -8 -336 -EOF -test_diff <<'EOF' -int printf(); -int main() { - printf("%d\n", 1 << 3); - printf("%d\n", 21 << 4); -} -EOF - -cat <<'EOF' > expected -13 -0 -EOF -test_diff <<'EOF' -int printf(); -int main() { - printf("%d\n", 111 >> 3); - printf("%d\n", 15 >> 14); -} -EOF diff --git a/tests/090.sh b/tests/090.sh deleted file mode 100644 index e5e4df8..0000000 --- a/tests/090.sh +++ /dev/null @@ -1,19 +0,0 @@ -cat <<'EOF' > expected -0 0 -1 1 -2 2 -3 3 -4 4 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - int i = 1000; - int j = 1000; - for (i = 0, j = 0; i < 5; i++, j++) { - printf("%d %d\n", i, j); - } -} -EOF diff --git a/tests/093.sh b/tests/093.sh deleted file mode 100644 index a22e168..0000000 --- a/tests/093.sh +++ /dev/null @@ -1,20 +0,0 @@ -cat <<'EOF' > expected -42 -246 -221 -EOF - -test_diff <<'EOF' -int printf(); - -#define A(x) x -#define B(x) x+x -#define C(x, y) x*y - -int main() { - printf("%d\n", A(42)); - printf("%d\n", B - (123)); - printf("%d\n", C (13, 17)); -} -EOF diff --git a/tests/096.sh b/tests/096.sh deleted file mode 100644 index 7963ed7..0000000 --- a/tests/096.sh +++ /dev/null @@ -1,39 +0,0 @@ -cat <<'EOF' > expected -10 20 -100 300 500 -EOF - -test_diff <<'EOF' -int printf(); -in\ -t ma\ -in() { - int x = 1\ -0; - - int y = 2\ -\ -\ -0; - -#def\ -ine X 100 -#define Y 100 + \ -200 -#define Z /* -*/ 500 - // comment \ - x *= 100, y *= 200; - /* comment *\ -/ - - printf("%d %d\n", x, y); - printf("%d %d %d\n", X, Y, Z); -} -EOF - -cat <<'EOF' > expected -main.c:1: <new-line> expected, but got <eof> -EOF - -echo -n 'int main() {}\' | test_compile_error diff --git a/tests/097.sh b/tests/097.sh deleted file mode 100644 index c5b8d0d..0000000 --- a/tests/097.sh +++ /dev/null @@ -1,18 +0,0 @@ -cat <<'EOF' > expected -1 -EOF - -test_diff <<'EOF' -int printf(); - -#define A -#define B - -int main() { -#if defined A && defined(B) - printf("1\n"); -#else - printf("2\n"); -#endif -} -EOF diff --git a/tests/100.sh b/tests/100.sh deleted file mode 100644 index 9df8476..0000000 --- a/tests/100.sh +++ /dev/null @@ -1,44 +0,0 @@ -cat <<'EOF' > expected -1 -1 -2 -3 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { -#if 1 - printf("1\n"); -#elif 1 - printf("2\n"); -#else - printf("3\n"); -#endif - -#if 1 - printf("1\n"); -#elif 0 - printf("2\n"); -#else - printf("3\n"); -#endif - -#if 0 - printf("1\n"); -#elif 1 - printf("2\n"); -#else - printf("3\n"); -#endif - -#if 0 - printf("1\n"); -#elif 0 - printf("2\n"); -#else - printf("3\n"); -#endif -} -EOF diff --git a/tests/101.sh b/tests/101.sh deleted file mode 100644 index 338b879..0000000 --- a/tests/101.sh +++ /dev/null @@ -1,22 +0,0 @@ -cat <<'EOF' > expected -main.c:2: expected '#endif', but got '<eof>' -EOF -test_compile_error <<'EOF' -#if 0 -EOF - -cat <<'EOF' > expected -main.c:3: expected '#endif', but got '<eof>' -EOF -test_compile_error <<'EOF' -#if 1 -#else -EOF - -cat <<'EOF' > expected -main.c:3: expected '#endif', but got '<eof>' -EOF -test_compile_error <<'EOF' -#if 1 -#elif 1 -EOF diff --git a/tests/104.sh b/tests/104.sh deleted file mode 100644 index d385e23..0000000 --- a/tests/104.sh +++ /dev/null @@ -1,32 +0,0 @@ -cat <<'EOF' > expected -4 -EOF -test_diff <<'EOF' -struct S0; -typedef struct S0 S0; - -struct S1 { - int x; -}; - -struct S2 { - int x; -}; - -struct S3 { - int x; -}; - -struct S4 { - int x; -}; - -struct S0 { - int x; -}; - -int printf(const char*, ...); -int main() { - printf("%zu\n", sizeof(S0)); -} -EOF diff --git a/tests/108.sh b/tests/108.sh deleted file mode 100644 index 7dab53b..0000000 --- a/tests/108.sh +++ /dev/null @@ -1,26 +0,0 @@ -cat <<'EOF' > expected -123 -EOF -test_diff <<'EOF' -#define A(x) x - -int printf(); - -int main() { - printf("%d\n", A ( 123 )); -} -EOF - -cat <<'EOF' > expected -main.c:4: expected ')', but got '<new-line>' -EOF -test_compile_error <<'EOF' -#define A(x) x - -int main() { -#if A ( - 123) < A(345) - printf("1\n"); -#endif -} -EOF diff --git a/tests/110.sh b/tests/110.sh deleted file mode 100644 index 4d48752..0000000 --- a/tests/110.sh +++ /dev/null @@ -1,15 +0,0 @@ -cat <<'EOF' > expected -main.c:1: cannot open include file: "hoge.h" -EOF - -test_compile_error <<'EOF' -#include "hoge.h" -EOF - -cat <<'EOF' > expected -main.c:1: cannot resolve include file name: <hoge.h> -EOF - -test_compile_error <<'EOF' -#include <hoge.h> -EOF diff --git a/tests/112.sh b/tests/112.sh deleted file mode 100644 index c56e0d6..0000000 --- a/tests/112.sh +++ /dev/null @@ -1,35 +0,0 @@ -cat <<'EOF' > expected -42 -100 200 -300 -0 -1 2 3 -15 -42 -123 -879 -EOF - -test_diff <<'EOF' -int printf(); - -#define ADD(a, b) ((a) + (b)) -#define PRINT_TWO(x, y) printf("%d %d\n", x, y) -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define NESTED(x) (x) -#define CONCAT3(a, b, c) a ## b ## c - -int main() { - printf("%d\n", ADD(40, 2)); - PRINT_TWO(100, 200); - printf("%d\n", MAX(100 + 200, 250)); - printf("%d\n"); - NESTED((printf("1 "), printf("2 "), printf("3\n"), 0)); - - int x = 5, y = 10; - printf("%d\n", ADD(x + 2, y - 2)); - printf("%d\n", ADD(MAX(10, 20), MAX(15 + 5, 22))); - printf("%d\n", ADD( 100 , 23 )); - printf("%d\n", ADD(NESTED((100 + 200)), MAX((123 + 456), (111 + 222)))); -} -EOF diff --git a/tests/114.sh b/tests/114.sh deleted file mode 100644 index 1ba1e8a..0000000 --- a/tests/114.sh +++ /dev/null @@ -1,26 +0,0 @@ -cat <<'EOF' > expected -1 -7 -6 -4 -3 2 3 0 -EOF -test_diff <<'EOF' -int printf(); - -int main() { - int a = 5; - int b = 3; - - printf("%d\n", a & b); - printf("%d\n", a | b); - printf("%d\n", a ^ b); - printf("%d\n", 2 + 3 & 4); - - int c = 1 + 2 & 3; - int d = 4 & 5 ^ 6; - int e = 1 ^ 2 | 3; - int f = 0 | 1 & 2; - printf("%d %d %d %d\n", c, d, e, f); -} -EOF diff --git a/tests/117.sh b/tests/117.sh deleted file mode 100644 index 765dc58..0000000 --- a/tests/117.sh +++ /dev/null @@ -1,31 +0,0 @@ -cat <<'EOF' > expected -8 -4 -4 -EOF - -test_diff <<'EOF' -int printf(); - -typedef struct { - int x; - int y; -} S; - -typedef union { - int a; - char b; -} U; - -typedef enum { - RED, - GREEN, - BLUE -} E; - -int main() { - printf("%zu\n", sizeof(S)); - printf("%zu\n", sizeof(U)); - printf("%zu\n", sizeof(E)); -} -EOF diff --git a/tests/118.sh b/tests/118.sh deleted file mode 100644 index 48a8569..0000000 --- a/tests/118.sh +++ /dev/null @@ -1,19 +0,0 @@ -cat <<'EOF' > expected -400 -80 -16 -EOF - -test_diff <<'EOF' -int printf(); - -int main() { - int a[10 * 10]; - int b[10 + 10]; - int c[1 << 2]; - - printf("%zu\n", sizeof(a)); - printf("%zu\n", sizeof(b)); - printf("%zu\n", sizeof(c)); -} -EOF diff --git a/tests/120.sh b/tests/120.sh deleted file mode 100644 index b3724cd..0000000 --- a/tests/120.sh +++ /dev/null @@ -1,21 +0,0 @@ -cat <<'EOF' > expected -42 -123 -EOF -test_diff <<'EOF' -int printf(const char*, ...); - -int main() { - // TODO: check if "foo" is expanded to "foo" or not once '#' operator is implemented. -#define foo foo - int foo = 42; - printf("%d\n", foo); - - // TODO: check if "a" is expanded to "a" or not once '#' operator is implemented. -#define a b -#define b c -#define c a - int a = 123; - printf("%d\n", a); -} -EOF diff --git a/tests/all.sh b/tests/all.sh index cb5df2b..a5c6df8 100644 --- a/tests/all.sh +++ b/tests/all.sh @@ -8,7 +8,7 @@ for filename in tests/*.sh; do testcase="${testcase_/%.sh/}" test_file="tests/$testcase.sh" case "$testcase" in - all|run|test_*) + all|run|helpers) ;; *) source tests/run.sh "$testcase" diff --git a/tests/test_helpers.sh b/tests/helpers.sh index eaccd5c..eaccd5c 100644 --- a/tests/test_helpers.sh +++ b/tests/helpers.sh diff --git a/tests/run.sh b/tests/run.sh index 728af52..1003e87 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -12,7 +12,7 @@ if [[ ! -f "$test_file" ]]; then exit 1 fi -source tests/test_helpers.sh +source tests/helpers.sh echo "$test_file" mkdir -p "$tmp_dir" diff --git a/tests/test_arithmetic_operators.sh b/tests/test_arithmetic_operators.sh new file mode 100644 index 0000000..50cb1ec --- /dev/null +++ b/tests/test_arithmetic_operators.sh @@ -0,0 +1,30 @@ +test_exit_code 42 <<'EOF' +int main() { + return 42; +} +EOF + +test_exit_code 21 <<'EOF' +int main() { + return 5+20-4; +} +EOF + +test_exit_code 26 <<'EOF' +int main() { + return 2*3+4*5; +} +EOF + +test_exit_code 197 <<'EOF' +int main() { + return (((3+5)/2) + (5*(9-6)) * (5+6*7)) % 256; +} +EOF + +test_exit_code 30 <<'EOF' +int main() { + return (-10 + 20 * -3) + 100; +} +EOF + diff --git a/tests/test_array_basics.sh b/tests/test_array_basics.sh new file mode 100644 index 0000000..75bb244 --- /dev/null +++ b/tests/test_array_basics.sh @@ -0,0 +1,163 @@ +cat <<'EOF' > expected +42 +EOF +test_diff <<'EOF' +int printf(); +void* calloc(); + +int main() { + int b; + int* a = &b; + a[0] = 42; + printf("%d\n", *a); + return 0; +} +EOF + +cat <<'EOF' > expected +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 +EOF +test_diff <<'EOF' +int printf(); +void* calloc(); + +int main() { + long* a = calloc(10, sizeof(long)); + long i = 0; + for (i = 0; i < 10; i = i + 1) { + a[i] = i; + } + for (i = 0; i < 10; i = i + 1) { + printf("%d %d\n", *(a + i), a[i]); + } + return 0; +} +EOF + +cat <<'EOF' > expected +65 +65 +66 +67 +68 +EOF +test_diff <<'EOF' +void* calloc(); +int printf(); + +int main() { + char* source = calloc(4, sizeof(char)); + + source[0] = 'A'; + source[1] = 'B'; + source[2] = 'C'; + source[3] = 'D'; + + int a = source[0]; + + printf("%d\n", a); + printf("%d\n", source[0]); + printf("%d\n", source[1]); + printf("%d\n", source[2]); + printf("%d\n", source[3]); + + return 0; +} +EOF + +cat <<'EOF' > expected +0 +1 +4 +9 +16 +25 +36 +49 +64 +81 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + int i; + int a[10]; + for (i = 0; i < 10; ++i) { + a[i] = i * i; + } + for (i = 0; i < 10; ++i) { + printf("%d\n", a[i]); + } +} +EOF + +cat <<'EOF' > expected +0 +42 +48 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +123 +EOF + +test_diff <<'EOF' +int printf(); + +int a; +int b[12]; + +int main() { + printf("%d\n", a); + a = 42; + printf("%d\n", a); + printf("%zu\n", sizeof(b)); + int i; + for (i = 0; i < 12; ++i) { + printf("%d\n", b[i]); + } + b[11] = 123; + printf("%d\n", b[11]); +} +EOF + +cat <<'EOF' > expected +400 +80 +16 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + int a[10 * 10]; + int b[10 + 10]; + int c[1 << 2]; + + printf("%zu\n", sizeof(a)); + printf("%zu\n", sizeof(b)); + printf("%zu\n", sizeof(c)); +} +EOF + diff --git a/tests/041.sh b/tests/test_assignment_operators.sh index a867cac..c1cce28 100644 --- a/tests/041.sh +++ b/tests/test_assignment_operators.sh @@ -46,3 +46,4 @@ int main() { return 0; } EOF + diff --git a/tests/test_bitwise_operators.sh b/tests/test_bitwise_operators.sh new file mode 100644 index 0000000..90f553a --- /dev/null +++ b/tests/test_bitwise_operators.sh @@ -0,0 +1,65 @@ +cat <<'EOF' > expected +123 +460 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + printf("%d\n", 0 | 123); + printf("%d\n", 12 | 456); +} +EOF + +cat <<'EOF' > expected +8 +336 +EOF +test_diff <<'EOF' +int printf(); +int main() { + printf("%d\n", 1 << 3); + printf("%d\n", 21 << 4); +} +EOF + +cat <<'EOF' > expected +13 +0 +EOF +test_diff <<'EOF' +int printf(); +int main() { + printf("%d\n", 111 >> 3); + printf("%d\n", 15 >> 14); +} +EOF + +cat <<'EOF' > expected +1 +7 +6 +4 +3 2 3 0 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + int a = 5; + int b = 3; + + printf("%d\n", a & b); + printf("%d\n", a | b); + printf("%d\n", a ^ b); + printf("%d\n", 2 + 3 & 4); + + int c = 1 + 2 & 3; + int d = 4 & 5 ^ 6; + int e = 1 ^ 2 | 3; + int f = 0 | 1 & 2; + printf("%d %d %d %d\n", c, d, e, f); +} +EOF + diff --git a/tests/119.sh b/tests/test_bool_type.sh index be485cf..16087bf 100644 --- a/tests/119.sh +++ b/tests/test_bool_type.sh @@ -11,3 +11,4 @@ int main() { printf("%d,%d,%d\n", sizeof(b1), sizeof(b0), sizeof(bool)); } EOF + diff --git a/tests/053.sh b/tests/test_char_literals.sh index f97a17d..3d1bff3 100644 --- a/tests/053.sh +++ b/tests/test_char_literals.sh @@ -1,4 +1,20 @@ cat <<'EOF' > expected +97 48 +92 39 +10 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("%d %d\n", 'a', '0'); + printf("%d %d\n", '\\', '\''); + printf("%d\n", '\n'); + return 0; +} +EOF + +cat <<'EOF' > expected 39 34 63 @@ -29,3 +45,15 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +0 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("%d\n", '\0'); +} +EOF + diff --git a/tests/095.sh b/tests/test_comma_operator.sh index 5d274d0..7c53845 100644 --- a/tests/095.sh +++ b/tests/test_comma_operator.sh @@ -1,4 +1,24 @@ cat <<'EOF' > expected +0 0 +1 1 +2 2 +3 3 +4 4 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + int i = 1000; + int j = 1000; + for (i = 0, j = 0; i < 5; i++, j++) { + printf("%d %d\n", i, j); + } +} +EOF + +cat <<'EOF' > expected 1 2 3 4 0 0 5 EOF @@ -14,3 +34,4 @@ int main() { printf("%d %d %d\n", x, y, z); } EOF + diff --git a/tests/048.sh b/tests/test_command_line_args.sh index 7286815..094b36c 100644 --- a/tests/048.sh +++ b/tests/test_command_line_args.sh @@ -16,3 +16,4 @@ int main(int argc, char** argv) { return 0; } EOF + diff --git a/tests/052.sh b/tests/test_comments.sh index 73bcd5d..7a43832 100644 --- a/tests/052.sh +++ b/tests/test_comments.sh @@ -7,3 +7,19 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +EOF + +test_diff <<'EOF' +/* lorem ipsum */ +/* +lorem ipsum +*/ +// /* +/* /* + */ +int/**/main() { +} +EOF + diff --git a/tests/006.sh b/tests/test_comparison_operators.sh index ee88013..3b6d827 100644 --- a/tests/006.sh +++ b/tests/test_comparison_operators.sh @@ -45,3 +45,4 @@ int main() { return 123 < 123; } EOF + diff --git a/tests/059.sh b/tests/test_compile_errors.sh index b478b14..23bf394 100644 --- a/tests/059.sh +++ b/tests/test_compile_errors.sh @@ -1,3 +1,12 @@ +cat <<'EOF' > expected +undefined function: f +EOF +test_compile_error <<'EOF' +int main() { + f(); +} +EOF + # TODO: improve error message # cat <<'EOF' > expected # main.c:1: expected ';' or '{', but got '}' @@ -21,3 +30,4 @@ EOF test_compile_error <<'EOF' int main() 123 EOF + diff --git a/tests/098.sh b/tests/test_compiler_output.sh index 33c4f17..6993c36 100644 --- a/tests/098.sh +++ b/tests/test_compiler_output.sh @@ -14,3 +14,4 @@ if [[ $exit_code -ne 0 ]]; then echo "invalid exit code: $exit_code" >&2 exit 1 fi + diff --git a/tests/111.sh b/tests/test_compiler_version.sh index 5b21831..1e22718 100644 --- a/tests/111.sh +++ b/tests/test_compiler_version.sh @@ -4,3 +4,4 @@ if [[ "$("$ducc" --version)" != "$expected" ]]; then echo "invalid output" >&2 exit 1 fi + diff --git a/tests/106.sh b/tests/test_conditional_errors.sh index 2a61a33..5a33e8c 100644 --- a/tests/106.sh +++ b/tests/test_conditional_errors.sh @@ -1,4 +1,27 @@ cat <<'EOF' > expected +main.c:2: expected '#endif', but got '<eof>' +EOF +test_compile_error <<'EOF' +#if 0 +EOF + +cat <<'EOF' > expected +main.c:3: expected '#endif', but got '<eof>' +EOF +test_compile_error <<'EOF' +#if 1 +#else +EOF + +cat <<'EOF' > expected +main.c:3: expected '#endif', but got '<eof>' +EOF +test_compile_error <<'EOF' +#if 1 +#elif 1 +EOF + +cat <<'EOF' > expected main.c:1: unexpected '#elif'; no corresponding '#if'* EOF test_compile_error <<'EOF' @@ -48,3 +71,4 @@ test_compile_error <<'EOF' int main() {} EOF + diff --git a/tests/test_define_macros.sh b/tests/test_define_macros.sh new file mode 100644 index 0000000..1b674f1 --- /dev/null +++ b/tests/test_define_macros.sh @@ -0,0 +1,92 @@ +cat <<'EOF' > expected +EOF +test_diff <<'EOF' +#define A 1 +int main() { + return 0; +} +EOF + +cat <<'EOF' > expected +1,2,3 +EOF +test_diff <<'EOF' +int printf(); + +#define A 1 +#define B 2 +#define C 3 + +int main() { + printf("%d,%d,%d\n", A, B, C); + return 0; +} +EOF + +cat <<'EOF' > expected +0,0,0,0 +EOF +test_diff <<'EOF' +int printf(); + +#define NULL 0 +#define TK_EOF 0 +#define TY_UNKNOWN 0 +#define AST_UNKNOWN 0 + +int main() { + printf("%d,%d,%d,%d\n", NULL, TK_EOF, TY_UNKNOWN, AST_UNKNOWN); + return 0; +} +EOF + +cat <<'EOF' > expected +42,123 +EOF +test_diff <<'EOF' +int printf(); + +#define A foo_a +#define B foo_b + +int main() { + int foo_a = 42; + int foo_b = 123; + + printf("%d,%d\n", A, B); + + return 0; +} +EOF + +cat <<'EOF' > expected +123 +EOF + +test_diff <<'EOF' +#define foo() 123 + +int printf(); + +int main() { + printf("%d\n", foo()); +} +EOF + +cat <<'EOF' > expected +579 +975 +EOF + +test_diff <<'EOF' +#define foo 123 + 456 +#define bar() 321 + 654 + +int printf(); + +int main() { + printf("%d\n", foo); + printf("%d\n", bar()); +} +EOF + diff --git a/tests/047.sh b/tests/test_do_while.sh index 57d0d8f..dbb4815 100644 --- a/tests/047.sh +++ b/tests/test_do_while.sh @@ -89,3 +89,4 @@ int main() { return 0; } EOF + diff --git a/tests/099.sh b/tests/test_empty_preprocessor.sh index 5a744a8..57e33ad 100644 --- a/tests/099.sh +++ b/tests/test_empty_preprocessor.sh @@ -7,3 +7,4 @@ test_diff <<'EOF' # int main() {} EOF + diff --git a/tests/065.sh b/tests/test_empty_statements.sh index 8588944..71caed5 100644 --- a/tests/065.sh +++ b/tests/test_empty_statements.sh @@ -4,3 +4,4 @@ EOF test_diff <<'EOF' int main() { ; } EOF + diff --git a/tests/113.sh b/tests/test_enums.sh index 94e6e5f..228786a 100644 --- a/tests/113.sh +++ b/tests/test_enums.sh @@ -1,4 +1,25 @@ cat <<'EOF' > expected +4 +0,1,2 +EOF +test_diff <<'EOF' +int printf(); + +enum E { + A, + B, + C, +}; + +int main() { + enum E x = A; + printf("%d\n", sizeof(enum E)); + printf("%d,%d,%d\n", A, B, C); + return 0; +} +EOF + +cat <<'EOF' > expected 10,11,20,21 0,5,6 EOF @@ -24,3 +45,4 @@ int main() { printf("%d,%d,%d\n", E, F, G); } EOF + diff --git a/tests/103.sh b/tests/test_error_directive.sh index becfa50..a8b3fdb 100644 --- a/tests/103.sh +++ b/tests/test_error_directive.sh @@ -24,3 +24,4 @@ test_compile_error <<'EOF' #error "foo" EOF + diff --git a/tests/020.sh b/tests/test_example_programs.sh index abc3f8e..21b7ca4 100644 --- a/tests/020.sh +++ b/tests/test_example_programs.sh @@ -119,3 +119,15 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +hello, world +EOF +test_diff <<'EOF' +int printf(); +int main() { + printf("hello, world\n"); + return 0; +} +EOF + diff --git a/tests/049.sh b/tests/test_file_io.sh index 4484324..07a335e 100644 --- a/tests/049.sh +++ b/tests/test_file_io.sh @@ -28,3 +28,4 @@ int main() { return 0; } EOF + diff --git a/tests/test_for_loops.sh b/tests/test_for_loops.sh new file mode 100644 index 0000000..2e3205f --- /dev/null +++ b/tests/test_for_loops.sh @@ -0,0 +1,141 @@ +test_exit_code 45 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 10; i = i + 1) { + ret = ret + i; + } + return ret; +} +EOF + +test_exit_code 25 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 10; i = i + 1) { + if (i % 2 == 0) { + continue; + } + ret = ret + i; + } + return ret; +} +EOF + +test_exit_code 66 <<'EOF' +int main() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 100; i = i + 1) { + if (i == 12) { + break; + } + ret = ret + i; + } + return ret; +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +10 +11 +12 +13 +14 +20 +21 +22 +23 +24 +25 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + int i = 0; + for (; i < 5; i = i + 1) { + printf("%d\n", i); + } + for (i = 10; i < 15; ) { + printf("%d\n", i); + i = i + 1; + } + for (i = 20; ; i = i + 1) { + printf("%d\n", i); + if (i == 25) break; + } + + return 0; +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + for (int i = 0; i < 10; i++) { + printf("%d\n", i); + } +} +EOF + +cat <<'EOF' > expected +0 +1 +2 +3 +4 +0 +1 +2 +3 +4 +43 +42 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + for (int i = 0; i < 5; i++) { + printf("%d\n", i); + } + for (int i = 0; i < 5; i++) { + printf("%d\n", i); + } + int x = 42; + { + int x = 43; + printf("%d\n", x); + } + printf("%d\n", x); +} +EOF + diff --git a/tests/015.sh b/tests/test_function_basics.sh index e1964b8..eb99cf5 100644 --- a/tests/015.sh +++ b/tests/test_function_basics.sh @@ -1,3 +1,23 @@ +test_exit_code 66 <<'EOF' +int foo() { + int i; + int ret; + i = 0; + ret = 0; + for (i = 0; i < 100; i = i + 1) { + if (i == 12) { + break; + } + ret = ret + i; + } + return ret; +} + +int main() { + return foo(); +} +EOF + test_exit_code 10 <<'EOF' int f(int a, int b, int c, int d, int e, int f) { return a; @@ -57,3 +77,11 @@ int main() { return 10 * f(1, 2, 3, 4, 5, 6); } EOF + +touch expected +test_diff <<'EOF' +int main() { + return 0; +} +EOF + diff --git a/tests/test_function_macros.sh b/tests/test_function_macros.sh new file mode 100644 index 0000000..4bc0cc2 --- /dev/null +++ b/tests/test_function_macros.sh @@ -0,0 +1,106 @@ +cat <<'EOF' > expected +42 +246 +221 +EOF + +test_diff <<'EOF' +int printf(); + +#define A(x) x +#define B(x) x+x +#define C(x, y) x*y + +int main() { + printf("%d\n", A(42)); + printf("%d\n", B + (123)); + printf("%d\n", C (13, 17)); +} +EOF + +cat <<'EOF' > expected +123 +EOF +test_diff <<'EOF' +#define A(x) x + +int printf(); + +int main() { + printf("%d\n", A ( 123 )); +} +EOF + +cat <<'EOF' > expected +main.c:4: expected ')', but got '<new-line>' +EOF +test_compile_error <<'EOF' +#define A(x) x + +int main() { +#if A ( + 123) < A(345) + printf("1\n"); +#endif +} +EOF + +cat <<'EOF' > expected +42 +100 200 +300 +0 +1 2 3 +15 +42 +123 +879 +EOF + +test_diff <<'EOF' +int printf(); + +#define ADD(a, b) ((a) + (b)) +#define PRINT_TWO(x, y) printf("%d %d\n", x, y) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define NESTED(x) (x) +#define CONCAT3(a, b, c) a ## b ## c + +int main() { + printf("%d\n", ADD(40, 2)); + PRINT_TWO(100, 200); + printf("%d\n", MAX(100 + 200, 250)); + printf("%d\n"); + NESTED((printf("1 "), printf("2 "), printf("3\n"), 0)); + + int x = 5, y = 10; + printf("%d\n", ADD(x + 2, y - 2)); + printf("%d\n", ADD(MAX(10, 20), MAX(15 + 5, 22))); + printf("%d\n", ADD( 100 , 23 )); + printf("%d\n", ADD(NESTED((100 + 200)), MAX((123 + 456), (111 + 222)))); +} +EOF + +cat <<'EOF' > expected +42 +123 +EOF +test_diff <<'EOF' +int printf(const char*, ...); + +int main() { + // TODO: check if "foo" is expanded to "foo" or not once '#' operator is implemented. +#define foo foo + int foo = 42; + printf("%d\n", foo); + + // TODO: check if "a" is expanded to "a" or not once '#' operator is implemented. +#define a b +#define b c +#define c a + int a = 123; + printf("%d\n", a); +} +EOF + diff --git a/tests/092.sh b/tests/test_global_variables.sh index 20c3a1f..b4eef09 100644 --- a/tests/092.sh +++ b/tests/test_global_variables.sh @@ -13,3 +13,4 @@ int main() { printf("%d %d %d\n", a, b, c); } EOF + diff --git a/tests/043.sh b/tests/test_identifiers.sh index ae00bd3..5786ff7 100644 --- a/tests/043.sh +++ b/tests/test_identifiers.sh @@ -13,3 +13,4 @@ int main() { return 0; } EOF + diff --git a/tests/102.sh b/tests/test_if_elif_else.sh index b323893..a07dd5c 100644 --- a/tests/102.sh +++ b/tests/test_if_elif_else.sh @@ -1,5 +1,69 @@ cat <<'EOF' > expected 1 +EOF + +test_diff <<'EOF' +int printf(); + +#define A +#define B + +int main() { +#if defined A && defined(B) + printf("1\n"); +#else + printf("2\n"); +#endif +} +EOF + +cat <<'EOF' > expected +1 +1 +2 +3 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { +#if 1 + printf("1\n"); +#elif 1 + printf("2\n"); +#else + printf("3\n"); +#endif + +#if 1 + printf("1\n"); +#elif 0 + printf("2\n"); +#else + printf("3\n"); +#endif + +#if 0 + printf("1\n"); +#elif 1 + printf("2\n"); +#else + printf("3\n"); +#endif + +#if 0 + printf("1\n"); +#elif 0 + printf("2\n"); +#else + printf("3\n"); +#endif +} +EOF + +cat <<'EOF' > expected +1 1 2 2 @@ -126,3 +190,4 @@ int main() { #endif } EOF + diff --git a/tests/010.sh b/tests/test_if_else.sh index 4ddf39c..cad1716 100644 --- a/tests/010.sh +++ b/tests/test_if_else.sh @@ -17,3 +17,4 @@ int main() { } } EOF + diff --git a/tests/078.sh b/tests/test_ifdef_ifndef.sh index a9ac190..f59b87b 100644 --- a/tests/078.sh +++ b/tests/test_ifdef_ifndef.sh @@ -11,6 +11,43 @@ int printf(); int main() { +#ifdef __ducc__ + printf("__ducc__ is defined.\n"); +#else + printf("__ducc__ is undefined.\n"); +#endif + +#ifdef A + printf("A is defined.\n"); +#else + printf("A is undefined.\n"); +#endif + +#ifdef B + printf("B is defined.\n"); +#else + printf("B is undefined.\n"); +#endif + +#define B 456 + + return 0; +} +EOF + +cat <<'EOF' > expected +__ducc__ is defined. +A is defined. +B is undefined. +EOF + +test_diff <<'EOF' +int printf(); + +#define A 123 + +int main() { + #ifndef __ducc__ printf("__ducc__ is undefined.\n"); #else @@ -34,3 +71,4 @@ int main() { return 0; } EOF + diff --git a/tests/064.sh b/tests/test_implicit_return.sh index 20a8bed..423844e 100644 --- a/tests/064.sh +++ b/tests/test_implicit_return.sh @@ -16,3 +16,4 @@ int main() { else return 1; } EOF + diff --git a/tests/test_include_errors.sh b/tests/test_include_errors.sh new file mode 100644 index 0000000..3ac546f --- /dev/null +++ b/tests/test_include_errors.sh @@ -0,0 +1,52 @@ +cat <<'EOF' > expected +main.c:1: cannot open include file: "nonexistent.h" +EOF + +test_compile_error <<'EOF' +#include "nonexistent.h" + +int main() { + return 0; +} +EOF + +cat <<'EOF' > expected +include depth limit exceeded +EOF + +# Create circular include files +cat <<'EOF' > a.h +#include "b.h" +int a() { return 1; } +EOF + +cat <<'EOF' > b.h +#include "a.h" +int b() { return 2; } +EOF + +test_compile_error <<'EOF' +#include "a.h" + +int main() { + a() + b(); + return 0; +} +EOF + +cat <<'EOF' > expected +main.c:1: cannot open include file: "hoge.h" +EOF + +test_compile_error <<'EOF' +#include "hoge.h" +EOF + +cat <<'EOF' > expected +main.c:1: cannot resolve include file name: <hoge.h> +EOF + +test_compile_error <<'EOF' +#include <hoge.h> +EOF + diff --git a/tests/079.sh b/tests/test_include_guards.sh index f8f0462..87c44a9 100644 --- a/tests/079.sh +++ b/tests/test_include_guards.sh @@ -23,3 +23,4 @@ int main() { return 0; } EOF + diff --git a/tests/055.sh b/tests/test_include_local.sh index 997f12b..c9fe755 100644 --- a/tests/055.sh +++ b/tests/test_include_local.sh @@ -49,3 +49,52 @@ int main() { printf("%d\n", A); } EOF + +cat <<'EOF' > expected +12 +EOF + +cat <<'EOF' > math.h +int multiply(int a, int b) { + return a * b; +} +EOF + +cat <<'EOF' > calc.h +#include "math.h" + +int calculate(int x) { + return multiply(x, 2); +} + +int printf(const char*, ...); +EOF + +test_diff <<'EOF' +#include "calc.h" + +int main() { + printf("%d\n", calculate(6)); + return 0; +} +EOF + +cat <<'EOF' > expected +42 +EOF + +cat <<'EOF' > header.h +#define A 42 +EOF + +test_diff <<'EOF' +#include "header.h" + +int printf(); + +int main() { + printf("%d\n", A); + return 0; +} +EOF + diff --git a/tests/080.sh b/tests/test_increment_operators.sh index e7fb221..f6aa2b5 100644 --- a/tests/080.sh +++ b/tests/test_increment_operators.sh @@ -26,3 +26,4 @@ int main() { printf("%d\n", a); } EOF + diff --git a/tests/038.sh b/tests/test_input_operations.sh index 465108e..15dfb2f 100644 --- a/tests/038.sh +++ b/tests/test_input_operations.sh @@ -34,3 +34,4 @@ int main() { return 0; } EOF + diff --git a/tests/083.sh b/tests/test_invalid_directives.sh index 2152666..877f9e9 100644 --- a/tests/083.sh +++ b/tests/test_invalid_directives.sh @@ -25,3 +25,4 @@ test_diff <<'EOF' int main() {} EOF + diff --git a/tests/094.sh b/tests/test_keywords.sh index ae622bc..1b99b67 100644 --- a/tests/094.sh +++ b/tests/test_keywords.sh @@ -6,3 +6,4 @@ test_diff <<'EOF' auto printf(); auto main() {} EOF + diff --git a/tests/121.sh b/tests/test_line_continuation.sh index a5ecdb6..c5b5c2e 100644 --- a/tests/121.sh +++ b/tests/test_line_continuation.sh @@ -1,4 +1,44 @@ cat <<'EOF' > expected +10 20 +100 300 500 +EOF + +test_diff <<'EOF' +int printf(); +in\ +t ma\ +in() { + int x = 1\ +0; + + int y = 2\ +\ +\ +0; + +#def\ +ine X 100 +#define Y 100 + \ +200 +#define Z /* +*/ 500 + // comment \ + x *= 100, y *= 200; + /* comment *\ +/ + + printf("%d %d\n", x, y); + printf("%d %d %d\n", X, Y, Z); +} +EOF + +cat <<'EOF' > expected +main.c:1: <new-line> expected, but got <eof> +EOF + +echo -n 'int main() {}\' | test_compile_error + +cat <<'EOF' > expected Hello World Line continues EOF @@ -14,3 +54,4 @@ test_diff < main_cr.c # Mixed printf 'int printf(const char*, ...);\nint main() {\r\n printf("Hello World\\n");\r printf("Line con\\\r\ntinues\\n");\n return 0;\r\n}\r\n' > main_mixed.c test_diff < main_mixed.c + diff --git a/tests/009.sh b/tests/test_local_variables.sh index 821d330..09c40b9 100644 --- a/tests/009.sh +++ b/tests/test_local_variables.sh @@ -1,3 +1,21 @@ +test_exit_code 42 <<'EOF' +int main() { + int foo; + foo = 42; + return foo; +} +EOF + +test_exit_code 70 <<'EOF' +int main() { + int foo; + int bar; + foo = 42; + bar = 28; + return foo + bar; +} +EOF + test_exit_code 45 <<'EOF' int main() { int a1; @@ -33,3 +51,17 @@ int main() { 0; } EOF + +cat <<'EOF' > expected +42 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + int a = 42; + printf("%d\n", a); + return 0; +} +EOF + diff --git a/tests/030.sh b/tests/test_logical_operators.sh index fda5dc8..1cc6594 100644 --- a/tests/030.sh +++ b/tests/test_logical_operators.sh @@ -49,3 +49,20 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +0 +1 +0 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("%d\n", !1); + printf("%d\n", !0); + printf("%d\n", !23); + return 0; +} +EOF + diff --git a/tests/107.sh b/tests/test_macro_operators.sh index bb0c1a2..daf8f47 100644 --- a/tests/107.sh +++ b/tests/test_macro_operators.sh @@ -40,3 +40,4 @@ int main() { return 0; } EOF + diff --git a/tests/105.sh b/tests/test_nested_conditionals.sh index 7c673ab..d149e07 100644 --- a/tests/105.sh +++ b/tests/test_nested_conditionals.sh @@ -9,3 +9,4 @@ test_diff <<'EOF' int main() {} EOF + diff --git a/tests/test_pointer_basics.sh b/tests/test_pointer_basics.sh new file mode 100644 index 0000000..2f34821 --- /dev/null +++ b/tests/test_pointer_basics.sh @@ -0,0 +1,79 @@ +cat <<'EOF' > expected +EOF +test_diff <<'EOF' +int main() { + int a1; + int* a2; + char a3; + char* a4; + long a5; + long* a6; + void* a8; + int** a10; + char** a12; + long** a14; + void** a16; + int*** a18; + char*** a20; + long*** a22; + void*** a24; + return 0; +} +EOF + +cat <<'EOF' > expected +42 42 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + int x; + int* y; + y = &x; + *y = 42; + printf("%d %d\n", x, *y); + return 0; +} +EOF + +cat <<'EOF' > expected +3 +3 +3 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + char c; + int i; + long l; + c = 42; + i = 42*2; + l = 42*3; + + char* cp1; + char* cp2; + int* ip1; + int* ip2; + long* lp1; + long* lp2; + + cp1 = &c; + cp2 = &c + 3; + + ip1 = &i; + ip2 = &i + 3; + + lp1 = &l; + lp2 = &l + 3; + + printf("%d\n", cp2 - cp1); + printf("%d\n", ip2 - ip1); + printf("%d\n", lp2 - lp1); + + return 0; +} +EOF + diff --git a/tests/test_predefined_macros.sh b/tests/test_predefined_macros.sh new file mode 100644 index 0000000..51aeca8 --- /dev/null +++ b/tests/test_predefined_macros.sh @@ -0,0 +1,55 @@ +cat <<'EOF' > expected +1 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + printf("%d\n", __ducc__); + return 0; +} +EOF + +cat <<'EOF' > expected +main.c +main.c +main.c +EOF + +cat <<'EOF' > header.h +#define A __FILE__ +EOF + +test_diff <<'EOF' +#define B __FILE__ +#include "header.h" +int printf(); +int main() { + printf("%s\n", __FILE__); + printf("%s\n", B); + printf("%s\n", A); +} +EOF + +cat <<'EOF' > expected +5 +6 6 +7 7 +EOF + +cat <<'EOF' > header.h +#define A __LINE__ +EOF + +test_diff <<'EOF' +#define B __LINE__ +#include "header.h" +int printf(); +int main() { + printf("%d\n", __LINE__); + printf("%d %d\n", B, B); + printf("%d %d\n", A, A); +} +EOF + diff --git a/tests/109.sh b/tests/test_preprocessor_comments.sh index 40b2c82..0fcea83 100644 --- a/tests/109.sh +++ b/tests/test_preprocessor_comments.sh @@ -8,3 +8,4 @@ test_diff <<'EOF' int main() {} EOF + diff --git a/tests/115.sh b/tests/test_printf.sh index ea7ca0b..da35fcb 100644 --- a/tests/115.sh +++ b/tests/test_printf.sh @@ -1,3 +1,37 @@ +touch expected +test_diff <<'EOF' +int printf(); + +int main() { + printf(""); + return 0; +} +EOF + +cat <<'EOF' > expected +Hello, World! +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("Hello, World!\n"); + return 0; +} +EOF + +cat <<'EOF' > expected +"Hello, World!" +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("\"Hello, World!\"\n"); + return 0; +} +EOF + cat <<'EOF' > expected 1 1 @@ -183,3 +217,4 @@ int main() { printf("%d\n", sizeof(int long long unsigned)); } EOF + diff --git a/tests/016.sh b/tests/test_recursive_functions.sh index 82c433d..f9f0ee5 100644 --- a/tests/016.sh +++ b/tests/test_recursive_functions.sh @@ -11,3 +11,4 @@ int main() { return fib(10); } EOF + diff --git a/tests/081.sh b/tests/test_short_type.sh index b298a98..fcbec87 100644 --- a/tests/081.sh +++ b/tests/test_short_type.sh @@ -14,3 +14,4 @@ int main() { printf("%zu %hd\n", sizeof(b), *b); } EOF + diff --git a/tests/test_sizeof_operator.sh b/tests/test_sizeof_operator.sh new file mode 100644 index 0000000..b14e2ca --- /dev/null +++ b/tests/test_sizeof_operator.sh @@ -0,0 +1,177 @@ +cat <<'EOF' > expected +sizeof(int) = 4 +sizeof(int*) = 8 +sizeof(char) = 1 +sizeof(char*) = 8 +sizeof(long) = 8 +sizeof(long*) = 8 +sizeof(void*) = 8 +sizeof(int**) = 8 +sizeof(char**) = 8 +sizeof(long**) = 8 +sizeof(void**) = 8 +sizeof(int***) = 8 +sizeof(char***) = 8 +sizeof(long***) = 8 +sizeof(void***) = 8 +EOF +test_diff <<'EOF' +int printf(); + +int main() { + printf("sizeof(int) = %d\n", sizeof(int)); + printf("sizeof(int*) = %d\n", sizeof(int*)); + printf("sizeof(char) = %d\n", sizeof(char)); + printf("sizeof(char*) = %d\n", sizeof(char*)); + printf("sizeof(long) = %d\n", sizeof(long)); + printf("sizeof(long*) = %d\n", sizeof(long*)); + printf("sizeof(void*) = %d\n", sizeof(void*)); + printf("sizeof(int**) = %d\n", sizeof(int**)); + printf("sizeof(char**) = %d\n", sizeof(char**)); + printf("sizeof(long**) = %d\n", sizeof(long**)); + printf("sizeof(void**) = %d\n", sizeof(void**)); + printf("sizeof(int***) = %d\n", sizeof(int***)); + printf("sizeof(char***) = %d\n", sizeof(char***)); + printf("sizeof(long***) = %d\n", sizeof(long***)); + printf("sizeof(void***) = %d\n", sizeof(void***)); + return 0; +} +EOF + +cat <<'EOF' > expected +sizeof(struct Token) = 16 +sizeof(struct Define) = 16 +sizeof(struct Type) = 24 +sizeof(struct AstNode) = 128 +sizeof(struct LVar) = 16 +sizeof(struct Func) = 16 +sizeof(struct Parser) = 64 +sizeof(struct CodeGen) = 16 +EOF +test_diff <<'EOF' +struct Token { + int kind; + char* value; +}; + +struct Define { + char* from; + struct Token* to; +}; + +struct AstNode; + +struct Type { + int kind; + struct Type* to; + struct AstNode* members; +}; + +struct AstNode { + int kind; + struct AstNode* next; + struct AstNode* last; + char* name; + struct AstNode* func_params; + struct AstNode* func_body; + int int_value; + struct AstNode* expr1; + struct AstNode* expr2; + struct AstNode* expr3; + int op; + struct Type* ty; + int var_index; + struct AstNode* node1; + struct AstNode* node2; + char** str_literals; +}; + +struct LVar { + char* name; + struct Type* ty; +}; + +struct Func { + char* name; + struct Type* ty; +}; + +struct Parser { + struct Token* tokens; + int pos; + struct LVar* locals; + int n_locals; + struct Func* funcs; + int n_funcs; + char** str_literals; + int n_str_literals; +}; + +struct CodeGen { + int next_label; + int* loop_labels; +}; + +int printf(); + +int main() { + printf("sizeof(struct Token) = %d\n", sizeof(struct Token)); + printf("sizeof(struct Define) = %d\n", sizeof(struct Define)); + printf("sizeof(struct Type) = %d\n", sizeof(struct Type)); + printf("sizeof(struct AstNode) = %d\n", sizeof(struct AstNode)); + printf("sizeof(struct LVar) = %d\n", sizeof(struct LVar)); + printf("sizeof(struct Func) = %d\n", sizeof(struct Func)); + printf("sizeof(struct Parser) = %d\n", sizeof(struct Parser)); + printf("sizeof(struct CodeGen) = %d\n", sizeof(struct CodeGen)); + return 0; +} +EOF + +cat <<'EOF' > expected +24 +EOF + +test_diff <<'EOF' +#include <stdarg.h> + +int printf(); + +int main() { + printf("%d\n", sizeof(va_list)); +} +EOF + +cat <<'EOF' > expected +sizeof(a) = 4 +sizeof(b) = 8 +sizeof(c) = 123 +sizeof(d) = 16 +sizeof(e) = 8 +sizeof(f) = 1968 +EOF +test_diff <<'EOF' +int printf(); + +struct S { + long x; + long y; +}; + +int main() { + int a; + long b; + char c[123]; + struct S d; + void* e; + struct S f[123]; + + printf("sizeof(a) = %d\n", sizeof(a)); + printf("sizeof(b) = %d\n", sizeof(b)); + printf("sizeof(c) = %d\n", sizeof(c)); + printf("sizeof(d) = %d\n", sizeof(d)); + printf("sizeof(e) = %d\n", sizeof(e)); + printf("sizeof(f) = %d\n", sizeof(f)); + return 0; +} +EOF + diff --git a/tests/045.sh b/tests/test_stdlib_declarations.sh index efd6a30..c919b88 100644 --- a/tests/045.sh +++ b/tests/test_stdlib_declarations.sh @@ -19,3 +19,4 @@ char* strstr(const char*, const char*); int main() { return 0; } EOF + diff --git a/tests/test_string_operations.sh b/tests/test_string_operations.sh new file mode 100644 index 0000000..0c9a07e --- /dev/null +++ b/tests/test_string_operations.sh @@ -0,0 +1,57 @@ +touch expected +test_diff <<'EOF' +int main() { + ""; + return 0; +} +EOF + +touch expected +test_diff <<'EOF' +int main() { + "abc"; + return 0; +} +EOF + +touch expected +test_diff <<'EOF' +int main() { + "\"foo\"bar\\\n\""; + return 0; +} +EOF + +cat <<'EOF' > expected +h +l +, +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + char* h = " hello,world" + 1; + printf("%c\n", *h); + printf("%c\n", h[2]); + printf("%c\n", *(h + 5)); +} +EOF + +cat <<'EOF' > expected +105 +0 +EOF + +test_diff <<'EOF' +int printf(); + +int main() { + char* s = "hi"; + while (*s++) { + printf("%d\n", *s); + } +} +EOF + diff --git a/tests/116.sh b/tests/test_struct_arrays.sh index 628c0d3..ca1e0b2 100644 --- a/tests/116.sh +++ b/tests/test_struct_arrays.sh @@ -31,3 +31,4 @@ int main() { printf("%d\n", x.a[4]); } EOF + diff --git a/tests/027.sh b/tests/test_struct_basics.sh index 167d398..74e2458 100644 --- a/tests/027.sh +++ b/tests/test_struct_basics.sh @@ -68,3 +68,54 @@ int main() { return 0; } EOF + +cat <<'EOF' > expected +42 +123 +EOF +test_diff <<'EOF' +struct S { + int a; + int b; +}; + +int printf(); +void* calloc(); + +int main() { + struct S* sp; + sp = calloc(1, sizeof(struct S)); + sp->a = 42; + printf("%d\n", sp->a); + (*sp).b = 123; + printf("%d\n", (*sp).b); + return 0; +} +EOF + +cat <<'EOF' > expected +42 +EOF +test_diff <<'EOF' +void* calloc(); +int printf(); + +struct T; + +struct S { + struct T* a; +}; + +struct T { + int b; +}; + +int main() { + struct S* s = calloc(1, sizeof(struct S)); + s->a = calloc(1, sizeof(struct T)); + s->a->b = 42; + printf("%d\n", s->a->b); + return 0; +} +EOF + diff --git a/tests/072.sh b/tests/test_struct_initialization.sh index d82751c..0454c57 100644 --- a/tests/072.sh +++ b/tests/test_struct_initialization.sh @@ -1,4 +1,26 @@ cat <<'EOF' > expected +0 +1 +EOF +test_diff <<'EOF' +int printf(); +void* calloc(); + +struct S { + int a; + int b; +}; + +int main() { + struct S* s = calloc(1, sizeof(struct S)); + s->b = 1; + printf("%ld\n", s->a); + printf("%ld\n", s->b); + return 0; +} +EOF + +cat <<'EOF' > expected 123 456 0 0 123 456 @@ -83,3 +105,4 @@ int main() { printf("%d %d\n", s2.a, s2.b); } EOF + diff --git a/tests/091.sh b/tests/test_ternary_operator.sh index a64c8ff..c98ff43 100644 --- a/tests/091.sh +++ b/tests/test_ternary_operator.sh @@ -9,3 +9,4 @@ int main() { printf("%d %d\n", 1 ? 2 : 3, 0 ? 4 : 5); } EOF + diff --git a/tests/test_typedef_struct.sh b/tests/test_typedef_struct.sh new file mode 100644 index 0000000..7181a86 --- /dev/null +++ b/tests/test_typedef_struct.sh @@ -0,0 +1,85 @@ +cat <<'EOF' > expected +42 +EOF +test_diff <<'EOF' +void* calloc(); +int printf(); + +struct S { + int x; +}; +typedef struct S S; + +int main() { + S* s = calloc(1, sizeof(S)); + s->x = 42; + printf("%d\n", s->x); + return 0; +} +EOF + +cat <<'EOF' > expected +4 +EOF +test_diff <<'EOF' +struct S0; +typedef struct S0 S0; + +struct S1 { + int x; +}; + +struct S2 { + int x; +}; + +struct S3 { + int x; +}; + +struct S4 { + int x; +}; + +struct S0 { + int x; +}; + +int printf(const char*, ...); +int main() { + printf("%zu\n", sizeof(S0)); +} +EOF + +cat <<'EOF' > expected +8 +4 +4 +EOF + +test_diff <<'EOF' +int printf(); + +typedef struct { + int x; + int y; +} S; + +typedef union { + int a; + char b; +} U; + +typedef enum { + RED, + GREEN, + BLUE +} E; + +int main() { + printf("%zu\n", sizeof(S)); + printf("%zu\n", sizeof(U)); + printf("%zu\n", sizeof(E)); +} +EOF + diff --git a/tests/084.sh b/tests/test_undef.sh index 8b0a900..34c3dad 100644 --- a/tests/084.sh +++ b/tests/test_undef.sh @@ -24,3 +24,4 @@ int main() { #endif } EOF + diff --git a/tests/082.sh b/tests/test_unions.sh index d1e87d6..b588792 100644 --- a/tests/082.sh +++ b/tests/test_unions.sh @@ -20,3 +20,4 @@ int main() { printf("%ld\n", u.l); } EOF + diff --git a/tests/063.sh b/tests/test_variadic_functions.sh index 4f899ee..ec85d9a 100644 --- a/tests/063.sh +++ b/tests/test_variadic_functions.sh @@ -29,3 +29,4 @@ int main() { return 0; } EOF + diff --git a/tests/026.sh b/tests/test_void_functions.sh index 093adf0..57116ce 100644 --- a/tests/026.sh +++ b/tests/test_void_functions.sh @@ -1,41 +1,49 @@ cat <<'EOF' > expected +123 EOF test_diff <<'EOF' -#define A 1 +int printf(); + +void foo_bar(int hoge_piyo) { + printf("%d\n", hoge_piyo); +} + int main() { + foo_bar(123); return 0; } EOF cat <<'EOF' > expected -1,2,3 EOF test_diff <<'EOF' -int printf(); +struct S { + int a; +}; + +struct S* f(); -#define A 1 -#define B 2 -#define C 3 +struct S* g() {} int main() { - printf("%d,%d,%d\n", A, B, C); return 0; } EOF cat <<'EOF' > expected -0,0,0,0 +hi EOF test_diff <<'EOF' int printf(); -#define NULL 0 -#define TK_EOF 0 -#define TY_UNKNOWN 0 -#define AST_UNKNOWN 0 +void f() { + printf("hi\n"); + return; +} int main() { - printf("%d,%d,%d,%d\n", NULL, TK_EOF, TY_UNKNOWN, AST_UNKNOWN); + f(); return 0; } EOF + |
