authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-16 17:10:52+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-16 17:10:52+03:00
log5e88a7a42724d7ccf9db58e1524beedebb1efd93
tree6866e272f3f9e6511e9f1b8bb7f507138db4adb8
parent06c08e5219f03328f483cded319c7ba75efb5188
signaturelock-open Commit is signed but in an unrecognized format.

add behavior tests fro macro translations


5 files changed, 28 insertions(+), 0 deletions(-)

CONTRIBUTING.md+5
......@@ -152,6 +152,11 @@ The relevant tests for this feature are:
152152 same, and that the program exits cleanly. This kind of test coverage is preferred, when
153153 possible, because it makes sure that the resulting Zig code is actually viable.
154154
155 * `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
156 which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
157 have the correct values. Macros have to be tested separately since they are expanded by
158 Clang in `run_translated_c` tests.
159
155160 * `test/translate_c.zig` - each test case is C code, with a list of expected strings which
156161 must be found in the resulting Zig code. This kind of test is more precise in what it
157162 measures, but does not provide test coverage of whether the resulting Zig code is valid.
test/stage1/behavior.zig+1
......@@ -133,4 +133,5 @@ comptime {
133133 _ = @import("behavior/while.zig");
134134 _ = @import("behavior/widening.zig");
135135 _ = @import("behavior/src.zig");
136 _ = @import("behavior/translate_c_macros.zig");
136137}
test/stage1/behavior/translate_c_macros.h created+9
......@@ -0,0 +1,9 @@
1// initializer list expression
2typedef 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
\ No newline at end of file
test/stage1/behavior/translate_c_macros.zig created+12
......@@ -0,0 +1,12 @@
1const expect = @import("std").testing.expect;
2
3const h = @cImport(@cInclude("stage1/behavior/translate_c_macros.h"));
4
5test "initializer list expression" {
6 @import("std").testing.expectEqual(h.Color{
7 .r = 200,
8 .g = 200,
9 .b = 200,
10 .a = 255,
11 }, h.LIGHTGRAY);
12}
test/tests.zig+1
......@@ -537,6 +537,7 @@ pub fn addPkgTests(
537537 these_tests.enable_qemu = is_qemu_enabled;
538538 these_tests.enable_wasmtime = is_wasmtime_enabled;
539539 these_tests.glibc_multi_install_dir = glibc_dir;
540 these_tests.addIncludeDir("test");
540541
541542 step.dependOn(&these_tests.step);
542543 }