authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-18 19:56:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-18 22:01:09-07:00
log9e6ff713300295150a02c6ab12852d325d92559a
tree0fb1853d4d2f0e9c1734a40e05455312fb850e73
parent9b714e019c1c26143112ee1e7930a95cd94797f4

langref: delete Nested Container Tests section

This section documented how a buggy feature worked at one point in time but it's not a description of what is supposed to happen. What is supposed to happen is simple enough to not warrant any documentation about it. When a file is imported, all the test decls are supposed to be queued for analysis. Also, refAllDecls() is a hack which should not be celebrated or even mentioned in the language reference. closes #18042

1 files changed, 0 insertions(+), 68 deletions(-)

doc/langref.html.in-68
......@@ -1173,74 +1173,6 @@ fn addOne(number: i32) i32 {
11731173 </p>
11741174 {#see_also|The Global Error Set|Grammar#}
11751175 {#header_close#}
1176 {#header_open|Nested Container Tests#}
1177 <p>
1178 When the <kbd>zig test</kbd> tool is building a test runner, only resolved {#syntax#}test{#endsyntax#}
1179 declarations are included in the build. Initially, only the given Zig source file's top-level
1180 declarations are resolved. Unless nested {#link|containers|Containers#} are referenced from a top-level test declaration,
1181 nested container tests will not be resolved.
1182 </p>
1183 <p>
1184 The code sample below uses the {#syntax#}std.testing.refAllDecls(@This()){#endsyntax#} function call to
1185 reference all of the containers that are in the file including the imported Zig source file. The code
1186 sample also shows an alternative way to reference containers using the {#syntax#}_ = C;{#endsyntax#}
1187 syntax. This syntax tells the compiler to ignore the result of the expression on the right side of the
1188 assignment operator.
1189 </p>
1190 {#code_begin|test|testing_nested_container_tests#}
1191const std = @import("std");
1192const expect = std.testing.expect;
1193
1194// Imported source file tests will run when referenced from a top-level test declaration.
1195// The next line alone does not cause "testing_introduction.zig" tests to run.
1196const imported_file = @import("testing_introduction.zig");
1197
1198test {
1199 // To run nested container tests, either, call `refAllDecls` which will
1200 // reference all declarations located in the given argument.
1201 // `@This()` is a builtin function that returns the innermost container it is called from.
1202 // In this example, the innermost container is this file (implicitly a struct).
1203 std.testing.refAllDecls(@This());
1204
1205 // or, reference each container individually from a top-level test declaration.
1206 // The `_ = C;` syntax is a no-op reference to the identifier `C`.
1207 _ = S;
1208 _ = U;
1209 _ = @import("testing_introduction.zig");
1210}
1211
1212const S = struct {
1213 test "S demo test" {
1214 try expect(true);
1215 }
1216
1217 const SE = enum {
1218 V,
1219
1220 // This test won't run because its container (SE) is not referenced.
1221 test "This Test Won't Run" {
1222 try expect(false);
1223 }
1224 };
1225};
1226
1227const U = union { // U is referenced by the file's top-level test declaration
1228 s: US, // and US is referenced here; therefore, "U.Us demo test" will run
1229
1230 const US = struct {
1231 test "U.US demo test" {
1232 // This test is a top-level test declaration for the struct.
1233 // The struct is nested (declared) inside of a union.
1234 try expect(true);
1235 }
1236 };
1237
1238 test "U demo test" {
1239 try expect(true);
1240 }
1241};
1242 {#code_end#}
1243 {#header_close#}
12441176 {#header_open|Test Failure#}
12451177 <p>
12461178 The default test runner checks for an {#link|error|Errors#} returned from a test.