Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-06-04 22:37:59 +0200
committerMartin Hořeňovský2017-06-04 22:37:59 +0200
commit860de28b8d87d97cd2405cecb28fb63fb8c73d0c (patch)
tree3c8e4a428430309bea6c9693dcdfc3aac6cf0f1b /include
parentda0edcbe257c9b5f19e69906ce1b10f4dac4fa98 (diff)
downloadcatch3-860de28b8d87d97cd2405cecb28fb63fb8c73d0c.tar.gz
Catch and register startup exceptions in autoregistrars
Previously they were registered where they would be thrown otherwise
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_tag_alias_registry.hpp35
-rw-r--r--include/internal/catch_test_case_info.hpp14
-rw-r--r--include/internal/catch_test_case_registry_impl.hpp20
3 files changed, 28 insertions, 41 deletions
diff --git a/include/internal/catch_tag_alias_registry.hpp b/include/internal/catch_tag_alias_registry.hpp
index a078e3ce..7439c36d 100644
--- a/include/internal/catch_tag_alias_registry.hpp
+++ b/include/internal/catch_tag_alias_registry.hpp
@@ -39,29 +39,13 @@ namespace Catch {
}
void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
- // Do not throw when constructing global objects, instead register the exception to be processed later
- if (!(startsWith( alias, "[@") && endsWith(alias, ']'))) {
- getMutableRegistryHub().registerStartupException(
- std::make_exception_ptr(
- CATCH_PREPARE_EXCEPTION( std::domain_error,
- "error: tag alias, '"
- << alias
- << "' is not of the form [@alias name].\n"
- << lineInfo)
- )
- );
- }
+ CATCH_ENFORCE( startsWith(alias, "[@") && endsWith(alias, ']'),
+ "error: tag alias, '" << alias << "' is not of the form [@alias name].\n" << lineInfo );
- if (!m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second) {
- getMutableRegistryHub().registerStartupException(
- std::make_exception_ptr(
- CATCH_PREPARE_EXCEPTION(std::domain_error,
- "error: tag alias, '" << alias << "' already registered.\n"
- << "\tFirst seen at: " << find(alias)->lineInfo << "\n"
- << "\tRedefined at: " << lineInfo)
- )
- );
- }
+ CATCH_ENFORCE( m_registry.insert(std::make_pair(alias, TagAlias(tag, lineInfo))).second,
+ "error: tag alias, '" << alias << "' already registered.\n"
+ << "\tFirst seen at: " << find(alias)->lineInfo << "\n"
+ << "\tRedefined at: " << lineInfo );
}
ITagAliasRegistry::~ITagAliasRegistry() {}
@@ -71,7 +55,12 @@ namespace Catch {
}
RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
- getMutableRegistryHub().registerTagAlias( alias, tag, lineInfo );
+ try {
+ getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo);
+ } catch (...) {
+ // Do not throw when constructing global objects, instead register the exception to be processed later
+ getMutableRegistryHub().registerStartupException(std::current_exception());
+ }
}
} // end namespace Catch
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 0af74698..8adf40c7 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -38,16 +38,10 @@ namespace Catch {
return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] );
}
inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
- // Do not throw when constructing global objects, instead register the exception to be processed later
- if (isReservedTag(tag)) {
- getMutableRegistryHub().registerStartupException(
- std::make_exception_ptr(
- CATCH_PREPARE_EXCEPTION(std::domain_error, "Tag name: [" << tag << "] is not allowed.\n"
- << "Tag names starting with non alpha-numeric characters are reserved\n"
- << _lineInfo)
- )
- );
- }
+ CATCH_ENFORCE( !isReservedTag(tag),
+ "Tag name: [" << tag << "] is not allowed.\n"
+ << "Tag names starting with non alpha-numeric characters are reserved\n"
+ << _lineInfo );
}
TestCase makeTestCase( ITestCase* _testCase,
diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp
index 5406c543..eebde92c 100644
--- a/include/internal/catch_test_case_registry_impl.hpp
+++ b/include/internal/catch_test_case_registry_impl.hpp
@@ -154,14 +154,18 @@ namespace Catch {
char const* classOrQualifiedMethodName,
NameAndDesc const& nameAndDesc,
SourceLineInfo const& lineInfo ) {
-
- getMutableRegistryHub().registerTest
- ( makeTestCase
- ( testCase,
- extractClassName( classOrQualifiedMethodName ),
- nameAndDesc.name,
- nameAndDesc.description,
- lineInfo ) );
+ try {
+ getMutableRegistryHub().registerTest
+ (makeTestCase
+ (testCase,
+ extractClassName(classOrQualifiedMethodName),
+ nameAndDesc.name,
+ nameAndDesc.description,
+ lineInfo));
+ } catch (...) {
+ // Do not throw when constructing global objects, instead register the exception to be processed later
+ getMutableRegistryHub().registerStartupException( std::current_exception() );
+ }
}
void registerTestCaseFunction
( TestFunction function,