authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-03-07 19:55:00+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-19 19:10:11-07:00
log03d392923208550c21f2f3813379830b76c54133
tree8bbe0dfc65e91bc0e9c5d4575a6044498ec800c4
parent1e2cd421b931b1de14492868647a88b7246722ae

autodoc: add simplified support for tests


1 files changed, 8 insertions(+), 1 deletions(-)

src/Autodoc.zig+8-1
...@@ -1388,12 +1388,15 @@ fn walkDecls(...@@ -1388,12 +1388,15 @@ fn walkDecls(
1388 // const pub_str = if (is_pub) "pub " else "";1388 // const pub_str = if (is_pub) "pub " else "";
1389 // const hash_bytes = @bitCast([16]u8, hash_u32s.*);1389 // const hash_bytes = @bitCast([16]u8, hash_u32s.*);
13901390
1391 var is_test = false; // we discover if it's a test by lookin at its name
1391 const name: []const u8 = blk: {1392 const name: []const u8 = blk: {
1392 if (decl_name_index == 0) {1393 if (decl_name_index == 0) {
1393 break :blk if (is_exported) "usingnamespace" else "comptime";1394 break :blk if (is_exported) "usingnamespace" else "comptime";
1394 } else if (decl_name_index == 1) {1395 } else if (decl_name_index == 1) {
1396 is_test = true;
1395 break :blk "test";1397 break :blk "test";
1396 } else if (decl_name_index == 2) {1398 } else if (decl_name_index == 2) {
1399 is_test = true;
1397 // it is a decltest1400 // it is a decltest
1398 const decl_being_tested = scope.resolveDeclName(doc_comment_index);1401 const decl_being_tested = scope.resolveDeclName(doc_comment_index);
1399 const ast_node_index = idx: {1402 const ast_node_index = idx: {
...@@ -1471,6 +1474,7 @@ fn walkDecls(...@@ -1471,6 +1474,7 @@ fn walkDecls(
1471 } else {1474 } else {
1472 const raw_decl_name = file.zir.nullTerminatedString(decl_name_index);1475 const raw_decl_name = file.zir.nullTerminatedString(decl_name_index);
1473 if (raw_decl_name.len == 0) {1476 if (raw_decl_name.len == 0) {
1477 is_test = true;
1474 break :blk file.zir.nullTerminatedString(decl_name_index + 1);1478 break :blk file.zir.nullTerminatedString(decl_name_index + 1);
1475 } else {1479 } else {
1476 break :blk raw_decl_name;1480 break :blk raw_decl_name;
...@@ -1496,7 +1500,10 @@ fn walkDecls(...@@ -1496,7 +1500,10 @@ fn walkDecls(
1496 break :idx idx;1500 break :idx idx;
1497 };1501 };
14981502
1499 const walk_result = try self.walkInstruction(file, scope, decl_index);1503 const walk_result = if (is_test) // TODO: decide if tests should show up at all
1504 DocData.WalkResult{ .void = {} }
1505 else
1506 try self.walkInstruction(file, scope, decl_index);
15001507
1501 if (is_pub) {1508 if (is_pub) {
1502 try decl_indexes.append(self.arena, decls_slot_index);1509 try decl_indexes.append(self.arena, decls_slot_index);