diff options
| author | Martin Hořeňovský | 2023-05-20 19:25:00 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-05-20 21:13:48 +0200 |
| commit | a153fce72402c74bb8480c0776f86f889b658fc1 (patch) | |
| tree | d100ab06f5f1177b5d705dd9a83ea9b698fa60c1 /src/catch2 | |
| parent | 06c0e1cfab2a2fd6d01527b92422df2a8c49a8d7 (diff) | |
| download | catch3-a153fce72402c74bb8480c0776f86f889b658fc1.tar.gz | |
Improve error messages for TEST_CASE tag parsing errors
Also removes a duplicated test case checking for empty tag error.
Related to #2650
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/catch_test_case_info.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp index a6adce0a..e9dad577 100644 --- a/src/catch2/catch_test_case_info.cpp +++ b/src/catch2/catch_test_case_info.cpp @@ -139,12 +139,20 @@ namespace Catch { for (size_t idx = 0; idx < originalTags.size(); ++idx) { auto c = originalTags[idx]; if (c == '[') { - assert(!inTag); + CATCH_ENFORCE( + !inTag, + "Found '[' inside a tag while registering test case '" + << _nameAndTags.name << "' at " << _lineInfo ); + inTag = true; tagStart = idx; } if (c == ']') { - assert(inTag); + CATCH_ENFORCE( + inTag, + "Found unmatched ']' while registering test case '" + << _nameAndTags.name << "' at " << _lineInfo ); + inTag = false; tagEnd = idx; assert(tagStart < tagEnd); @@ -153,7 +161,11 @@ namespace Catch { // it over to backing storage and actually reference the // backing storage in the saved tags StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1); - CATCH_ENFORCE(!tagStr.empty(), "Empty tags are not allowed"); + CATCH_ENFORCE( !tagStr.empty(), + "Found an empty tag while registering test case '" + << _nameAndTags.name << "' at " + << _lineInfo ); + enforceNotReservedTag(tagStr, lineInfo); properties |= parseSpecialTag(tagStr); // When copying a tag to the backing storage, we need to @@ -167,8 +179,12 @@ namespace Catch { // the tags. internalAppendTag(tagStr); } - (void)inTag; // Silence "set-but-unused" warning in release mode. } + CATCH_ENFORCE( !inTag, + "Found an unclosed tag while registering test case '" + << _nameAndTags.name << "' at " << _lineInfo ); + + // Add [.] if relevant if (isHidden()) { internalAppendTag("."_sr); |