| author | |
| committer | |
| log | ac004e1bf13d00804c30f55d479b554774798307 |
| tree | 53f6540c14b043db95aed562945e66d0d9493dc5 |
| parent | fc5ae1c4096fa814b97671525db17c0b4f0b786d |
Nameless blocks are never filtered, the test prefix is still applied.6 files changed, 17 insertions(+), 12 deletions(-)
lib/std/zig/ast.zig+1-1| ... | ... | @@ -3231,7 +3231,7 @@ pub const Node = struct { |
| 3231 | 3231 | base: Node = Node{ .tag = .TestDecl }, |
| 3232 | 3232 | doc_comments: ?*DocComment, |
| 3233 | 3233 | test_token: TokenIndex, |
| 3234 | name: *Node, | |
| 3234 | name: ?*Node, | |
| 3235 | 3235 | body_node: *Node, |
| 3236 | 3236 | |
| 3237 | 3237 | pub fn iterate(self: *const TestDecl, index: usize) ?*Node { |
lib/std/zig/parse.zig+1-3| ... | ... | @@ -366,9 +366,7 @@ const Parser = struct { |
| 366 | 366 | /// TestDecl <- KEYWORD_test STRINGLITERALSINGLE Block |
| 367 | 367 | fn parseTestDecl(p: *Parser) !?*Node { |
| 368 | 368 | const test_token = p.eatToken(.Keyword_test) orelse return null; |
| 369 | const name_node = try p.expectNode(parseStringLiteralSingle, .{ | |
| 370 | .ExpectedStringLiteral = .{ .token = p.tok_i }, | |
| 371 | }); | |
| 369 | const name_node = try p.parseStringLiteralSingle(); | |
| 372 | 370 | const block_node = (try p.parseBlock(null)) orelse { |
| 373 | 371 | try p.errors.append(p.gpa, .{ .ExpectedLBrace = .{ .token = p.tok_i } }); |
| 374 | 372 | return error.ParseError; |
lib/std/zig/render.zig+2-1| ... | ... | @@ -228,7 +228,8 @@ fn renderContainerDecl(allocator: *mem.Allocator, ais: anytype, tree: *ast.Tree, |
| 228 | 228 | |
| 229 | 229 | try renderDocComments(tree, ais, test_decl, test_decl.doc_comments); |
| 230 | 230 | try renderToken(tree, ais, test_decl.test_token, .Space); |
| 231 | try renderExpression(allocator, ais, tree, test_decl.name, .Space); | |
| 231 | if (test_decl.name) |name| | |
| 232 | try renderExpression(allocator, ais, tree, name, .Space); | |
| 232 | 233 | try renderExpression(allocator, ais, tree, test_decl.body_node, space); |
| 233 | 234 | }, |
| 234 | 235 |
src/stage1/all_types.hpp+1| ... | ... | @@ -797,6 +797,7 @@ struct AstNodeVariableDeclaration { |
| 797 | 797 | }; |
| 798 | 798 | |
| 799 | 799 | struct AstNodeTestDecl { |
| 800 | // nullptr if the test declaration has no name | |
| 800 | 801 | Buf *name; |
| 801 | 802 | |
| 802 | 803 | AstNode *body; |
src/stage1/analyze.cpp+10-5| ... | ... | @@ -3871,13 +3871,18 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope |
| 3871 | 3871 | return; |
| 3872 | 3872 | |
| 3873 | 3873 | Buf *decl_name_buf = node->data.test_decl.name; |
| 3874 | Buf *test_name; | |
| 3874 | 3875 | |
| 3875 | Buf *test_name = g->test_name_prefix ? | |
| 3876 | buf_sprintf("%s%s", buf_ptr(g->test_name_prefix), buf_ptr(decl_name_buf)) : decl_name_buf; | |
| 3876 | if (decl_name_buf != nullptr) { | |
| 3877 | test_name = g->test_name_prefix ? | |
| 3878 | buf_sprintf("%s%s", buf_ptr(g->test_name_prefix), buf_ptr(decl_name_buf)) : decl_name_buf; | |
| 3877 | 3879 | |
| 3878 | if (g->test_filter != nullptr && buf_len(test_name) > 0 && | |
| 3879 | strstr(buf_ptr(test_name), buf_ptr(g->test_filter)) == nullptr) { | |
| 3880 | return; | |
| 3880 | if (g->test_filter != nullptr && strstr(buf_ptr(test_name), buf_ptr(g->test_filter)) == nullptr) { | |
| 3881 | return; | |
| 3882 | } | |
| 3883 | } else { | |
| 3884 | // Unnamed test blocks are always executed. | |
| 3885 | test_name = buf_sprintf("%s", g->test_name_prefix ? buf_ptr(g->test_name_prefix) : ""); | |
| 3881 | 3886 | } |
| 3882 | 3887 | |
| 3883 | 3888 | TldFn *tld_fn = heap::c_allocator.create<TldFn>(); |
src/stage1/parser.cpp+2-2| ... | ... | @@ -658,10 +658,10 @@ static AstNode *ast_parse_test_decl(ParseContext *pc) { |
| 658 | 658 | if (test == nullptr) |
| 659 | 659 | return nullptr; |
| 660 | 660 | |
| 661 | Token *name = expect_token(pc, TokenIdStringLiteral); | |
| 661 | Token *name = eat_token_if(pc, TokenIdStringLiteral); | |
| 662 | 662 | AstNode *block = ast_expect(pc, ast_parse_block); |
| 663 | 663 | AstNode *res = ast_create_node(pc, NodeTypeTestDecl, test); |
| 664 | res->data.test_decl.name = token_buf(name); | |
| 664 | res->data.test_decl.name = name ? token_buf(name) : nullptr; | |
| 665 | 665 | res->data.test_decl.body = block; |
| 666 | 666 | return res; |
| 667 | 667 | } |