Skip to content

Commit 3a04d75

Browse files
authored
Merge pull request ziglang#17524 from Vexu/aro-translate-c
Add ability to test Aro based `translate-c`
2 parents 393ee33 + db3ab26 commit 3a04d75

13 files changed

+80
-10
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you want it to be run with `zig test` and match expected error messages:
99

1010
```zig
1111
// error
12-
// is_test=1
12+
// is_test=true
1313
//
1414
// :4:13: error: 'try' outside function scope
1515
```
@@ -22,6 +22,33 @@ This will do `zig run` on the code and expect exit code 0.
2222
// run
2323
```
2424

25+
## Translate-c
26+
27+
If you want to test translating C code to Zig use `translate-c`:
28+
29+
```c
30+
// translate-c
31+
// c_frontend=aro,clang
32+
// target=x86_64-linux
33+
//
34+
// pub const foo = 1;
35+
// pub const immediately_after_foo = 2;
36+
//
37+
// pub const somewhere_else_in_the_file = 3:
38+
```
39+
40+
## Run Translated C
41+
42+
If you want to test translating C code to Zig and then executing it use `run-translated-c`:
43+
44+
```c
45+
// run-translated-c
46+
// c_frontend=aro,clang
47+
// target=x86_64-linux
48+
//
49+
// Hello world!
50+
```
51+
2552
## Incremental Compilation
2653

2754
Make multiple files that have ".", and then an integer, before the ".zig"

compile_errors/access_invalid_typeInfo_decl.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ test "Crash" {
66
// error
77
// backend=stage2
88
// target=native
9-
// is_test=1
9+
// is_test=true
1010
//
1111
// :1:11: error: use of undeclared identifier 'B'

compile_errors/invalid_duplicate_test_decl_name.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test "thingy" {}
44
// error
55
// backend=stage2
66
// target=native
7-
// is_test=1
7+
// is_test=true
88
//
99
// :1:6: error: duplicate test name: test.thingy
1010
// :2:6: note: other test here

compile_errors/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ test "1" {
99
// error
1010
// backend=stage2
1111
// target=native
12-
// is_test=1
12+
// is_test=true
1313
//
1414
// :2:12: error: use of undeclared identifier 'Q'

compile_errors/return_invalid_type_from_test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ test "example" {
55
// error
66
// backend=stage2
77
// target=native
8-
// is_test=1
8+
// is_test=true
99
//
1010
// :2:12: error: expected type 'anyerror!void', found 'comptime_int'

compile_errors/tagName_on_invalid_value_of_non-exhaustive_enum.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test "enum" {
66
// error
77
// backend=stage2
88
// target=native
9-
// is_test=1
9+
// is_test=true
1010
//
1111
// :3:9: error: no field with value '@enumFromInt(5)' in enum 'test.enum.E'
1212
// :2:15: note: declared here

f32_passed_to_variadic_fn.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn main() void {
99
// run
1010
// backend=llvm
1111
// target=x86_64-linux-gnu
12-
// link_libc=1
12+
// link_libc=true
1313
//
1414
// f64: 2.000000
1515
// f32: 10.000000

fn_typeinfo_passed_to_comptime_fn.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ fn foo(comptime info: std.builtin.Type) !void {
1313
}
1414

1515
// run
16-
// is_test=1
16+
// is_test=true
1717
// backend=llvm
1818
//

llvm/hello_world.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn main() void {
77
// run
88
// backend=llvm
99
// target=x86_64-linux,x86_64-macos
10-
// link_libc=1
10+
// link_libc=true
1111
//
1212
// hello world!
1313
//
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdlib.h>
2+
int main(void) {
3+
int i = 0;
4+
*&i = 42;
5+
if (i != 42) abort();
6+
return 0;
7+
}
8+
9+
// run-translated-c
10+
// c_frontend=clang
11+
// link_libc=true

translate_c/enums msvc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
enum Foo {
2+
FooA = 2,
3+
FooB = 5,
4+
Foo1,
5+
};
6+
7+
// translate-c
8+
// target=x86_64-windows-msvc
9+
// c_frontend=clang
10+
//
11+
// pub const FooA: c_int = 2;
12+
// pub const FooB: c_int = 5;
13+
// pub const Foo1: c_int = 6;
14+
// pub const enum_Foo = c_int;
15+
//
16+
// pub const Foo = enum_Foo;

translate_c/enums.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
enum Foo {
2+
FooA = 2,
3+
FooB = 5,
4+
Foo1,
5+
};
6+
7+
// translate-c
8+
// target=x86_64-linux
9+
// c_frontend=clang,aro
10+
//
11+
// pub const FooA: c_int = 2;
12+
// pub const FooB: c_int = 5;
13+
// pub const Foo1: c_int = 6;
14+
// pub const enum_Foo = c_uint;
15+
//
16+
// pub const Foo = enum_Foo;

try_in_comptime_in_struct_in_test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ test "@unionInit on union w/ tag but no fields" {
88
}
99

1010
// error
11-
// is_test=1
11+
// is_test=true
1212
//
1313
// :4:13: error: 'try' outside function scope

0 commit comments

Comments
 (0)