cmake: discover wrapped test declarations in the scanner (X-QA-03)
This commit is contained in:
1 parent
f158d7b1cc
commit
4bc8a7c59b
2 files changed
+75
-2
No files matched your search
@@ -22,6 +22,15 @@ set(fixture_class_name "")
|
|||||||
set(fixture_indent "")
|
set(fixture_indent "")
|
||||||
set(line_number 0)
|
set(line_number 0)
|
||||||
|
|
||||||
|
# A Test/DisabledTest declaration may wrap across lines. These patterns let
|
||||||
|
# the loop join such a declaration into one logical line instead of silently
|
||||||
|
# dropping it (X-QA-03).
|
||||||
|
set(_test_decl_regex "(Void::Testing::)?(Test|DisabledTest)[ \t]+([A-Za-z_][A-Za-z0-9_]*)[ \t]*\\(\\s*\\)")
|
||||||
|
set(_test_decl_start_regex "^[ \t]*(Void::Testing::)?(Test|DisabledTest)([ \t]|$)")
|
||||||
|
set(_test_decl_partial_regex "^[ \t]*(Void::Testing::)?(Test|DisabledTest)([ \t]+[A-Za-z_][A-Za-z0-9_]*)?[ \t]*\\(?[ \t]*$")
|
||||||
|
set(pending_decl "")
|
||||||
|
set(pending_decl_line 0)
|
||||||
|
|
||||||
# Accumulators for preceding comments
|
# Accumulators for preceding comments
|
||||||
set(current_tags "")
|
set(current_tags "")
|
||||||
set(current_skip "")
|
set(current_skip "")
|
||||||
@@ -33,6 +42,32 @@ foreach(line IN LISTS lines)
|
|||||||
string(REPLACE "__VOID_SCAN_SC__" ";" line "${line}")
|
string(REPLACE "__VOID_SCAN_SC__" ";" line "${line}")
|
||||||
string(REPLACE "__VOID_SCAN_BS__" "\\" line "${line}")
|
string(REPLACE "__VOID_SCAN_BS__" "\\" line "${line}")
|
||||||
|
|
||||||
|
# Join a wrapped test declaration before any other per-line handling so
|
||||||
|
# tags/skip comments that precede it stay associated with it.
|
||||||
|
set(registration_line ${line_number})
|
||||||
|
if(pending_decl)
|
||||||
|
string(APPEND pending_decl " ${line}")
|
||||||
|
if(pending_decl MATCHES "${_test_decl_regex}")
|
||||||
|
# Complete: process the joined declaration as one logical line.
|
||||||
|
set(line "${pending_decl}")
|
||||||
|
set(registration_line ${pending_decl_line})
|
||||||
|
set(pending_decl "")
|
||||||
|
elseif(pending_decl MATCHES "${_test_decl_partial_regex}")
|
||||||
|
continue()
|
||||||
|
else()
|
||||||
|
# Not a wrapped test declaration after all; handle this line
|
||||||
|
# normally and drop the accumulated prefix.
|
||||||
|
set(pending_decl "")
|
||||||
|
endif()
|
||||||
|
elseif(line MATCHES "${_test_decl_start_regex}" AND NOT line MATCHES "${_test_decl_regex}")
|
||||||
|
set(pending_decl "${line}")
|
||||||
|
set(pending_decl_line ${line_number})
|
||||||
|
if(pending_decl MATCHES "${_test_decl_partial_regex}")
|
||||||
|
continue()
|
||||||
|
endif()
|
||||||
|
set(pending_decl "")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Parse preceding comments for @tag and @skip
|
# Parse preceding comments for @tag and @skip
|
||||||
string(REGEX MATCH "//[ \t]*@tag[ \t]+(.*)" _tag_match "${line}")
|
string(REGEX MATCH "//[ \t]*@tag[ \t]+(.*)" _tag_match "${line}")
|
||||||
if(_tag_match)
|
if(_tag_match)
|
||||||
@@ -129,11 +164,11 @@ foreach(line IN LISTS lines)
|
|||||||
|
|
||||||
if(in_fixture_class)
|
if(in_fixture_class)
|
||||||
string(APPEND registrations
|
string(APPEND registrations
|
||||||
"static Void::Testing::Detail::test_registrar<&${fixture_class_name}::${func_name}> _auto_reg_${safe_func_name}{\"${SUITE_NAME}\", \"${INPUT_FILE_FORWARD}\", ${line_number}, \"${func_name}\", std::vector<std::string>${tags_cpp}, ${is_skipped_str}, ${current_skip}};\n"
|
"static Void::Testing::Detail::test_registrar<&${fixture_class_name}::${func_name}> _auto_reg_${safe_func_name}{\"${SUITE_NAME}\", \"${INPUT_FILE_FORWARD}\", ${registration_line}, \"${func_name}\", std::vector<std::string>${tags_cpp}, ${is_skipped_str}, ${current_skip}};\n"
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
string(APPEND registrations
|
string(APPEND registrations
|
||||||
"static Void::Testing::Detail::test_registrar<&${func_name}> _auto_reg_${safe_func_name}{\"${SUITE_NAME}\", \"${INPUT_FILE_FORWARD}\", ${line_number}, \"${func_name}\", std::vector<std::string>${tags_cpp}, ${is_skipped_str}, ${current_skip}};\n"
|
"static Void::Testing::Detail::test_registrar<&${func_name}> _auto_reg_${safe_func_name}{\"${SUITE_NAME}\", \"${INPUT_FILE_FORWARD}\", ${registration_line}, \"${func_name}\", std::vector<std::string>${tags_cpp}, ${is_skipped_str}, ${current_skip}};\n"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Fixture.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
// Regression fixture for cmake/VoidTestScanner.cmake (X-QA-03): a test
|
||||||
|
// declaration that wraps across lines must be discovered and registered
|
||||||
|
// exactly like a single-line declaration.
|
||||||
|
|
||||||
|
// Control: the same declaration on one line is already discovered.
|
||||||
|
Void::Testing::Test scanner_single_line_control()
|
||||||
|
{
|
||||||
|
Void::Testing::expect(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapped between the return type and the function name.
|
||||||
|
Void::Testing::Test
|
||||||
|
scanner_wrapped_return_type()
|
||||||
|
{
|
||||||
|
Void::Testing::expect(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapped between the function name and the empty parameter list.
|
||||||
|
Void::Testing::Test scanner_wrapped_name
|
||||||
|
()
|
||||||
|
{
|
||||||
|
Void::Testing::expect(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScannerWrappedFixture : public Void::Testing::Fixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Wrapped member declaration inside a fixture class.
|
||||||
|
Void::Testing::Test
|
||||||
|
wrapped_member()
|
||||||
|
{
|
||||||
|
Void::Testing::expect(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user