authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:19:37-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-30 00:19:37-07:00
log692c254336da71cbe21aaf9fbc21240fd1269b95
treefe9c5fdfd23281c593345ae40c90ccecab48ce9b
parent902df103c6151c257c90de9ba5f29f7f4b9dbea2

Revert "I found some more passing behavior tests"

This reverts commit 0a9b4d092f58595888f9e4be8ef683b2ed8a0da1. Hm, these are all passing for me locally. I'll have to do some troubleshooting to figure out which one(s) are failing on the CI.

6 files changed, 262 insertions(+), 248 deletions(-)

test/behavior.zig+18-16
......@@ -10,41 +10,32 @@ test {
1010 _ = @import("behavior/bugs/655.zig");
1111 _ = @import("behavior/bugs/679.zig");
1212 _ = @import("behavior/bugs/704.zig");
13 _ = @import("behavior/bugs/1111.zig");
1413 _ = @import("behavior/bugs/1486.zig");
1514 _ = @import("behavior/bugs/2346.zig");
1615 _ = @import("behavior/bugs/2692.zig");
1716 _ = @import("behavior/bugs/2889.zig");
18 _ = @import("behavior/bugs/3046.zig");
1917 _ = @import("behavior/bugs/3586.zig");
2018 _ = @import("behavior/bugs/4560.zig");
2119 _ = @import("behavior/bugs/4769_a.zig");
2220 _ = @import("behavior/bugs/4769_b.zig");
23 _ = @import("behavior/bugs/4954.zig");
2421 _ = @import("behavior/bugs/6850.zig");
25 _ = @import("behavior/byval_arg_var.zig");
2622 _ = @import("behavior/call.zig");
2723 _ = @import("behavior/cast.zig");
2824 _ = @import("behavior/defer.zig");
2925 _ = @import("behavior/enum.zig");
3026 _ = @import("behavior/error.zig");
31 _ = @import("behavior/fn_in_struct_in_comptime.zig");
3227 _ = @import("behavior/generics.zig");
3328 _ = @import("behavior/hasdecl.zig");
3429 _ = @import("behavior/hasfield.zig");
3530 _ = @import("behavior/if.zig");
3631 _ = @import("behavior/import.zig");
37 _ = @import("behavior/incomplete_struct_param_tld.zig");
3832 _ = @import("behavior/int128.zig");
39 _ = @import("behavior/inttoptr.zig");
4033 _ = @import("behavior/member_func.zig");
4134 _ = @import("behavior/null.zig");
4235 _ = @import("behavior/optional.zig");
4336 _ = @import("behavior/pointers.zig");
4437 _ = @import("behavior/ptrcast.zig");
4538 _ = @import("behavior/pub_enum.zig");
46 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
47 _ = @import("behavior/slice_sentinel_comptime.zig");
4839 _ = @import("behavior/struct.zig");
4940 _ = @import("behavior/this.zig");
5041 _ = @import("behavior/translate_c_macros.zig");
......@@ -56,22 +47,17 @@ test {
5647 if (builtin.object_format != .c) {
5748 // Tests that pass for stage1 and stage2 but not the C backend.
5849 _ = @import("behavior/align_llvm.zig");
59 _ = @import("behavior/alignof.zig");
6050 _ = @import("behavior/array.zig");
6151 _ = @import("behavior/atomics.zig");
6252 _ = @import("behavior/basic_llvm.zig");
6353 _ = @import("behavior/bugs/394.zig");
64 _ = @import("behavior/bugs/656.zig");
6554 _ = @import("behavior/bugs/1277.zig");
66 _ = @import("behavior/bugs/1381.zig");
6755 _ = @import("behavior/bugs/1500.zig");
6856 _ = @import("behavior/bugs/1741.zig");
6957 _ = @import("behavior/bugs/2006.zig");
70 _ = @import("behavior/bugs/2578.zig");
71 _ = @import("behavior/bugs/3007.zig");
7258 _ = @import("behavior/bugs/3112.zig");
73 _ = @import("behavior/bugs/7250.zig");
7459 _ = @import("behavior/cast_llvm.zig");
60 _ = @import("behavior/error.zig");
7561 _ = @import("behavior/eval.zig");
7662 _ = @import("behavior/floatop.zig");
7763 _ = @import("behavior/fn.zig");
......@@ -79,7 +65,6 @@ test {
7965 _ = @import("behavior/generics_llvm.zig");
8066 _ = @import("behavior/math.zig");
8167 _ = @import("behavior/maximum_minimum.zig");
82 _ = @import("behavior/namespace_depends_on_compile_var.zig");
8368 _ = @import("behavior/null_llvm.zig");
8469 _ = @import("behavior/optional_llvm.zig");
8570 _ = @import("behavior/popcount.zig");
......@@ -99,6 +84,7 @@ test {
9984 _ = @import("behavior/slice_stage2.zig");
10085 } else {
10186 _ = @import("behavior/align_stage1.zig");
87 _ = @import("behavior/alignof.zig");
10288 _ = @import("behavior/array_stage1.zig");
10389 if (builtin.os.tag != .wasi) {
10490 _ = @import("behavior/asm.zig");
......@@ -110,15 +96,18 @@ test {
11096 _ = @import("behavior/bitreverse.zig");
11197 _ = @import("behavior/bugs/421.zig");
11298 _ = @import("behavior/bugs/529.zig");
99 _ = @import("behavior/bugs/656.zig");
113100 _ = @import("behavior/bugs/718.zig");
114101 _ = @import("behavior/bugs/726.zig");
115102 _ = @import("behavior/bugs/828.zig");
116103 _ = @import("behavior/bugs/920.zig");
117104 _ = @import("behavior/bugs/1025.zig");
118105 _ = @import("behavior/bugs/1076.zig");
106 _ = @import("behavior/bugs/1111.zig");
119107 _ = @import("behavior/bugs/1120.zig");
120108 _ = @import("behavior/bugs/1310.zig");
121109 _ = @import("behavior/bugs/1322.zig");
110 _ = @import("behavior/bugs/1381.zig");
122111 _ = @import("behavior/bugs/1421.zig");
123112 _ = @import("behavior/bugs/1442.zig");
124113 _ = @import("behavior/bugs/1607.zig");
......@@ -126,11 +115,15 @@ test {
126115 _ = @import("behavior/bugs/1851.zig");
127116 _ = @import("behavior/bugs/1914.zig");
128117 _ = @import("behavior/bugs/2114.zig");
118 _ = @import("behavior/bugs/2578.zig");
119 _ = @import("behavior/bugs/3007.zig");
120 _ = @import("behavior/bugs/3046.zig");
129121 _ = @import("behavior/bugs/3367.zig");
130122 _ = @import("behavior/bugs/3384.zig");
131123 _ = @import("behavior/bugs/3742.zig");
132124 _ = @import("behavior/bugs/3779.zig");
133125 _ = @import("behavior/bugs/4328.zig");
126 _ = @import("behavior/bugs/4954.zig");
134127 _ = @import("behavior/bugs/5398.zig");
135128 _ = @import("behavior/bugs/5413.zig");
136129 _ = @import("behavior/bugs/5474.zig");
......@@ -140,10 +133,12 @@ test {
140133 _ = @import("behavior/bugs/7003.zig");
141134 _ = @import("behavior/bugs/7027.zig");
142135 _ = @import("behavior/bugs/7047.zig");
136 _ = @import("behavior/bugs/7250.zig");
143137 _ = @import("behavior/bugs/9584.zig");
144138 _ = @import("behavior/bugs/9967.zig");
145139 _ = @import("behavior/bugs/10147.zig");
146140 _ = @import("behavior/byteswap.zig");
141 _ = @import("behavior/byval_arg_var.zig");
147142 _ = @import("behavior/call_stage1.zig");
148143 _ = @import("behavior/cast_stage1.zig");
149144 _ = @import("behavior/const_slice_child.zig");
......@@ -155,22 +150,28 @@ test {
155150 _ = @import("behavior/floatop_stage1.zig");
156151 _ = @import("behavior/fn_stage1.zig");
157152 _ = @import("behavior/fn_delegation.zig");
153 _ = @import("behavior/fn_in_struct_in_comptime.zig");
158154 _ = @import("behavior/for_stage1.zig");
159155 _ = @import("behavior/if_stage1.zig");
156 _ = @import("behavior/incomplete_struct_param_tld.zig");
157 _ = @import("behavior/inttoptr.zig");
160158 _ = @import("behavior/ir_block_deps.zig");
161159 _ = @import("behavior/math_stage1.zig");
162160 _ = @import("behavior/merge_error_sets.zig");
163161 _ = @import("behavior/misc.zig");
164162 _ = @import("behavior/muladd.zig");
163 _ = @import("behavior/namespace_depends_on_compile_var.zig");
165164 _ = @import("behavior/null_stage1.zig");
166165 _ = @import("behavior/optional_stage1.zig");
167166 _ = @import("behavior/pointers_stage1.zig");
168167 _ = @import("behavior/popcount_stage1.zig");
169168 _ = @import("behavior/ptrcast_stage1.zig");
169 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
170170 _ = @import("behavior/reflection.zig");
171171 _ = @import("behavior/select.zig");
172172 _ = @import("behavior/shuffle.zig");
173173 _ = @import("behavior/sizeof_and_typeof_stage1.zig");
174 _ = @import("behavior/slice_sentinel_comptime.zig");
174175 _ = @import("behavior/slice_stage1.zig");
175176 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
176177 _ = @import("behavior/struct_contains_slice_of_itself.zig");
......@@ -185,6 +186,7 @@ test {
185186 _ = @import("behavior/typename.zig");
186187 _ = @import("behavior/union_stage1.zig");
187188 _ = @import("behavior/union_with_members.zig");
189 _ = @import("behavior/usingnamespace_stage1.zig");
188190 _ = @import("behavior/var_args.zig");
189191 _ = @import("behavior/vector.zig");
190192 if (builtin.target.cpu.arch == .wasm32) {
test/behavior/struct.zig-141
......@@ -6,55 +6,12 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9top_level_field: i32,
10
11test "top level fields" {
12 var instance = @This(){
13 .top_level_field = 1234,
14 };
15 instance.top_level_field += 1;
16 try expect(@as(i32, 1235) == instance.top_level_field);
17}
18
199const StructWithNoFields = struct {
2010 fn add(a: i32, b: i32) i32 {
2111 return a + b;
2212 }
2313};
2414
25const StructFoo = struct {
26 a: i32,
27 b: bool,
28 c: f32,
29};
30
31test "structs" {
32 var foo: StructFoo = undefined;
33 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
34 foo.a += 1;
35 foo.b = foo.a == 1;
36 try testFoo(foo);
37 testMutation(&foo);
38 try expect(foo.c == 100);
39}
40fn testFoo(foo: StructFoo) !void {
41 try expect(foo.b);
42}
43fn testMutation(foo: *StructFoo) void {
44 foo.c = 100;
45}
46
47test "struct byval assign" {
48 var foo1: StructFoo = undefined;
49 var foo2: StructFoo = undefined;
50
51 foo1.a = 1234;
52 foo2.a = 0;
53 try expect(foo2.a == 0);
54 foo2 = foo1;
55 try expect(foo2.a == 1234);
56}
57
5815test "call struct static method" {
5916 const result = StructWithNoFields.add(3, 4);
6017 try expect(result == 7);
......@@ -84,23 +41,6 @@ const Val = struct {
8441 x: i32,
8542};
8643
87test "fn call of struct field" {
88 const Foo = struct {
89 ptr: fn () i32,
90 };
91 const S = struct {
92 fn aFunc() i32 {
93 return 13;
94 }
95
96 fn callStructField(foo: Foo) i32 {
97 return foo.ptr();
98 }
99 };
100
101 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
102}
103
10444test "struct initializer" {
10545 const val = Val{ .x = 42 };
10646 try expect(val.x == 42);
......@@ -118,84 +58,3 @@ test "call member function directly" {
11858 const result = MemberFnTestFoo.member(instance);
11959 try expect(result == 1234);
12060}
121
122test "store member function in variable" {
123 const instance = MemberFnTestFoo{ .x = 1234 };
124 const memberFn = MemberFnTestFoo.member;
125 const result = memberFn(instance);
126 try expect(result == 1234);
127}
128
129test "member functions" {
130 const r = MemberFnRand{ .seed = 1234 };
131 try expect(r.getSeed() == 1234);
132}
133const MemberFnRand = struct {
134 seed: u32,
135 pub fn getSeed(r: *const MemberFnRand) u32 {
136 return r.seed;
137 }
138};
139
140test "return struct byval from function" {
141 const bar = makeBar2(1234, 5678);
142 try expect(bar.y == 5678);
143}
144const Bar = struct {
145 x: i32,
146 y: i32,
147};
148fn makeBar2(x: i32, y: i32) Bar {
149 return Bar{
150 .x = x,
151 .y = y,
152 };
153}
154
155test "call method with mutable reference to struct with no fields" {
156 const S = struct {
157 fn doC(s: *const @This()) bool {
158 _ = s;
159 return true;
160 }
161 fn do(s: *@This()) bool {
162 _ = s;
163 return true;
164 }
165 };
166
167 var s = S{};
168 try expect(S.doC(&s));
169 try expect(s.doC());
170 try expect(S.do(&s));
171 try expect(s.do());
172}
173
174test "usingnamespace within struct scope" {
175 const S = struct {
176 usingnamespace struct {
177 pub fn inner() i32 {
178 return 42;
179 }
180 };
181 };
182 try expect(@as(i32, 42) == S.inner());
183}
184
185test "struct field init with catch" {
186 const S = struct {
187 fn doTheTest() !void {
188 var x: anyerror!isize = 1;
189 var req = Foo{
190 .field = x catch undefined,
191 };
192 try expect(req.field == 1);
193 }
194
195 pub const Foo = extern struct {
196 field: isize,
197 };
198 };
199 try S.doTheTest();
200 comptime try S.doTheTest();
201}
test/behavior/struct_llvm.zig+64-51
......@@ -6,6 +6,44 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9const StructWithNoFields = struct {
10 fn add(a: i32, b: i32) i32 {
11 return a + b;
12 }
13};
14
15const StructFoo = struct {
16 a: i32,
17 b: bool,
18 c: f32,
19};
20test "structs" {
21 var foo: StructFoo = undefined;
22 @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
23 foo.a += 1;
24 foo.b = foo.a == 1;
25 try testFoo(foo);
26 testMutation(&foo);
27 try expect(foo.c == 100);
28}
29fn testFoo(foo: StructFoo) !void {
30 try expect(foo.b);
31}
32fn testMutation(foo: *StructFoo) void {
33 foo.c = 100;
34}
35
36test "struct byval assign" {
37 var foo1: StructFoo = undefined;
38 var foo2: StructFoo = undefined;
39
40 foo1.a = 1234;
41 foo2.a = 0;
42 try expect(foo2.a == 0);
43 foo2 = foo1;
44 try expect(foo2.a == 1234);
45}
46
947const Node = struct {
1048 val: Val,
1149 next: *Node,
......@@ -43,61 +81,36 @@ const VoidStructFieldsFoo = struct {
4381 c: void,
4482};
4583
46test "return empty struct from fn" {
47 _ = testReturnEmptyStructFromFn();
48}
49const EmptyStruct2 = struct {};
50fn testReturnEmptyStructFromFn() EmptyStruct2 {
51 return EmptyStruct2{};
84test "member functions" {
85 const r = MemberFnRand{ .seed = 1234 };
86 try expect(r.getSeed() == 1234);
5287}
88const MemberFnRand = struct {
89 seed: u32,
90 pub fn getSeed(r: *const MemberFnRand) u32 {
91 return r.seed;
92 }
93};
5394
54test "pass slice of empty struct to fn" {
55 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
95test "return struct byval from function" {
96 const bar = makeBar2(1234, 5678);
97 try expect(bar.y == 5678);
5698}
57fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
58 return slice.len;
59}
60
61test "for loop over pointers to struct, getting field from struct pointer" {
62 const S = struct {
63 const Foo = struct {
64 name: []const u8,
65 };
66
67 var ok = true;
68
69 fn eql(a: []const u8) bool {
70 _ = a;
71 return true;
72 }
73
74 const ArrayList = struct {
75 fn toSlice(self: *ArrayList) []*Foo {
76 _ = self;
77 return @as([*]*Foo, undefined)[0..0];
78 }
79 };
80
81 fn doTheTest() !void {
82 var objects: ArrayList = undefined;
83
84 for (objects.toSlice()) |obj| {
85 if (eql(obj.name)) {
86 ok = false;
87 }
88 }
89
90 try expect(ok);
91 }
99const Bar = struct {
100 x: i32,
101 y: i32,
102};
103fn makeBar2(x: i32, y: i32) Bar {
104 return Bar{
105 .x = x,
106 .y = y,
92107 };
93 try S.doTheTest();
94108}
95109
96test "self-referencing struct via array member" {
97 const T = struct {
98 children: [1]*@This(),
99 };
100 var x: T = undefined;
101 x = T{ .children = .{&x} };
102 try expect(x.children[0] == &x);
110test "return empty struct from fn" {
111 _ = testReturnEmptyStructFromFn();
112}
113const EmptyStruct2 = struct {};
114fn testReturnEmptyStructFromFn() EmptyStruct2 {
115 return EmptyStruct2{};
103116}
test/behavior/struct_stage1.zig+139
......@@ -6,6 +6,16 @@ const expectEqual = std.testing.expectEqual;
66const expectEqualSlices = std.testing.expectEqualSlices;
77const maxInt = std.math.maxInt;
88
9top_level_field: i32,
10
11test "top level fields" {
12 var instance = @This(){
13 .top_level_field = 1234,
14 };
15 instance.top_level_field += 1;
16 try expectEqual(@as(i32, 1235), instance.top_level_field);
17}
18
919const StructFoo = struct {
1020 a: i32,
1121 b: bool,
......@@ -21,6 +31,36 @@ const Val = struct {
2131 x: i32,
2232};
2333
34test "fn call of struct field" {
35 const Foo = struct {
36 ptr: fn () i32,
37 };
38 const S = struct {
39 fn aFunc() i32 {
40 return 13;
41 }
42
43 fn callStructField(foo: Foo) i32 {
44 return foo.ptr();
45 }
46 };
47
48 try expect(S.callStructField(Foo{ .ptr = S.aFunc }) == 13);
49}
50
51const MemberFnTestFoo = struct {
52 x: i32,
53 fn member(foo: MemberFnTestFoo) i32 {
54 return foo.x;
55 }
56};
57test "store member function in variable" {
58 const instance = MemberFnTestFoo{ .x = 1234 };
59 const memberFn = MemberFnTestFoo.member;
60 const result = memberFn(instance);
61 try expect(result == 1234);
62}
63
2464test "empty struct method call" {
2565 const es = EmptyStruct{};
2666 try expect(es.method() == 1234);
......@@ -37,6 +77,13 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
3777 return EmptyStruct2{};
3878}
3979
80test "pass slice of empty struct to fn" {
81 try expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
82}
83fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
84 return slice.len;
85}
86
4087const APackedStruct = packed struct {
4188 x: u8,
4289 y: u8,
......@@ -285,6 +332,25 @@ fn alloc(comptime T: type) []T {
285332 return &[_]T{};
286333}
287334
335test "call method with mutable reference to struct with no fields" {
336 const S = struct {
337 fn doC(s: *const @This()) bool {
338 _ = s;
339 return true;
340 }
341 fn do(s: *@This()) bool {
342 _ = s;
343 return true;
344 }
345 };
346
347 var s = S{};
348 try expect(S.doC(&s));
349 try expect(s.doC());
350 try expect(S.do(&s));
351 try expect(s.do());
352}
353
288354test "implicit cast packed struct field to const ptr" {
289355 const LevelUpMove = packed struct {
290356 move_id: u9,
......@@ -384,6 +450,17 @@ test "packed struct with fp fields" {
384450 try expectEqual(@as(f32, 20.0), s.data[2]);
385451}
386452
453test "use within struct scope" {
454 const S = struct {
455 usingnamespace struct {
456 pub fn inner() i32 {
457 return 42;
458 }
459 };
460 };
461 try expectEqual(@as(i32, 42), S.inner());
462}
463
387464test "default struct initialization fields" {
388465 const S = struct {
389466 a: i32 = 1234,
......@@ -424,6 +501,41 @@ test "fn with C calling convention returns struct by value" {
424501 comptime try S.entry();
425502}
426503
504test "for loop over pointers to struct, getting field from struct pointer" {
505 const S = struct {
506 const Foo = struct {
507 name: []const u8,
508 };
509
510 var ok = true;
511
512 fn eql(a: []const u8) bool {
513 _ = a;
514 return true;
515 }
516
517 const ArrayList = struct {
518 fn toSlice(self: *ArrayList) []*Foo {
519 _ = self;
520 return @as([*]*Foo, undefined)[0..0];
521 }
522 };
523
524 fn doTheTest() !void {
525 var objects: ArrayList = undefined;
526
527 for (objects.toSlice()) |obj| {
528 if (eql(obj.name)) {
529 ok = false;
530 }
531 }
532
533 try expect(ok);
534 }
535 };
536 try S.doTheTest();
537}
538
427539test "zero-bit field in packed struct" {
428540 const S = packed struct {
429541 x: u10,
......@@ -433,6 +545,24 @@ test "zero-bit field in packed struct" {
433545 _ = x;
434546}
435547
548test "struct field init with catch" {
549 const S = struct {
550 fn doTheTest() !void {
551 var x: anyerror!isize = 1;
552 var req = Foo{
553 .field = x catch undefined,
554 };
555 try expect(req.field == 1);
556 }
557
558 pub const Foo = extern struct {
559 field: isize,
560 };
561 };
562 try S.doTheTest();
563 comptime try S.doTheTest();
564}
565
436566test "packed struct with non-ABI-aligned field" {
437567 const S = packed struct {
438568 x: u9,
......@@ -587,6 +717,15 @@ test "anon struct literal field value initialized with fn call" {
587717 comptime try S.doTheTest();
588718}
589719
720test "self-referencing struct via array member" {
721 const T = struct {
722 children: [1]*@This(),
723 };
724 var x: T = undefined;
725 x = T{ .children = .{&x} };
726 try expect(x.children[0] == &x);
727}
728
590729test "struct with union field" {
591730 const Value = struct {
592731 ref: u32 = 2,
test/behavior/usingnamespace.zig-40
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const expect = std.testing.expect;
32
43const A = struct {
54 pub const B = bool;
......@@ -12,42 +11,3 @@ const C = struct {
1211test "basic usingnamespace" {
1312 try std.testing.expect(C.B == bool);
1413}
15
16fn Foo(comptime T: type) type {
17 return struct {
18 usingnamespace T;
19 };
20}
21
22test "usingnamespace inside a generic struct" {
23 const std2 = Foo(std);
24 const testing2 = Foo(std.testing);
25 try std2.testing.expect(true);
26 try testing2.expect(true);
27}
28
29usingnamespace struct {
30 pub const foo = 42;
31};
32
33test "usingnamespace does not redeclare an imported variable" {
34 comptime try std.testing.expect(@This().foo == 42);
35}
36
37usingnamespace @import("usingnamespace/foo.zig");
38test "usingnamespace omits mixing in private functions" {
39 try expect(@This().privateFunction());
40 try expect(!@This().printText());
41}
42fn privateFunction() bool {
43 return true;
44}
45
46test {
47 _ = @import("usingnamespace/import_segregation.zig");
48}
49
50usingnamespace @import("usingnamespace/a.zig");
51test "two files usingnamespace import each other" {
52 try expect(@This().ok());
53}
test/behavior/usingnamespace_stage1.zig created+41
......@@ -0,0 +1,41 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4fn Foo(comptime T: type) type {
5 return struct {
6 usingnamespace T;
7 };
8}
9
10test "usingnamespace inside a generic struct" {
11 const std2 = Foo(std);
12 const testing2 = Foo(std.testing);
13 try std2.testing.expect(true);
14 try testing2.expect(true);
15}
16
17usingnamespace struct {
18 pub const foo = 42;
19};
20
21test "usingnamespace does not redeclare an imported variable" {
22 comptime try std.testing.expect(@This().foo == 42);
23}
24
25usingnamespace @import("usingnamespace/foo.zig");
26test "usingnamespace omits mixing in private functions" {
27 try expect(@This().privateFunction());
28 try expect(!@This().printText());
29}
30fn privateFunction() bool {
31 return true;
32}
33
34test {
35 _ = @import("usingnamespace/import_segregation.zig");
36}
37
38usingnamespace @import("usingnamespace/a.zig");
39test "two files usingnamespace import each other" {
40 try expect(@This().ok());
41}