diff options
-rw-r--r-- | src/expand/test.cpp | 60 | ||||
-rw-r--r-- | src/expand/test_harness.cpp | 4 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/expand/test.cpp b/src/expand/test.cpp index 26639203..707d0795 100644 --- a/src/expand/test.cpp +++ b/src/expand/test.cpp @@ -24,6 +24,7 @@ class CTestHandler: ::AST::TestDesc td; td.name = path.nodes().back().name(); td.path = ::AST::Path(path); + crate.m_tests.push_back( mv$(td) ); } else @@ -32,6 +33,65 @@ class CTestHandler: } } }; +class CTestHandler_SP: + public ExpandDecorator +{ + AttrStage stage() const override { return AttrStage::Pre; } + + void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + if( ! i.is_Function() ) { + ERROR(sp, E0000, "#[should_panic] can only be put on functions - found on " << i.tag_str()); + } + + if( crate.m_test_harness ) + { + for(auto& td : crate.m_tests) + { + if( td.path != path ) + continue ; + + if( mi.has_sub_items() ) + { + td.panic_type = ::AST::TestDesc::ShouldPanic::YesWithMessage; + // TODO: Check that name is correct and that it is a string + td.expected_panic_message = mi.items().at(0).string(); + } + else + { + td.panic_type = ::AST::TestDesc::ShouldPanic::Yes; + } + return ; + } + //ERROR() + } + } +}; +class CTestHandler_Ignore: + public ExpandDecorator +{ + AttrStage stage() const override { return AttrStage::Pre; } + + void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + if( ! i.is_Function() ) { + ERROR(sp, E0000, "#[should_panic] can only be put on functions - found on " << i.tag_str()); + } + + if( crate.m_test_harness ) + { + for(auto& td : crate.m_tests) + { + if( td.path != path ) + continue ; + + td.ignore = true; + return ; + } + //ERROR() + } + } +}; STATIC_DECORATOR("test", CTestHandler); +STATIC_DECORATOR("should_panic", CTestHandler_SP); +STATIC_DECORATOR("ignore", CTestHandler_Ignore); diff --git a/src/expand/test_harness.cpp b/src/expand/test_harness.cpp index 883bd2aa..12d32121 100644 --- a/src/expand/test_harness.cpp +++ b/src/expand/test_harness.cpp @@ -49,6 +49,10 @@ void Expand_TestHarness(::AST::Crate& crate) for(const auto& test : crate.m_tests) { + // HACK: Don't emit should_panic tests + if( test.panic_type != ::AST::TestDesc::ShouldPanic::No ) + continue ; + ::AST::ExprNode_StructLiteral::t_values desc_vals; // `name: "foo",` desc_vals.push_back( ::std::make_pair("name", NEWNODE(_CallPath, |