Commit 5e88a7a427
Changed files (5)
test
test/stage1/behavior/translate_c_macros.h
@@ -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
\ No newline at end of file
test/stage1/behavior/translate_c_macros.zig
@@ -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);
+}
test/stage1/behavior.zig
@@ -133,4 +133,5 @@ comptime {
_ = @import("behavior/while.zig");
_ = @import("behavior/widening.zig");
_ = @import("behavior/src.zig");
+ _ = @import("behavior/translate_c_macros.zig");
}
test/tests.zig
@@ -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);
}
CONTRIBUTING.md
@@ -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.