mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-24 22:36:10 +01:00
Integrate tests for #1394 into our test suite
This commit is contained in:
parent
d084162b2f
commit
8989c9b560
@ -1,35 +0,0 @@
|
|||||||
// Provide a basis to check whether section selection via the `-c` command line
|
|
||||||
// option works as intended.
|
|
||||||
|
|
||||||
#define CATCH_CONFIG_MAIN
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
bool previouslyRun = false;
|
|
||||||
bool previouslyRunNested = false;
|
|
||||||
|
|
||||||
TEST_CASE( "#1394" ) {
|
|
||||||
// -- Don't re-run after specified section is done
|
|
||||||
REQUIRE(previouslyRun == false);
|
|
||||||
|
|
||||||
SECTION( "RunSection" ) {
|
|
||||||
previouslyRun = true;
|
|
||||||
}
|
|
||||||
SECTION( "SkipSection" ) {
|
|
||||||
// cause an error if this section is called because it shouldn't be
|
|
||||||
REQUIRE(1 == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE( "#1394 nested" ) {
|
|
||||||
REQUIRE(previouslyRunNested == false);
|
|
||||||
|
|
||||||
SECTION( "NestedRunSection" ) {
|
|
||||||
SECTION( "s1" ) {
|
|
||||||
previouslyRunNested = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SECTION( "NestedSkipSection" ) {
|
|
||||||
// cause an error if this section is called because it shouldn't be
|
|
||||||
REQUIRE(1 == 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,7 +21,6 @@ set( REPORTER_HEADER_DIR ${CATCH_DIR}/include/reporters )
|
|||||||
set( SOURCES_SINGLE_FILE
|
set( SOURCES_SINGLE_FILE
|
||||||
010-TestCase.cpp
|
010-TestCase.cpp
|
||||||
231-Cfg-OutputStreams.cpp
|
231-Cfg-OutputStreams.cpp
|
||||||
300-FilteredSection.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# multiple-file modules:
|
# multiple-file modules:
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# make sure single-file header was regenerated
|
|
||||||
../scripts/generateSingleHeader.py
|
|
||||||
|
|
||||||
# run Test case with specified section to trigger bug #1394
|
|
||||||
../cmake-build-debug/examples/300-FilteredSection \#1394 -c RunSection
|
|
||||||
../cmake-build-debug/examples/300-FilteredSection \#1394\ nested -c NestedRunSection -c s1
|
|
@ -9,6 +9,38 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
std::string escape_arg(const std::string& arg) {
|
||||||
|
if (arg.empty() == false &&
|
||||||
|
arg.find_first_of(" \t\n\v\"") == arg.npos) {
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string escaped;
|
||||||
|
escaped.push_back('"');
|
||||||
|
for (auto it = arg.begin(); ; ++it) {
|
||||||
|
int num_backslashes = 0;
|
||||||
|
|
||||||
|
while (it != arg.end() && *it == '\\') {
|
||||||
|
++it;
|
||||||
|
++num_backslashes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it == arg.end()) {
|
||||||
|
escaped.append(num_backslashes * 2, '\\');
|
||||||
|
break;
|
||||||
|
} else if (*it == '"') {
|
||||||
|
escaped.append(num_backslashes * 2 + 1, '\\');
|
||||||
|
escaped.push_back(*it);
|
||||||
|
} else {
|
||||||
|
escaped.append(num_backslashes, '\\');
|
||||||
|
escaped.push_back(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
escaped.push_back('"');
|
||||||
|
|
||||||
|
return escaped;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void create_empty_file(std::string const& path) {
|
void create_empty_file(std::string const& path) {
|
||||||
std::ofstream ofs(path);
|
std::ofstream ofs(path);
|
||||||
@ -60,8 +92,9 @@ std::string windowsify_path(std::string path) {
|
|||||||
void exec_cmd(std::string const& cmd, int log_num, std::string const& path) {
|
void exec_cmd(std::string const& cmd, int log_num, std::string const& path) {
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
// cmd has already been escaped outside this function.
|
||||||
auto real_cmd = "OpenCppCoverage --export_type binary:cov-report" + std::to_string(log_num)
|
auto real_cmd = "OpenCppCoverage --export_type binary:cov-report" + std::to_string(log_num)
|
||||||
+ ".bin --quiet " + "--sources " + path + " --cover_children -- " + cmd;
|
+ ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd;
|
||||||
std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n';
|
std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n';
|
||||||
std::shared_ptr<FILE> pipe(_popen(real_cmd.c_str(), "r"), _pclose);
|
std::shared_ptr<FILE> pipe(_popen(real_cmd.c_str(), "r"), _pclose);
|
||||||
#else // Just for testing, in the real world we will always work under WIN32
|
#else // Just for testing, in the real world we will always work under WIN32
|
||||||
@ -93,7 +126,7 @@ int main(int argc, char** argv) {
|
|||||||
auto num = parse_log_file_arg(args[1]);
|
auto num = parse_log_file_arg(args[1]);
|
||||||
|
|
||||||
auto cmdline = std::accumulate(++sep, end(args), std::string{}, [] (const std::string& lhs, const std::string& rhs) {
|
auto cmdline = std::accumulate(++sep, end(args), std::string{}, [] (const std::string& lhs, const std::string& rhs) {
|
||||||
return lhs + ' ' + rhs;
|
return lhs + ' ' + escape_arg(rhs);
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -345,10 +345,16 @@ set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No asserti
|
|||||||
add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> -w NoTests "___nonexistent_test___")
|
add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> -w NoTests "___nonexistent_test___")
|
||||||
set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched")
|
set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched")
|
||||||
|
|
||||||
|
add_test(NAME FilteredSection-1 COMMAND $<TARGET_FILE:SelfTest> \#1394 -c RunSection)
|
||||||
|
set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
|
||||||
|
add_test(NAME FilteredSection-2 COMMAND $<TARGET_FILE:SelfTest> \#1394\ nested -c NestedRunSection -c s1)
|
||||||
|
set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
|
||||||
|
|
||||||
# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
|
# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable
|
||||||
add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
|
add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
|
||||||
set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
|
set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
|
||||||
|
|
||||||
|
|
||||||
if (CATCH_USE_VALGRIND)
|
if (CATCH_USE_VALGRIND)
|
||||||
add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)
|
add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)
|
||||||
add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
|
add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
|
||||||
|
@ -324,3 +324,33 @@ TEST_CASE( "Tracker" ) {
|
|||||||
// two sections within a generator
|
// two sections within a generator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool previouslyRun = false;
|
||||||
|
static bool previouslyRunNested = false;
|
||||||
|
|
||||||
|
TEST_CASE( "#1394", "[.][approvals][tracker]" ) {
|
||||||
|
// -- Don't re-run after specified section is done
|
||||||
|
REQUIRE(previouslyRun == false);
|
||||||
|
|
||||||
|
SECTION( "RunSection" ) {
|
||||||
|
previouslyRun = true;
|
||||||
|
}
|
||||||
|
SECTION( "SkipSection" ) {
|
||||||
|
// cause an error if this section is called because it shouldn't be
|
||||||
|
REQUIRE(1 == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "#1394 nested", "[.][approvals][tracker]" ) {
|
||||||
|
REQUIRE(previouslyRunNested == false);
|
||||||
|
|
||||||
|
SECTION( "NestedRunSection" ) {
|
||||||
|
SECTION( "s1" ) {
|
||||||
|
previouslyRunNested = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SECTION( "NestedSkipSection" ) {
|
||||||
|
// cause an error if this section is called because it shouldn't be
|
||||||
|
REQUIRE(1 == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user