mirror of
https://github.com/ziglang/zig.git
synced 2024-12-14 23:30:15 +00:00
add behavior tests fro macro translations
This commit is contained in:
parent
06c08e5219
commit
5e88a7a427
@ -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
|
||||
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
|
||||
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.
|
||||
|
@ -133,4 +133,5 @@ comptime {
|
||||
_ = @import("behavior/while.zig");
|
||||
_ = @import("behavior/widening.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_wasmtime = is_wasmtime_enabled;
|
||||
these_tests.glibc_multi_install_dir = glibc_dir;
|
||||
these_tests.addIncludeDir("test");
|
||||
|
||||
step.dependOn(&these_tests.step);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user