diff options
| author | Martin Hořeňovský | 2021-09-25 21:37:03 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-09-25 21:37:03 +0200 |
| commit | fb4153e05e430921574d79d868ebc44dd9528629 (patch) | |
| tree | 80084812f69e65567cdc29de6388b81b72debcfe /tests | |
| parent | e8e28ba40151dff22992c95d367cc75967bc07d4 (diff) | |
| download | catch3-fb4153e05e430921574d79d868ebc44dd9528629.tar.gz | |
Multiple tests can have same name as long as their tags differ
This change also changes it so that test case macros using a
class name can have same name **and** tags as long as the
used class name differs.
Closes #1915
Closes #1999
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ExtraTests/CMakeLists.txt | 53 | ||||
| -rw-r--r-- | tests/ExtraTests/X31-DuplicatedTestCases.cpp | 16 | ||||
| -rw-r--r-- | tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp | 17 | ||||
| -rw-r--r-- | tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp | 22 | ||||
| -rw-r--r-- | tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp | 27 | ||||
| -rw-r--r-- | tests/SelfTest/UsageTests/Misc.tests.cpp | 3 |
6 files changed, 138 insertions, 0 deletions
diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index bd7a575c..bce10df5 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -180,6 +180,55 @@ add_test( COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $<TARGET_FILE:PartialTestCaseEvents> ) + +add_executable(DuplicatedTestCases-SameNameAndTags ${TESTS_DIR}/X31-DuplicatedTestCases.cpp) +target_link_libraries(DuplicatedTestCases-SameNameAndTags PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::SameNameAndTags + COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameAndTags> +) +set_tests_properties( + DuplicatedTestCases::SameNameAndTags + PROPERTIES + PASS_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-SameNameDifferentTags ${TESTS_DIR}/X32-DuplicatedTestCasesDifferentTags.cpp) +target_link_libraries(DuplicatedTestCases-SameNameDifferentTags PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::SameNameDifferentTags + COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameDifferentTags> +) +set_tests_properties( + DuplicatedTestCases::SameNameDifferentTags + PROPERTIES + FAIL_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-DuplicatedTestCaseMethods ${TESTS_DIR}/X33-DuplicatedTestCaseMethods.cpp) +target_link_libraries(DuplicatedTestCases-DuplicatedTestCaseMethods PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::DuplicatedTestCaseMethods + COMMAND $<TARGET_FILE:DuplicatedTestCases-DuplicatedTestCaseMethods> +) +set_tests_properties( + DuplicatedTestCases::DuplicatedTestCaseMethods + PROPERTIES + PASS_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-DifferentFixtures ${TESTS_DIR}/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp) +target_link_libraries(DuplicatedTestCases-DifferentFixtures PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures + COMMAND $<TARGET_FILE:DuplicatedTestCases-DifferentFixtures> +) +set_tests_properties( + DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures + PROPERTIES + FAIL_REGULAR_EXPRESSION "error: .* already defined\\." +) + #add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp) #target_link_libraries(DebugBreakMacros Catch2) #add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break) @@ -196,6 +245,10 @@ set( EXTRA_TEST_BINARIES DisabledExceptions-CustomHandler FallbackStringifier DisableStringification + PartialTestCaseEvents + DuplicatedTestCases-SameNameAndTags + DuplicatedTestCases-SameNameDifferentTags + DuplicatedTestCases-DuplicatedTestCaseMethods # DebugBreakMacros ) diff --git a/tests/ExtraTests/X31-DuplicatedTestCases.cpp b/tests/ExtraTests/X31-DuplicatedTestCases.cpp new file mode 100644 index 00000000..2235ca83 --- /dev/null +++ b/tests/ExtraTests/X31-DuplicatedTestCases.cpp @@ -0,0 +1,16 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test cases with identical name and tags are reported as error + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} +TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} diff --git a/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp b/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp new file mode 100644 index 00000000..6a4246be --- /dev/null +++ b/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp @@ -0,0 +1,17 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test cases with identical name but different tags are + * not reported as an error. + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("A test case with duplicated name but different tags", "[tag1]") {} +TEST_CASE("A test case with duplicated name but different tags", "[tag2]") {} diff --git a/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp b/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp new file mode 100644 index 00000000..ff6660a8 --- /dev/null +++ b/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp @@ -0,0 +1,22 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test case methods with identical class, name and tags are + * reported as error. + */ + +#include <catch2/catch_test_macros.hpp> + +class TestCaseFixture { +public: + int m_a; +}; + +TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} +TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} diff --git a/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp b/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp new file mode 100644 index 00000000..b2021f5f --- /dev/null +++ b/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp @@ -0,0 +1,27 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test case methods with different class, but same name and + * tags name and tags are not reported as error. + */ + +#include <catch2/catch_test_macros.hpp> + +class TestCaseFixture1 { +public: + int m_a; +}; + +class TestCaseFixture2 { +public: + int m_a; +}; + +TEST_CASE_METHOD(TestCaseFixture1, "A test case with duplicated name and tags", "[tag1]") {} +TEST_CASE_METHOD(TestCaseFixture2, "A test case with duplicated name and tags", "[tag1]") {} diff --git a/tests/SelfTest/UsageTests/Misc.tests.cpp b/tests/SelfTest/UsageTests/Misc.tests.cpp index ee4444f5..e3b9bd3a 100644 --- a/tests/SelfTest/UsageTests/Misc.tests.cpp +++ b/tests/SelfTest/UsageTests/Misc.tests.cpp @@ -519,3 +519,6 @@ TEMPLATE_TEST_CASE_SIG("#1954 - 7 arg template test case sig compiles", "[regres (1, 1, 1, 1, 1, 0, 0), (5, 1, 1, 1, 1, 0, 0), (5, 3, 1, 1, 1, 0, 0)) { SUCCEED(); } + +TEST_CASE("Same test name but with different tags is fine", "[.approvals][some-tag]") {} +TEST_CASE("Same test name but with different tags is fine", "[.approvals][other-tag]") {} |