mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
add behavior tests fro macro translations
This commit is contained in:
parent
06c08e5219
commit
5e88a7a427
5 changed files with 28 additions and 0 deletions
|
|
@ -152,6 +152,11 @@ The relevant tests for this feature are:
|
||||||
same, and that the program exits cleanly. This kind of test coverage is preferred, when
|
same, and that the program exits cleanly. This kind of test coverage is preferred, when
|
||||||
possible, because it makes sure that the resulting Zig code is actually viable.
|
possible, because it makes sure that the resulting Zig code is actually viable.
|
||||||
|
|
||||||
|
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
|
||||||
|
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
|
||||||
|
have the correct values. Macros have to be tested separately since they are expanded by
|
||||||
|
Clang in `run_translated_c` tests.
|
||||||
|
|
||||||
* `test/translate_c.zig` - each test case is C code, with a list of expected strings which
|
* `test/translate_c.zig` - each test case is C code, with a list of expected strings which
|
||||||
must be found in the resulting Zig code. This kind of test is more precise in what it
|
must be found in the resulting Zig code. This kind of test is more precise in what it
|
||||||
measures, but does not provide test coverage of whether the resulting Zig code is valid.
|
measures, but does not provide test coverage of whether the resulting Zig code is valid.
|
||||||
|
|
|
||||||
|
|
@ -133,4 +133,5 @@ comptime {
|
||||||
_ = @import("behavior/while.zig");
|
_ = @import("behavior/while.zig");
|
||||||
_ = @import("behavior/widening.zig");
|
_ = @import("behavior/widening.zig");
|
||||||
_ = @import("behavior/src.zig");
|
_ = @import("behavior/src.zig");
|
||||||
|
_ = @import("behavior/translate_c_macros.zig");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
test/stage1/behavior/translate_c_macros.h
Normal file
9
test/stage1/behavior/translate_c_macros.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
// initializer list expression
|
||||||
|
typedef struct Color {
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
unsigned char a;
|
||||||
|
} Color;
|
||||||
|
#define CLITERAL(type) (type)
|
||||||
|
#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray
|
||||||
12
test/stage1/behavior/translate_c_macros.zig
Normal file
12
test/stage1/behavior/translate_c_macros.zig
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const expect = @import("std").testing.expect;
|
||||||
|
|
||||||
|
const h = @cImport(@cInclude("stage1/behavior/translate_c_macros.h"));
|
||||||
|
|
||||||
|
test "initializer list expression" {
|
||||||
|
@import("std").testing.expectEqual(h.Color{
|
||||||
|
.r = 200,
|
||||||
|
.g = 200,
|
||||||
|
.b = 200,
|
||||||
|
.a = 255,
|
||||||
|
}, h.LIGHTGRAY);
|
||||||
|
}
|
||||||
|
|
@ -537,6 +537,7 @@ pub fn addPkgTests(
|
||||||
these_tests.enable_qemu = is_qemu_enabled;
|
these_tests.enable_qemu = is_qemu_enabled;
|
||||||
these_tests.enable_wasmtime = is_wasmtime_enabled;
|
these_tests.enable_wasmtime = is_wasmtime_enabled;
|
||||||
these_tests.glibc_multi_install_dir = glibc_dir;
|
these_tests.glibc_multi_install_dir = glibc_dir;
|
||||||
|
these_tests.addIncludeDir("test");
|
||||||
|
|
||||||
step.dependOn(&these_tests.step);
|
step.dependOn(&these_tests.step);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue