add behavior tests fro macro translations

This commit is contained in:
Vexu 2020-07-16 17:10:52 +03:00
parent 06c08e5219
commit 5e88a7a427
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
5 changed files with 28 additions and 0 deletions

View File

@ -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.

View File

@ -133,4 +133,5 @@ comptime {
_ = @import("behavior/while.zig");
_ = @import("behavior/widening.zig");
_ = @import("behavior/src.zig");
_ = @import("behavior/translate_c_macros.zig");
}

View 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

View 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);
}

View File

@ -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);
}