| author | |
| committer | |
| log | 2291560424b3cfa614cb0320d73e41aa1f5fa221 |
| tree | f3f131f6bb5baf8e7afb44df953c83070877cba7 |
| parent | 556db2ca36afccd623d80b620139a1428c7b65fa |
This introduces the new test step `test-c-import`, and removes the
ability of the behavior tests to `@cImport` paths relative to `test`.
This allows the behavior tests to be run without translate c.19 files changed, 364 insertions(+), 351 deletions(-)
build.zig+17| ... | ... | @@ -471,6 +471,7 @@ pub fn build(b: *std.Build) !void { |
| 471 | 471 | .name = "behavior", |
| 472 | 472 | .desc = "Run the behavior tests", |
| 473 | 473 | .optimize_modes = optimization_modes, |
| 474 | .include_paths = &.{}, | |
| 474 | 475 | .skip_single_threaded = skip_single_threaded, |
| 475 | 476 | .skip_non_native = skip_non_native, |
| 476 | 477 | .skip_cross_glibc = skip_cross_glibc, |
| ... | ... | @@ -478,12 +479,26 @@ pub fn build(b: *std.Build) !void { |
| 478 | 479 | .max_rss = 1 * 1024 * 1024 * 1024, |
| 479 | 480 | })); |
| 480 | 481 | |
| 482 | test_step.dependOn(tests.addModuleTests(b, .{ | |
| 483 | .test_filter = test_filter, | |
| 484 | .root_src = "test/c_import.zig", | |
| 485 | .name = "c-import", | |
| 486 | .desc = "Run the @cImport tests", | |
| 487 | .optimize_modes = optimization_modes, | |
| 488 | .include_paths = &.{"test/c_import"}, | |
| 489 | .skip_single_threaded = true, | |
| 490 | .skip_non_native = skip_non_native, | |
| 491 | .skip_cross_glibc = skip_cross_glibc, | |
| 492 | .skip_libc = skip_libc, | |
| 493 | })); | |
| 494 | ||
| 481 | 495 | test_step.dependOn(tests.addModuleTests(b, .{ |
| 482 | 496 | .test_filter = test_filter, |
| 483 | 497 | .root_src = "lib/compiler_rt.zig", |
| 484 | 498 | .name = "compiler-rt", |
| 485 | 499 | .desc = "Run the compiler_rt tests", |
| 486 | 500 | .optimize_modes = optimization_modes, |
| 501 | .include_paths = &.{}, | |
| 487 | 502 | .skip_single_threaded = true, |
| 488 | 503 | .skip_non_native = skip_non_native, |
| 489 | 504 | .skip_cross_glibc = skip_cross_glibc, |
| ... | ... | @@ -496,6 +511,7 @@ pub fn build(b: *std.Build) !void { |
| 496 | 511 | .name = "universal-libc", |
| 497 | 512 | .desc = "Run the universal libc tests", |
| 498 | 513 | .optimize_modes = optimization_modes, |
| 514 | .include_paths = &.{}, | |
| 499 | 515 | .skip_single_threaded = true, |
| 500 | 516 | .skip_non_native = skip_non_native, |
| 501 | 517 | .skip_cross_glibc = skip_cross_glibc, |
| ... | ... | @@ -527,6 +543,7 @@ pub fn build(b: *std.Build) !void { |
| 527 | 543 | .name = "std", |
| 528 | 544 | .desc = "Run the standard library tests", |
| 529 | 545 | .optimize_modes = optimization_modes, |
| 546 | .include_paths = &.{}, | |
| 530 | 547 | .skip_single_threaded = skip_single_threaded, |
| 531 | 548 | .skip_non_native = skip_non_native, |
| 532 | 549 | .skip_cross_glibc = skip_cross_glibc, |
ci/aarch64-linux-debug.sh+2-2| ... | ... | @@ -99,11 +99,11 @@ unset CXX |
| 99 | 99 | |
| 100 | 100 | ninja install |
| 101 | 101 | |
| 102 | stage3/bin/zig test ../test/behavior.zig -I../test | |
| 102 | stage3/bin/zig test ../test/behavior.zig | |
| 103 | 103 | stage3/bin/zig build -p stage4 \ |
| 104 | 104 | -Dstatic-llvm \ |
| 105 | 105 | -Dtarget=native-native-musl \ |
| 106 | 106 | -Dno-lib \ |
| 107 | 107 | --search-prefix "$PREFIX" \ |
| 108 | 108 | --zig-lib-dir "$(pwd)/../lib" |
| 109 | stage4/bin/zig test ../test/behavior.zig -I../test | |
| 109 | stage4/bin/zig test ../test/behavior.zig |
ci/aarch64-linux-release.sh+2-2| ... | ... | @@ -99,11 +99,11 @@ unset CXX |
| 99 | 99 | |
| 100 | 100 | ninja install |
| 101 | 101 | |
| 102 | stage3/bin/zig test ../test/behavior.zig -I../test | |
| 102 | stage3/bin/zig test ../test/behavior.zig | |
| 103 | 103 | stage3/bin/zig build -p stage4 \ |
| 104 | 104 | -Dstatic-llvm \ |
| 105 | 105 | -Dtarget=native-native-musl \ |
| 106 | 106 | -Dno-lib \ |
| 107 | 107 | --search-prefix "$PREFIX" \ |
| 108 | 108 | --zig-lib-dir "$(pwd)/../lib" |
| 109 | stage4/bin/zig test ../test/behavior.zig -I../test | |
| 109 | stage4/bin/zig test ../test/behavior.zig |
ci/x86_64-linux-debug.sh+3-4| ... | ... | @@ -25,8 +25,7 @@ rm -rf zig-out |
| 25 | 25 | cc -o bootstrap bootstrap.c |
| 26 | 26 | ./bootstrap |
| 27 | 27 | ./zig2 build -Dno-lib |
| 28 | # In order to run these behavior tests we need to move the `@cImport` ones to somewhere else. | |
| 29 | # ./zig-out/bin/zig test test/behavior.zig | |
| 28 | ./zig-out/bin/zig test test/behavior.zig | |
| 30 | 29 | |
| 31 | 30 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 32 | 31 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| ... | ... | @@ -108,11 +107,11 @@ unset CXX |
| 108 | 107 | |
| 109 | 108 | ninja install |
| 110 | 109 | |
| 111 | stage3/bin/zig test ../test/behavior.zig -I../test | |
| 110 | stage3/bin/zig test ../test/behavior.zig | |
| 112 | 111 | stage3/bin/zig build -p stage4 \ |
| 113 | 112 | -Dstatic-llvm \ |
| 114 | 113 | -Dtarget=native-native-musl \ |
| 115 | 114 | -Dno-lib \ |
| 116 | 115 | --search-prefix "$PREFIX" \ |
| 117 | 116 | --zig-lib-dir "$(pwd)/../lib" |
| 118 | stage4/bin/zig test ../test/behavior.zig -I../test | |
| 117 | stage4/bin/zig test ../test/behavior.zig |
ci/x86_64-linux-release.sh+3-4| ... | ... | @@ -25,8 +25,7 @@ rm -rf zig-out |
| 25 | 25 | cc -o bootstrap bootstrap.c |
| 26 | 26 | ./bootstrap |
| 27 | 27 | ./zig2 build -Dno-lib |
| 28 | # In order to run these behavior tests we need to move the `@cImport` ones to somewhere else. | |
| 29 | # ./zig-out/bin/zig test test/behavior.zig | |
| 28 | ./zig-out/bin/zig test test/behavior.zig | |
| 30 | 29 | |
| 31 | 30 | export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" |
| 32 | 31 | export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" |
| ... | ... | @@ -125,11 +124,11 @@ unset CXX |
| 125 | 124 | |
| 126 | 125 | ninja install |
| 127 | 126 | |
| 128 | stage3/bin/zig test ../test/behavior.zig -I../test | |
| 127 | stage3/bin/zig test ../test/behavior.zig | |
| 129 | 128 | stage3/bin/zig build -p stage4 \ |
| 130 | 129 | -Dstatic-llvm \ |
| 131 | 130 | -Dtarget=native-native-musl \ |
| 132 | 131 | -Dno-lib \ |
| 133 | 132 | --search-prefix "$PREFIX" \ |
| 134 | 133 | --zig-lib-dir "$(pwd)/../lib" |
| 135 | stage4/bin/zig test ../test/behavior.zig -I../test | |
| 134 | stage4/bin/zig test ../test/behavior.zig |
ci/x86_64-macos-release.sh+1-2| ... | ... | @@ -31,8 +31,7 @@ rm -rf zig-out |
| 31 | 31 | cc -o bootstrap bootstrap.c |
| 32 | 32 | ./bootstrap |
| 33 | 33 | ./zig2 build -Dno-lib |
| 34 | # In order to run these behavior tests we need to move the `@cImport` ones to somewhere else. | |
| 35 | # ./zig-out/bin/zig test test/behavior.zig | |
| 34 | ./zig-out/bin/zig test test/behavior.zig | |
| 36 | 35 | |
| 37 | 36 | rm -rf build |
| 38 | 37 | mkdir build |
ci/x86_64-windows-debug.ps1-2| ... | ... | @@ -66,8 +66,6 @@ Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." |
| 66 | 66 | & "stage3-debug\bin\zig.exe" test ` |
| 67 | 67 | ..\test\behavior.zig ` |
| 68 | 68 | --zig-lib-dir "$ZIG_LIB_DIR" ` |
| 69 | -I..\test ` | |
| 70 | -I..\lib ` | |
| 71 | 69 | -ofmt=c ` |
| 72 | 70 | -femit-bin="test-x86_64-windows-msvc.c" ` |
| 73 | 71 | --test-no-exec ` |
ci/x86_64-windows-release.ps1-2| ... | ... | @@ -65,8 +65,6 @@ Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." |
| 65 | 65 | & "stage3-release\bin\zig.exe" test ` |
| 66 | 66 | ..\test\behavior.zig ` |
| 67 | 67 | --zig-lib-dir "$ZIG_LIB_DIR" ` |
| 68 | -I..\test ` | |
| 69 | -I..\lib ` | |
| 70 | 68 | -ofmt=c ` |
| 71 | 69 | -femit-bin="test-x86_64-windows-msvc.c" ` |
| 72 | 70 | --test-no-exec ` |
test/behavior.zig-2| ... | ... | @@ -14,7 +14,6 @@ test { |
| 14 | 14 | _ = @import("behavior/bool.zig"); |
| 15 | 15 | _ = @import("behavior/byteswap.zig"); |
| 16 | 16 | _ = @import("behavior/byval_arg_var.zig"); |
| 17 | _ = @import("behavior/c_char_signedness.zig"); | |
| 18 | 17 | _ = @import("behavior/call.zig"); |
| 19 | 18 | _ = @import("behavior/call_tail.zig"); |
| 20 | 19 | _ = @import("behavior/cast.zig"); |
| ... | ... | @@ -92,7 +91,6 @@ test { |
| 92 | 91 | _ = @import("behavior/switch_prong_implicit_cast.zig"); |
| 93 | 92 | _ = @import("behavior/this.zig"); |
| 94 | 93 | _ = @import("behavior/threadlocal.zig"); |
| 95 | _ = @import("behavior/translate_c_macros.zig"); | |
| 96 | 94 | _ = @import("behavior/truncate.zig"); |
| 97 | 95 | _ = @import("behavior/try.zig"); |
| 98 | 96 | _ = @import("behavior/tuple.zig"); |
test/behavior/c_char_signedness.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const expectEqual = std.testing.expectEqual; | |
| 4 | const c = @cImport({ | |
| 5 | @cInclude("limits.h"); | |
| 6 | }); | |
| 7 | ||
| 8 | test "c_char signedness" { | |
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 10 | ||
| 11 | try expectEqual(@as(c_char, c.CHAR_MIN), std.math.minInt(c_char)); | |
| 12 | try expectEqual(@as(c_char, c.CHAR_MAX), std.math.maxInt(c_char)); | |
| 13 | } |
test/behavior/translate_c_macros.h deleted-70| ... | ... | @@ -1,70 +0,0 @@ |
| 1 | // initializer list expression | |
| 2 | typedef struct Color { | |
| 3 | unsigned char r; | |
| 4 | unsigned char g; | |
| 5 | unsigned char b; | |
| 6 | unsigned char a; | |
| 7 | } Color; | |
| 8 | #define CLITERAL(type) (type) | |
| 9 | #define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray | |
| 10 | ||
| 11 | #define MY_SIZEOF(x) ((int)sizeof(x)) | |
| 12 | #define MY_SIZEOF2(x) ((int)sizeof x) | |
| 13 | ||
| 14 | struct Foo { | |
| 15 | int a; | |
| 16 | }; | |
| 17 | ||
| 18 | union U { | |
| 19 | long l; | |
| 20 | double d; | |
| 21 | }; | |
| 22 | ||
| 23 | #define SIZE_OF_FOO sizeof(struct Foo) | |
| 24 | ||
| 25 | #define MAP_FAILED	((void *) -1) | |
| 26 | ||
| 27 | #define IGNORE_ME_1(x) ((void)(x)) | |
| 28 | #define IGNORE_ME_2(x) ((const void)(x)) | |
| 29 | #define IGNORE_ME_3(x) ((volatile void)(x)) | |
| 30 | #define IGNORE_ME_4(x) ((const volatile void)(x)) | |
| 31 | #define IGNORE_ME_5(x) ((volatile const void)(x)) | |
| 32 | ||
| 33 | #define IGNORE_ME_6(x) (void)(x) | |
| 34 | #define IGNORE_ME_7(x) (const void)(x) | |
| 35 | #define IGNORE_ME_8(x) (volatile void)(x) | |
| 36 | #define IGNORE_ME_9(x) (const volatile void)(x) | |
| 37 | #define IGNORE_ME_10(x) (volatile const void)(x) | |
| 38 | ||
| 39 | #define UNION_CAST(X) (union U)(X) | |
| 40 | #define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val)) | |
| 41 | ||
| 42 | #define NESTED_COMMA_OPERATOR (1, (2, 3)) | |
| 43 | #define NESTED_COMMA_OPERATOR_LHS (1, 2), 3 | |
| 44 | ||
| 45 | #include <stdint.h> | |
| 46 | #if !defined(__UINTPTR_MAX__) | |
| 47 | typedef _Bool uintptr_t; | |
| 48 | #endif | |
| 49 | ||
| 50 | #define CAST_TO_BOOL(X) (_Bool)(X) | |
| 51 | #define CAST_TO_UINTPTR(X) (uintptr_t)(X) | |
| 52 | ||
| 53 | #define LARGE_INT 18446744073709550592 | |
| 54 | ||
| 55 | #define EMBEDDED_TAB "hello	" | |
| 56 | ||
| 57 | #define DIVIDE_CONSTANT(version) (version / 1000) | |
| 58 | #define DIVIDE_ARGS(A, B) (A / B) | |
| 59 | ||
| 60 | #define REMAINDER_CONSTANT(version) (version % 10000) | |
| 61 | #define REMAINDER_ARGS(A, B) (A % B) | |
| 62 | ||
| 63 | #define LONG(x) x##L | |
| 64 | #define X LONG(10) | |
| 65 | ||
| 66 | #define BLANK_MACRO | |
| 67 | #define BLANK_CHILD_MACRO BLANK_MACRO BLANK_MACRO BLANK_MACRO | |
| 68 | #define MACRO_VALUE 0 | |
| 69 | typedef long def_type; | |
| 70 | #define BLANK_MACRO_CAST (BLANK_CHILD_MACRO def_type BLANK_CHILD_MACRO)MACRO_VALUE |
test/behavior/translate_c_macros.zig deleted-242| ... | ... | @@ -1,242 +0,0 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const std = @import("std"); | |
| 3 | const expect = std.testing.expect; | |
| 4 | const expectEqual = std.testing.expectEqual; | |
| 5 | const expectEqualStrings = std.testing.expectEqualStrings; | |
| 6 | ||
| 7 | const h = @cImport(@cInclude("behavior/translate_c_macros.h")); | |
| 8 | const latin1 = @cImport(@cInclude("behavior/translate_c_macros_not_utf8.h")); | |
| 9 | ||
| 10 | test "casting to void with a macro" { | |
| 11 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 12 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 13 | ||
| 14 | h.IGNORE_ME_1(42); | |
| 15 | h.IGNORE_ME_2(42); | |
| 16 | h.IGNORE_ME_3(42); | |
| 17 | h.IGNORE_ME_4(42); | |
| 18 | h.IGNORE_ME_5(42); | |
| 19 | h.IGNORE_ME_6(42); | |
| 20 | h.IGNORE_ME_7(42); | |
| 21 | h.IGNORE_ME_8(42); | |
| 22 | h.IGNORE_ME_9(42); | |
| 23 | h.IGNORE_ME_10(42); | |
| 24 | } | |
| 25 | ||
| 26 | test "initializer list expression" { | |
| 27 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 28 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 30 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 31 | ||
| 32 | try expectEqual(h.Color{ | |
| 33 | .r = 200, | |
| 34 | .g = 200, | |
| 35 | .b = 200, | |
| 36 | .a = 255, | |
| 37 | }, h.LIGHTGRAY); | |
| 38 | } | |
| 39 | ||
| 40 | test "sizeof in macros" { | |
| 41 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 42 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 43 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 44 | ||
| 45 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF(u32)); | |
| 46 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF2(u32)); | |
| 47 | } | |
| 48 | ||
| 49 | test "reference to a struct type" { | |
| 50 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 51 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 52 | ||
| 53 | try expect(@sizeOf(h.struct_Foo) == h.SIZE_OF_FOO); | |
| 54 | } | |
| 55 | ||
| 56 | test "cast negative integer to pointer" { | |
| 57 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 58 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 59 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 60 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 61 | ||
| 62 | try expectEqual(@as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))), h.MAP_FAILED); | |
| 63 | } | |
| 64 | ||
| 65 | test "casting to union with a macro" { | |
| 66 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 67 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 68 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 69 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 70 | ||
| 71 | const l: c_long = 42; | |
| 72 | const d: f64 = 2.0; | |
| 73 | ||
| 74 | var casted = h.UNION_CAST(l); | |
| 75 | try expect(l == casted.l); | |
| 76 | ||
| 77 | casted = h.UNION_CAST(d); | |
| 78 | try expect(d == casted.d); | |
| 79 | } | |
| 80 | ||
| 81 | test "casting or calling a value with a paren-surrounded macro" { | |
| 82 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 83 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 84 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 85 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 86 | ||
| 87 | const l: c_long = 42; | |
| 88 | const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l); | |
| 89 | try expect(casted == @as(c_int, @intCast(l))); | |
| 90 | ||
| 91 | const Helper = struct { | |
| 92 | fn foo(n: c_int) !void { | |
| 93 | try expect(n == 42); | |
| 94 | } | |
| 95 | }; | |
| 96 | ||
| 97 | try h.CAST_OR_CALL_WITH_PARENS(Helper.foo, 42); | |
| 98 | } | |
| 99 | ||
| 100 | test "nested comma operator" { | |
| 101 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 102 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 103 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 104 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 105 | ||
| 106 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR); | |
| 107 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS); | |
| 108 | } | |
| 109 | ||
| 110 | test "cast functions" { | |
| 111 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 112 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 113 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 114 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 115 | ||
| 116 | const S = struct { | |
| 117 | fn foo() void {} | |
| 118 | }; | |
| 119 | try expectEqual(true, h.CAST_TO_BOOL(S.foo)); | |
| 120 | try expect(h.CAST_TO_UINTPTR(S.foo) != 0); | |
| 121 | } | |
| 122 | ||
| 123 | test "large integer macro" { | |
| 124 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 125 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 126 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 127 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 128 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 129 | ||
| 130 | try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT); | |
| 131 | } | |
| 132 | ||
| 133 | test "string literal macro with embedded tab character" { | |
| 134 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 135 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 136 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 137 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 138 | ||
| 139 | try expectEqualStrings("hello\t", h.EMBEDDED_TAB); | |
| 140 | } | |
| 141 | ||
| 142 | test "string and char literals that are not UTF-8 encoded. Issue #12784" { | |
| 143 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 144 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 145 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 146 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 147 | ||
| 148 | try expectEqual(@as(u8, '\xA9'), latin1.UNPRINTABLE_CHAR); | |
| 149 | try expectEqualStrings("\xA9\xA9\xA9", latin1.UNPRINTABLE_STRING); | |
| 150 | } | |
| 151 | ||
| 152 | test "Macro that uses division operator. Issue #13162" { | |
| 153 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 154 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 155 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 156 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 157 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 158 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; | |
| 159 | ||
| 160 | try expectEqual(@as(c_int, 42), h.DIVIDE_CONSTANT(@as(c_int, 42_000))); | |
| 161 | try expectEqual(@as(c_uint, 42), h.DIVIDE_CONSTANT(@as(c_uint, 42_000))); | |
| 162 | ||
| 163 | try expectEqual( | |
| 164 | @as(f64, 42.0), | |
| 165 | h.DIVIDE_ARGS( | |
| 166 | @as(f64, 42.0), | |
| 167 | true, | |
| 168 | ), | |
| 169 | ); | |
| 170 | try expectEqual( | |
| 171 | @as(c_int, 21), | |
| 172 | h.DIVIDE_ARGS( | |
| 173 | @as(i8, 42), | |
| 174 | @as(i8, 2), | |
| 175 | ), | |
| 176 | ); | |
| 177 | ||
| 178 | try expectEqual( | |
| 179 | @as(c_int, 21), | |
| 180 | h.DIVIDE_ARGS( | |
| 181 | @as(c_ushort, 42), | |
| 182 | @as(c_ushort, 2), | |
| 183 | ), | |
| 184 | ); | |
| 185 | } | |
| 186 | ||
| 187 | test "Macro that uses remainder operator. Issue #13346" { | |
| 188 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 189 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 190 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 191 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 192 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 193 | ||
| 194 | try expectEqual(@as(c_int, 2_010), h.REMAINDER_CONSTANT(@as(c_int, 42_010))); | |
| 195 | try expectEqual(@as(c_uint, 2_030), h.REMAINDER_CONSTANT(@as(c_uint, 42_030))); | |
| 196 | ||
| 197 | try expectEqual( | |
| 198 | @as(c_int, 7), | |
| 199 | h.REMAINDER_ARGS( | |
| 200 | @as(i8, 17), | |
| 201 | @as(i8, 10), | |
| 202 | ), | |
| 203 | ); | |
| 204 | ||
| 205 | try expectEqual( | |
| 206 | @as(c_int, 5), | |
| 207 | h.REMAINDER_ARGS( | |
| 208 | @as(c_ushort, 25), | |
| 209 | @as(c_ushort, 20), | |
| 210 | ), | |
| 211 | ); | |
| 212 | ||
| 213 | try expectEqual( | |
| 214 | @as(c_int, 1), | |
| 215 | h.REMAINDER_ARGS( | |
| 216 | @as(c_int, 5), | |
| 217 | @as(c_int, -2), | |
| 218 | ), | |
| 219 | ); | |
| 220 | } | |
| 221 | ||
| 222 | test "@typeInfo on @cImport result" { | |
| 223 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 224 | ||
| 225 | try expect(@typeInfo(h).Struct.decls.len > 1); | |
| 226 | } | |
| 227 | ||
| 228 | test "Macro that uses Long type concatenation casting" { | |
| 229 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 230 | ||
| 231 | try expect((@TypeOf(h.X)) == c_long); | |
| 232 | try expectEqual(h.X, @as(c_long, 10)); | |
| 233 | } | |
| 234 | ||
| 235 | test "Blank macros" { | |
| 236 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 237 | ||
| 238 | try expectEqual(h.BLANK_MACRO, ""); | |
| 239 | try expectEqual(h.BLANK_CHILD_MACRO, ""); | |
| 240 | try expect(@TypeOf(h.BLANK_MACRO_CAST) == h.def_type); | |
| 241 | try expectEqual(h.BLANK_MACRO_CAST, @as(c_long, 0)); | |
| 242 | } |
test/behavior/translate_c_macros_not_utf8.h deleted-5| ... | ... | @@ -1,5 +0,0 @@ |
| 1 | // Note: This file is encoded with ISO/IEC 8859-1 (latin1), not UTF-8. | |
| 2 | // Do not change the encoding | |
| 3 | ||
| 4 | #define UNPRINTABLE_STRING "���" | |
| 5 | #define UNPRINTABLE_CHAR '�' |
test/c_import.zig created+4| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | test { | |
| 2 | _ = @import("c_import/c_char_signedness.zig"); | |
| 3 | _ = @import("c_import/macros.zig"); | |
| 4 | } |
test/c_import/c_char_signedness.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | const expectEqual = std.testing.expectEqual; | |
| 4 | const c = @cImport({ | |
| 5 | @cInclude("limits.h"); | |
| 6 | }); | |
| 7 | ||
| 8 | test "c_char signedness" { | |
| 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 10 | ||
| 11 | try expectEqual(@as(c_char, c.CHAR_MIN), std.math.minInt(c_char)); | |
| 12 | try expectEqual(@as(c_char, c.CHAR_MAX), std.math.maxInt(c_char)); | |
| 13 | } |
test/c_import/macros.h created+70| ... | ... | @@ -0,0 +1,70 @@ |
| 1 | // initializer list expression | |
| 2 | typedef struct Color { | |
| 3 | unsigned char r; | |
| 4 | unsigned char g; | |
| 5 | unsigned char b; | |
| 6 | unsigned char a; | |
| 7 | } Color; | |
| 8 | #define CLITERAL(type) (type) | |
| 9 | #define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray | |
| 10 | ||
| 11 | #define MY_SIZEOF(x) ((int)sizeof(x)) | |
| 12 | #define MY_SIZEOF2(x) ((int)sizeof x) | |
| 13 | ||
| 14 | struct Foo { | |
| 15 | int a; | |
| 16 | }; | |
| 17 | ||
| 18 | union U { | |
| 19 | long l; | |
| 20 | double d; | |
| 21 | }; | |
| 22 | ||
| 23 | #define SIZE_OF_FOO sizeof(struct Foo) | |
| 24 | ||
| 25 | #define MAP_FAILED	((void *) -1) | |
| 26 | ||
| 27 | #define IGNORE_ME_1(x) ((void)(x)) | |
| 28 | #define IGNORE_ME_2(x) ((const void)(x)) | |
| 29 | #define IGNORE_ME_3(x) ((volatile void)(x)) | |
| 30 | #define IGNORE_ME_4(x) ((const volatile void)(x)) | |
| 31 | #define IGNORE_ME_5(x) ((volatile const void)(x)) | |
| 32 | ||
| 33 | #define IGNORE_ME_6(x) (void)(x) | |
| 34 | #define IGNORE_ME_7(x) (const void)(x) | |
| 35 | #define IGNORE_ME_8(x) (volatile void)(x) | |
| 36 | #define IGNORE_ME_9(x) (const volatile void)(x) | |
| 37 | #define IGNORE_ME_10(x) (volatile const void)(x) | |
| 38 | ||
| 39 | #define UNION_CAST(X) (union U)(X) | |
| 40 | #define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val)) | |
| 41 | ||
| 42 | #define NESTED_COMMA_OPERATOR (1, (2, 3)) | |
| 43 | #define NESTED_COMMA_OPERATOR_LHS (1, 2), 3 | |
| 44 | ||
| 45 | #include <stdint.h> | |
| 46 | #if !defined(__UINTPTR_MAX__) | |
| 47 | typedef _Bool uintptr_t; | |
| 48 | #endif | |
| 49 | ||
| 50 | #define CAST_TO_BOOL(X) (_Bool)(X) | |
| 51 | #define CAST_TO_UINTPTR(X) (uintptr_t)(X) | |
| 52 | ||
| 53 | #define LARGE_INT 18446744073709550592 | |
| 54 | ||
| 55 | #define EMBEDDED_TAB "hello	" | |
| 56 | ||
| 57 | #define DIVIDE_CONSTANT(version) (version / 1000) | |
| 58 | #define DIVIDE_ARGS(A, B) (A / B) | |
| 59 | ||
| 60 | #define REMAINDER_CONSTANT(version) (version % 10000) | |
| 61 | #define REMAINDER_ARGS(A, B) (A % B) | |
| 62 | ||
| 63 | #define LONG(x) x##L | |
| 64 | #define X LONG(10) | |
| 65 | ||
| 66 | #define BLANK_MACRO | |
| 67 | #define BLANK_CHILD_MACRO BLANK_MACRO BLANK_MACRO BLANK_MACRO | |
| 68 | #define MACRO_VALUE 0 | |
| 69 | typedef long def_type; | |
| 70 | #define BLANK_MACRO_CAST (BLANK_CHILD_MACRO def_type BLANK_CHILD_MACRO)MACRO_VALUE |
test/c_import/macros.zig created+242| ... | ... | @@ -0,0 +1,242 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const std = @import("std"); | |
| 3 | const expect = std.testing.expect; | |
| 4 | const expectEqual = std.testing.expectEqual; | |
| 5 | const expectEqualStrings = std.testing.expectEqualStrings; | |
| 6 | ||
| 7 | const h = @cImport(@cInclude("macros.h")); | |
| 8 | const latin1 = @cImport(@cInclude("macros_not_utf8.h")); | |
| 9 | ||
| 10 | test "casting to void with a macro" { | |
| 11 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 12 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 13 | ||
| 14 | h.IGNORE_ME_1(42); | |
| 15 | h.IGNORE_ME_2(42); | |
| 16 | h.IGNORE_ME_3(42); | |
| 17 | h.IGNORE_ME_4(42); | |
| 18 | h.IGNORE_ME_5(42); | |
| 19 | h.IGNORE_ME_6(42); | |
| 20 | h.IGNORE_ME_7(42); | |
| 21 | h.IGNORE_ME_8(42); | |
| 22 | h.IGNORE_ME_9(42); | |
| 23 | h.IGNORE_ME_10(42); | |
| 24 | } | |
| 25 | ||
| 26 | test "initializer list expression" { | |
| 27 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 28 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 29 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 30 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 31 | ||
| 32 | try expectEqual(h.Color{ | |
| 33 | .r = 200, | |
| 34 | .g = 200, | |
| 35 | .b = 200, | |
| 36 | .a = 255, | |
| 37 | }, h.LIGHTGRAY); | |
| 38 | } | |
| 39 | ||
| 40 | test "sizeof in macros" { | |
| 41 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 42 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 43 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 44 | ||
| 45 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF(u32)); | |
| 46 | try expect(@as(c_int, @sizeOf(u32)) == h.MY_SIZEOF2(u32)); | |
| 47 | } | |
| 48 | ||
| 49 | test "reference to a struct type" { | |
| 50 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 51 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 52 | ||
| 53 | try expect(@sizeOf(h.struct_Foo) == h.SIZE_OF_FOO); | |
| 54 | } | |
| 55 | ||
| 56 | test "cast negative integer to pointer" { | |
| 57 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 58 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 59 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 60 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 61 | ||
| 62 | try expectEqual(@as(?*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1))))), h.MAP_FAILED); | |
| 63 | } | |
| 64 | ||
| 65 | test "casting to union with a macro" { | |
| 66 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 67 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 68 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 69 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 70 | ||
| 71 | const l: c_long = 42; | |
| 72 | const d: f64 = 2.0; | |
| 73 | ||
| 74 | var casted = h.UNION_CAST(l); | |
| 75 | try expect(l == casted.l); | |
| 76 | ||
| 77 | casted = h.UNION_CAST(d); | |
| 78 | try expect(d == casted.d); | |
| 79 | } | |
| 80 | ||
| 81 | test "casting or calling a value with a paren-surrounded macro" { | |
| 82 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 83 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 84 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 85 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 86 | ||
| 87 | const l: c_long = 42; | |
| 88 | const casted = h.CAST_OR_CALL_WITH_PARENS(c_int, l); | |
| 89 | try expect(casted == @as(c_int, @intCast(l))); | |
| 90 | ||
| 91 | const Helper = struct { | |
| 92 | fn foo(n: c_int) !void { | |
| 93 | try expect(n == 42); | |
| 94 | } | |
| 95 | }; | |
| 96 | ||
| 97 | try h.CAST_OR_CALL_WITH_PARENS(Helper.foo, 42); | |
| 98 | } | |
| 99 | ||
| 100 | test "nested comma operator" { | |
| 101 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 102 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 103 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 104 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 105 | ||
| 106 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR); | |
| 107 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS); | |
| 108 | } | |
| 109 | ||
| 110 | test "cast functions" { | |
| 111 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 112 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 113 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 114 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 115 | ||
| 116 | const S = struct { | |
| 117 | fn foo() void {} | |
| 118 | }; | |
| 119 | try expectEqual(true, h.CAST_TO_BOOL(S.foo)); | |
| 120 | try expect(h.CAST_TO_UINTPTR(S.foo) != 0); | |
| 121 | } | |
| 122 | ||
| 123 | test "large integer macro" { | |
| 124 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 125 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 126 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 127 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 128 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 129 | ||
| 130 | try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT); | |
| 131 | } | |
| 132 | ||
| 133 | test "string literal macro with embedded tab character" { | |
| 134 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 135 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 136 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 137 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 138 | ||
| 139 | try expectEqualStrings("hello\t", h.EMBEDDED_TAB); | |
| 140 | } | |
| 141 | ||
| 142 | test "string and char literals that are not UTF-8 encoded. Issue #12784" { | |
| 143 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 144 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 145 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 146 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 147 | ||
| 148 | try expectEqual(@as(u8, '\xA9'), latin1.UNPRINTABLE_CHAR); | |
| 149 | try expectEqualStrings("\xA9\xA9\xA9", latin1.UNPRINTABLE_STRING); | |
| 150 | } | |
| 151 | ||
| 152 | test "Macro that uses division operator. Issue #13162" { | |
| 153 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 154 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 155 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 156 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 157 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 158 | if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; | |
| 159 | ||
| 160 | try expectEqual(@as(c_int, 42), h.DIVIDE_CONSTANT(@as(c_int, 42_000))); | |
| 161 | try expectEqual(@as(c_uint, 42), h.DIVIDE_CONSTANT(@as(c_uint, 42_000))); | |
| 162 | ||
| 163 | try expectEqual( | |
| 164 | @as(f64, 42.0), | |
| 165 | h.DIVIDE_ARGS( | |
| 166 | @as(f64, 42.0), | |
| 167 | true, | |
| 168 | ), | |
| 169 | ); | |
| 170 | try expectEqual( | |
| 171 | @as(c_int, 21), | |
| 172 | h.DIVIDE_ARGS( | |
| 173 | @as(i8, 42), | |
| 174 | @as(i8, 2), | |
| 175 | ), | |
| 176 | ); | |
| 177 | ||
| 178 | try expectEqual( | |
| 179 | @as(c_int, 21), | |
| 180 | h.DIVIDE_ARGS( | |
| 181 | @as(c_ushort, 42), | |
| 182 | @as(c_ushort, 2), | |
| 183 | ), | |
| 184 | ); | |
| 185 | } | |
| 186 | ||
| 187 | test "Macro that uses remainder operator. Issue #13346" { | |
| 188 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | |
| 189 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 190 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 191 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 192 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 193 | ||
| 194 | try expectEqual(@as(c_int, 2_010), h.REMAINDER_CONSTANT(@as(c_int, 42_010))); | |
| 195 | try expectEqual(@as(c_uint, 2_030), h.REMAINDER_CONSTANT(@as(c_uint, 42_030))); | |
| 196 | ||
| 197 | try expectEqual( | |
| 198 | @as(c_int, 7), | |
| 199 | h.REMAINDER_ARGS( | |
| 200 | @as(i8, 17), | |
| 201 | @as(i8, 10), | |
| 202 | ), | |
| 203 | ); | |
| 204 | ||
| 205 | try expectEqual( | |
| 206 | @as(c_int, 5), | |
| 207 | h.REMAINDER_ARGS( | |
| 208 | @as(c_ushort, 25), | |
| 209 | @as(c_ushort, 20), | |
| 210 | ), | |
| 211 | ); | |
| 212 | ||
| 213 | try expectEqual( | |
| 214 | @as(c_int, 1), | |
| 215 | h.REMAINDER_ARGS( | |
| 216 | @as(c_int, 5), | |
| 217 | @as(c_int, -2), | |
| 218 | ), | |
| 219 | ); | |
| 220 | } | |
| 221 | ||
| 222 | test "@typeInfo on @cImport result" { | |
| 223 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 224 | ||
| 225 | try expect(@typeInfo(h).Struct.decls.len > 1); | |
| 226 | } | |
| 227 | ||
| 228 | test "Macro that uses Long type concatenation casting" { | |
| 229 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 230 | ||
| 231 | try expect((@TypeOf(h.X)) == c_long); | |
| 232 | try expectEqual(h.X, @as(c_long, 10)); | |
| 233 | } | |
| 234 | ||
| 235 | test "Blank macros" { | |
| 236 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 237 | ||
| 238 | try expectEqual(h.BLANK_MACRO, ""); | |
| 239 | try expectEqual(h.BLANK_CHILD_MACRO, ""); | |
| 240 | try expect(@TypeOf(h.BLANK_MACRO_CAST) == h.def_type); | |
| 241 | try expectEqual(h.BLANK_MACRO_CAST, @as(c_long, 0)); | |
| 242 | } |
test/c_import/macros_not_utf8.h created+5| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | // Note: This file is encoded with ISO/IEC 8859-1 (latin1), not UTF-8. | |
| 2 | // Do not change the encoding | |
| 3 | ||
| 4 | #define UNPRINTABLE_STRING "���" | |
| 5 | #define UNPRINTABLE_CHAR '�' |
test/tests.zig+2-1| ... | ... | @@ -1037,6 +1037,7 @@ const ModuleTestOptions = struct { |
| 1037 | 1037 | name: []const u8, |
| 1038 | 1038 | desc: []const u8, |
| 1039 | 1039 | optimize_modes: []const OptimizeMode, |
| 1040 | include_paths: []const []const u8, | |
| 1040 | 1041 | skip_single_threaded: bool, |
| 1041 | 1042 | skip_non_native: bool, |
| 1042 | 1043 | skip_cross_glibc: bool, |
| ... | ... | @@ -1140,7 +1141,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1140 | 1141 | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; |
| 1141 | 1142 | const use_pic = if (test_target.pic == true) "-pic" else ""; |
| 1142 | 1143 | |
| 1143 | these_tests.addIncludePath(.{ .path = "test" }); | |
| 1144 | for (options.include_paths) |include_path| these_tests.addIncludePath(.{ .path = include_path }); | |
| 1144 | 1145 | |
| 1145 | 1146 | if (target.os.tag == .wasi) { |
| 1146 | 1147 | // WASI's default stack size can be too small for some big tests. |