diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-10-14 22:02:32 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-10-17 11:55:17 +0300 |
| commit | e765495b114af3417aea4cffcd7c37f400aab3fe (patch) | |
| tree | 89e1f9a8e856e565d192d08ec8db165fd5d2b6f4 /test/cases | |
| parent | 58b07ea14fcf5212cfcc14e5ad3366287894618e (diff) | |
| download | zig-e765495b114af3417aea4cffcd7c37f400aab3fe.tar.gz zig-e765495b114af3417aea4cffcd7c37f400aab3fe.zip | |
tests: translate-c and run-translated-c to the test harness
Diffstat (limited to 'test/cases')
13 files changed, 80 insertions, 10 deletions
diff --git a/test/cases/README.md b/test/cases/README.md index 4c9f401ab6..97c82dae96 100644 --- a/test/cases/README.md +++ b/test/cases/README.md @@ -9,7 +9,7 @@ If you want it to be run with `zig test` and match expected error messages: ```zig // error -// is_test=1 +// is_test=true // // :4:13: error: 'try' outside function scope ``` @@ -22,6 +22,33 @@ This will do `zig run` on the code and expect exit code 0. // run ``` +## Translate-c + +If you want to test translating C code to Zig use `translate-c`: + +```c +// translate-c +// c_frontend=aro,clang +// target=x86_64-linux +// +// pub const foo = 1; +// pub const immediately_after_foo = 2; +// +// pub const somewhere_else_in_the_file = 3: +``` + +## Run Translated C + +If you want to test translating C code to Zig and then executing it use `run-translated-c`: + +```c +// run-translated-c +// c_frontend=aro,clang +// target=x86_64-linux +// +// Hello world! +``` + ## Incremental Compilation Make multiple files that have ".", and then an integer, before the ".zig" diff --git a/test/cases/compile_errors/access_invalid_typeInfo_decl.zig b/test/cases/compile_errors/access_invalid_typeInfo_decl.zig index 4233b42e7d..13fda8fa7b 100644 --- a/test/cases/compile_errors/access_invalid_typeInfo_decl.zig +++ b/test/cases/compile_errors/access_invalid_typeInfo_decl.zig @@ -6,6 +6,6 @@ test "Crash" { // error // backend=stage2 // target=native -// is_test=1 +// is_test=true // // :1:11: error: use of undeclared identifier 'B' diff --git a/test/cases/compile_errors/invalid_duplicate_test_decl_name.zig b/test/cases/compile_errors/invalid_duplicate_test_decl_name.zig index c3ecdbf4fc..48008f970d 100644 --- a/test/cases/compile_errors/invalid_duplicate_test_decl_name.zig +++ b/test/cases/compile_errors/invalid_duplicate_test_decl_name.zig @@ -4,7 +4,7 @@ test "thingy" {} // error // backend=stage2 // target=native -// is_test=1 +// is_test=true // // :1:6: error: duplicate test name: test.thingy // :2:6: note: other test here diff --git a/test/cases/compile_errors/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig b/test/cases/compile_errors/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig index 201c8c870b..35273065eb 100644 --- a/test/cases/compile_errors/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig +++ b/test/cases/compile_errors/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig @@ -9,6 +9,6 @@ test "1" { // error // backend=stage2 // target=native -// is_test=1 +// is_test=true // // :2:12: error: use of undeclared identifier 'Q' diff --git a/test/cases/compile_errors/return_invalid_type_from_test.zig b/test/cases/compile_errors/return_invalid_type_from_test.zig index acc932cb0a..dda31b6f84 100644 --- a/test/cases/compile_errors/return_invalid_type_from_test.zig +++ b/test/cases/compile_errors/return_invalid_type_from_test.zig @@ -5,6 +5,6 @@ test "example" { // error // backend=stage2 // target=native -// is_test=1 +// is_test=true // // :2:12: error: expected type 'anyerror!void', found 'comptime_int' diff --git a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig index 2b45fb6076..06e17a1e87 100644 --- a/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig +++ b/test/cases/compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig @@ -6,7 +6,7 @@ test "enum" { // error // backend=stage2 // target=native -// is_test=1 +// is_test=true // // :3:9: error: no field with value '@enumFromInt(5)' in enum 'test.enum.E' // :2:15: note: declared here diff --git a/test/cases/f32_passed_to_variadic_fn.zig b/test/cases/f32_passed_to_variadic_fn.zig index 4ae1d2cf08..16f95fdfe8 100644 --- a/test/cases/f32_passed_to_variadic_fn.zig +++ b/test/cases/f32_passed_to_variadic_fn.zig @@ -9,7 +9,7 @@ pub fn main() void { // run // backend=llvm // target=x86_64-linux-gnu -// link_libc=1 +// link_libc=true // // f64: 2.000000 // f32: 10.000000 diff --git a/test/cases/fn_typeinfo_passed_to_comptime_fn.zig b/test/cases/fn_typeinfo_passed_to_comptime_fn.zig index fb64788126..4946381968 100644 --- a/test/cases/fn_typeinfo_passed_to_comptime_fn.zig +++ b/test/cases/fn_typeinfo_passed_to_comptime_fn.zig @@ -13,6 +13,6 @@ fn foo(comptime info: std.builtin.Type) !void { } // run -// is_test=1 +// is_test=true // backend=llvm // diff --git a/test/cases/llvm/hello_world.zig b/test/cases/llvm/hello_world.zig index 0f75f624ec..8bc1c60614 100644 --- a/test/cases/llvm/hello_world.zig +++ b/test/cases/llvm/hello_world.zig @@ -7,7 +7,7 @@ pub fn main() void { // run // backend=llvm // target=x86_64-linux,x86_64-macos -// link_libc=1 +// link_libc=true // // hello world! // diff --git a/test/cases/run_translated_c/dereference address of.c b/test/cases/run_translated_c/dereference address of.c new file mode 100644 index 0000000000..15b9777c7a --- /dev/null +++ b/test/cases/run_translated_c/dereference address of.c @@ -0,0 +1,11 @@ +#include <stdlib.h> +int main(void) { + int i = 0; + *&i = 42; + if (i != 42) abort(); + return 0; +} + +// run-translated-c +// c_frontend=clang +// link_libc=true diff --git a/test/cases/translate_c/enums msvc.c b/test/cases/translate_c/enums msvc.c new file mode 100644 index 0000000000..ab7242512f --- /dev/null +++ b/test/cases/translate_c/enums msvc.c @@ -0,0 +1,16 @@ +enum Foo { + FooA = 2, + FooB = 5, + Foo1, +}; + +// translate-c +// target=x86_64-windows-msvc +// c_frontend=clang +// +// pub const FooA: c_int = 2; +// pub const FooB: c_int = 5; +// pub const Foo1: c_int = 6; +// pub const enum_Foo = c_int; +// +// pub const Foo = enum_Foo; diff --git a/test/cases/translate_c/enums.c b/test/cases/translate_c/enums.c new file mode 100644 index 0000000000..528ae60190 --- /dev/null +++ b/test/cases/translate_c/enums.c @@ -0,0 +1,16 @@ +enum Foo { + FooA = 2, + FooB = 5, + Foo1, +}; + +// translate-c +// target=x86_64-linux +// c_frontend=clang,aro +// +// pub const FooA: c_int = 2; +// pub const FooB: c_int = 5; +// pub const Foo1: c_int = 6; +// pub const enum_Foo = c_uint; +// +// pub const Foo = enum_Foo; diff --git a/test/cases/try_in_comptime_in_struct_in_test.zig b/test/cases/try_in_comptime_in_struct_in_test.zig index e88aa13a7b..c6abb13ee6 100644 --- a/test/cases/try_in_comptime_in_struct_in_test.zig +++ b/test/cases/try_in_comptime_in_struct_in_test.zig @@ -8,6 +8,6 @@ test "@unionInit on union w/ tag but no fields" { } // error -// is_test=1 +// is_test=true // // :4:13: error: 'try' outside function scope |
