diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
| commit | 54edbc6815e42457cd28fa9f1b94e732504b3fc9 (patch) | |
| tree | 36c97169bf0cd59326a93b8c3c0d458f94aed8a9 /test | |
| parent | 4cb55d3af6a71467b7d4399bedb961c81e9ad3d5 (diff) | |
| parent | d495dcc3c952c99e5358d9610cf09eb856f643b0 (diff) | |
| download | zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.tar.gz zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'test')
| -rw-r--r-- | test/build_examples.zig | 2 | ||||
| -rw-r--r-- | test/stage1/behavior/slice.zig | 13 | ||||
| -rw-r--r-- | test/stage1/behavior/switch.zig | 14 | ||||
| -rw-r--r-- | test/stage1/behavior/type_info.zig | 14 | ||||
| -rw-r--r-- | test/standalone/empty_env/build.zig | 12 | ||||
| -rw-r--r-- | test/standalone/empty_env/main.zig | 6 | ||||
| -rw-r--r-- | test/standalone/use_alias/build.zig | 3 | ||||
| -rw-r--r-- | test/tests.zig | 8 | ||||
| -rw-r--r-- | test/translate_c.zig | 6 |
9 files changed, 68 insertions, 10 deletions
diff --git a/test/build_examples.zig b/test/build_examples.zig index c51fdfdf89..4d9fcc6618 100644 --- a/test/build_examples.zig +++ b/test/build_examples.zig @@ -19,6 +19,7 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { cases.addBuildFile("test/standalone/pkg_import/build.zig"); cases.addBuildFile("test/standalone/use_alias/build.zig"); cases.addBuildFile("test/standalone/brace_expansion/build.zig"); + cases.addBuildFile("test/standalone/empty_env/build.zig"); if (false) { // TODO this test is disabled because it is failing on the CI server's linux. when this is fixed // enable it for at least linux @@ -29,7 +30,6 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { if (!is_windows // TODO support compiling C files on windows with zig build system and builtin.arch == builtin.Arch.x86_64 // TODO add C ABI support for other architectures - and builtin.os != builtin.Os.macosx // TODO macosx C ABI test failures ) { cases.addBuildFile("test/stage1/c_abi/build.zig"); } diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index 19eb570150..7f3d7c95ee 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -47,3 +47,16 @@ test "C pointer" { var slice = buf[0..len]; expectEqualSlices(u8, "kjdhfkjdhf", slice); } + +fn sliceSum(comptime q: []const u8) i32 { + comptime var result = 0; + inline for (q) |item| { + result += item; + } + return result; +} + +test "comptime slices are disambiguated" { + expect(sliceSum([]u8{ 1, 2 }) == 3); + expect(sliceSum([]u8{ 3, 4 }) == 7); +} diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig index 1059bf28f8..046700e7d6 100644 --- a/test/stage1/behavior/switch.zig +++ b/test/stage1/behavior/switch.zig @@ -269,3 +269,17 @@ fn testSwitchOnBoolsFalseWithElse(x: bool) bool { else => false, }; } + +test "u0" { + var val: u0 = 0; + switch (val) { + 0 => expect(val == 0), + } +} + +test "undefined.u0" { + var val: u0 = undefined; + switch (val) { + 0 => expect(val == 0), + } +} diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index 12a7c118b7..3eb91d534f 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -299,3 +299,17 @@ test "type info: optional field unwrapping" { _ = field.offset orelse 0; } + +test "type info: pass to function" { + _ = passTypeInfo(@typeInfo(void)); + _ = comptime passTypeInfo(@typeInfo(void)); +} + +fn passTypeInfo(comptime info: TypeInfo) type { + return void; +} + +test "type info: TypeId -> TypeInfo impl cast" { + _ = passTypeInfo(TypeId.Void); + _ = comptime passTypeInfo(TypeId.Void); +} diff --git a/test/standalone/empty_env/build.zig b/test/standalone/empty_env/build.zig new file mode 100644 index 0000000000..2a184dcd2e --- /dev/null +++ b/test/standalone/empty_env/build.zig @@ -0,0 +1,12 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const main = b.addExecutable("main", "main.zig"); + main.setBuildMode(b.standardReleaseOptions()); + + const run = main.run(); + run.clearEnvironment(); + + const test_step = b.step("test", "Test it"); + test_step.dependOn(&run.step); +} diff --git a/test/standalone/empty_env/main.zig b/test/standalone/empty_env/main.zig new file mode 100644 index 0000000000..20b45c3137 --- /dev/null +++ b/test/standalone/empty_env/main.zig @@ -0,0 +1,6 @@ +const std = @import("std"); + +pub fn main() void { + const env_map = std.os.getEnvMap(std.debug.global_allocator) catch @panic("unable to get env map"); + std.testing.expect(env_map.count() == 0); +} diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig index c700d43db9..5efc2b0a64 100644 --- a/test/standalone/use_alias/build.zig +++ b/test/standalone/use_alias/build.zig @@ -1,10 +1,9 @@ const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { - b.addCIncludePath("."); - const main = b.addTest("main.zig"); main.setBuildMode(b.standardReleaseOptions()); + main.addIncludeDir("."); const test_step = b.step("test", "Test it"); test_step.dependOn(&main.step); diff --git a/test/tests.zig b/test/tests.zig index ad7e5d3652..ba713902ba 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -158,7 +158,6 @@ pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { .step = b.step("test-gen-h", "Run the C header file generation tests"), .test_index = 0, .test_filter = test_filter, - .counter = 0, }; gen_h.addCases(cases); @@ -1105,7 +1104,6 @@ pub const GenHContext = struct { step: *build.Step, test_index: usize, test_filter: ?[]const u8, - counter: usize, const TestCase = struct { name: []const u8, @@ -1208,11 +1206,7 @@ pub const GenHContext = struct { } pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void { - // MacOS appears to not be returning nanoseconds in fstat mtime, - // which causes fast test executions to think the file contents are unchanged. - const modified_name = self.b.fmt("test-{}.zig", self.counter); - self.counter += 1; - const tc = self.create(modified_name, name, source, expected_lines); + const tc = self.create("test.zig", name, source, expected_lines); self.addCase(tc); } diff --git a/test/translate_c.zig b/test/translate_c.zig index f5eeceff95..e83ca74786 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1467,6 +1467,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { "pub const ZERO = c_ulonglong(0);" ); + cases.addC("bitwise not on u-suffixed 0 (zero) in macro definition", + "#define NOT_ZERO (~0U)" + , + "pub const NOT_ZERO = ~c_uint(0);" + ); + // cases.add("empty array with initializer", // "int a[4] = {};" // , |
