diff options
Diffstat (limited to 'src/expand/test.cpp')
-rw-r--r-- | src/expand/test.cpp | 60 |
1 files changed, 60 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); |