Switched over to new name/ tag parser

This commit is contained in:
Phil Nash
2014-05-16 18:24:07 +01:00
parent 56b8d3a5f9
commit ae75b3774a
14 changed files with 108 additions and 433 deletions

View File

@@ -216,5 +216,13 @@ TEST_CASE( "Parse test names and tags", "" ) {
CHECK( spec.matches( tcC ) == false );
CHECK( spec.matches( tcD ) == false );
}
SECTION( "quoted string followed by tag exclusion" ) {
TestSpec spec = parseTestSpec( "\"*name*\"~[.]" );
CHECK( spec.hasFilters() == true );
CHECK( spec.matches( tcA ) == false );
CHECK( spec.matches( tcB ) == false );
CHECK( spec.matches( tcC ) == false );
CHECK( spec.matches( tcD ) == true );
}
}

View File

@@ -0,0 +1,2 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "catch_test_spec.h"

View File

@@ -54,18 +54,16 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "test1" ) ) );
}
SECTION( "Specify one test case exclusion using exclude:", "" ) {
const char* argv[] = { "test", "exclude:test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) );
}
SECTION( "Specify one test case exclusion using ~", "" ) {
@@ -73,21 +71,10 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) );
}
SECTION( "Specify two test cases using -t", "" ) {
const char* argv[] = { "test", "-t", "test1", "test2" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test2" ) ) );
}
}
SECTION( "reporter", "" ) {
@@ -191,156 +178,6 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
}
}
TEST_CASE( "selftest/test filter", "Individual filters" ) {
Catch::TestCaseFilter matchAny( "*" );
Catch::TestCaseFilter matchNone( "*", Catch::IfFilterMatches::ExcludeTests );
CHECK( matchAny.shouldInclude( fakeTestCase( "any" ) ));
CHECK( matchNone.shouldInclude( fakeTestCase( "any" ) ) == false );
Catch::TestCaseFilter matchHidden( "./*" );
Catch::TestCaseFilter matchNonHidden( "./*", Catch::IfFilterMatches::ExcludeTests );
CHECK( matchHidden.shouldInclude( fakeTestCase( "any" ) ) == false );
CHECK( matchNonHidden.shouldInclude( fakeTestCase( "any" ) ) );
CHECK( matchHidden.shouldInclude( fakeTestCase( "./any" ) ) );
CHECK( matchNonHidden.shouldInclude( fakeTestCase( "./any" ) ) == false );
}
TEST_CASE( "selftest/test filters", "Sets of filters" ) {
Catch::TestCaseFilter matchHidden( "./*" );
Catch::TestCaseFilter dontMatchA( "./a*", Catch::IfFilterMatches::ExcludeTests );
Catch::TestCaseFilters filters( "" );
filters.addFilter( matchHidden );
filters.addFilter( dontMatchA );
CHECK( matchHidden.shouldInclude( fakeTestCase( "./something" ) ) );
CHECK( filters.shouldInclude( fakeTestCase( "any" ) ) == false );
CHECK( filters.shouldInclude( fakeTestCase( "./something" ) ) );
CHECK( filters.shouldInclude( fakeTestCase( "./anything" ) ) == false );
}
TEST_CASE( "selftest/filter/prefix wildcard", "Individual filters with wildcards at the start" ) {
Catch::TestCaseFilter matchBadgers( "*badger" );
CHECK( matchBadgers.shouldInclude( fakeTestCase( "big badger" ) ));
CHECK( matchBadgers.shouldInclude( fakeTestCase( "little badgers" ) ) == false );
}
TEST_CASE( "selftest/filter/wildcard at both ends", "Individual filters with wildcards at both ends" ) {
Catch::TestCaseFilter matchBadgers( "*badger*" );
CHECK( matchBadgers.shouldInclude( fakeTestCase( "big badger" ) ));
CHECK( matchBadgers.shouldInclude( fakeTestCase( "little badgers" ) ) );
CHECK( matchBadgers.shouldInclude( fakeTestCase( "badgers are big" ) ) );
CHECK( matchBadgers.shouldInclude( fakeTestCase( "hedgehogs" ) ) == false );
}
template<size_t size>
int getArgc( const char * (&)[size] ) {
return size;
}
TEST_CASE( "selftest/tags", "[tags]" ) {
std::string p1 = "[one]";
std::string p2 = "[one],[two]";
std::string p3 = "[one][two]";
std::string p4 = "[one][two],[three]";
std::string p5 = "[one][two]~[.],[three]";
std::string p6 = "[one][two]exclude:[.],[three]";
SECTION( "single [one] tag", "" ) {
Catch::TestCase oneTag = makeTestCase( NULL, "", "test", "[one]", CATCH_INTERNAL_LINEINFO );
CHECK( oneTag.getTestCaseInfo().description == "" );
CHECK( oneTag.hasTag( "one" ) );
CHECK( oneTag.getTags().size() == 1 );
CHECK( oneTag.matchesTags( p1 ) == true );
CHECK( oneTag.matchesTags( p2 ) == true );
CHECK( oneTag.matchesTags( p3 ) == false );
CHECK( oneTag.matchesTags( p4 ) == false );
CHECK( oneTag.matchesTags( p5 ) == false );
CHECK( oneTag.matchesTags( p6 ) == false );
}
SECTION( "single [two] tag", "" ) {
Catch::TestCase oneTag = makeTestCase( NULL, "", "test", "[two]", CATCH_INTERNAL_LINEINFO );
CHECK( oneTag.getTestCaseInfo().description == "" );
CHECK( oneTag.hasTag( "two" ) );
CHECK( oneTag.getTags().size() == 1 );
CHECK( oneTag.matchesTags( p1 ) == false );
CHECK( oneTag.matchesTags( p2 ) == true );
CHECK( oneTag.matchesTags( p3 ) == false );
CHECK( oneTag.matchesTags( p4 ) == false );
CHECK( oneTag.matchesTags( p5 ) == false );
CHECK( oneTag.matchesTags( p6 ) == false );
}
SECTION( "two tags", "" ) {
Catch::TestCase twoTags= makeTestCase( NULL, "", "test", "[one][two]", CATCH_INTERNAL_LINEINFO );
CHECK( twoTags.getTestCaseInfo().description == "" );
CHECK( twoTags.hasTag( "one" ) );
CHECK( twoTags.hasTag( "two" ) );
CHECK( twoTags.hasTag( "Two" ) );
CHECK( twoTags.hasTag( "three" ) == false );
CHECK( twoTags.getTags().size() == 2 );
CHECK( twoTags.matchesTags( p1 ) == true );
CHECK( twoTags.matchesTags( p2 ) == true );
CHECK( twoTags.matchesTags( p3 ) == true );
CHECK( twoTags.matchesTags( p4 ) == true );
CHECK( twoTags.matchesTags( p5 ) == true );
CHECK( twoTags.matchesTags( p6 ) == true );
}
SECTION( "complex", "" ) {
CHECK( fakeTestCase( "test", "[one][.]" ).matchesTags( p1 ) );
CHECK_FALSE( fakeTestCase( "test", "[one][.]" ).matchesTags( p5 ) );
CHECK( fakeTestCase( "test", "[three]" ).matchesTags( p4 ) );
CHECK( fakeTestCase( "test", "[three]" ).matchesTags( p5 ) );
CHECK( fakeTestCase( "test", "[three]" ).matchesTags( "[three]~[one]" ) );
CHECK( fakeTestCase( "test", "[three]" ).matchesTags( "[three]exclude:[one]" ) );
CHECK( fakeTestCase( "test", "[unit][not_apple]" ).matchesTags( "[unit]" ) );
CHECK_FALSE( fakeTestCase( "test", "[unit][not_apple]" ).matchesTags( "[unit]~[not_apple]" ) );
CHECK_FALSE( fakeTestCase( "test", "[unit][not_apple]" ).matchesTags( "[unit]exclude:[not_apple]" ) );
}
SECTION( "one tag with characters either side", "" ) {
Catch::TestCase oneTagWithExtras = makeTestCase( NULL, "", "test", "12[one]34", CATCH_INTERNAL_LINEINFO );
CHECK( oneTagWithExtras.getTestCaseInfo().description == "1234" );
CHECK( oneTagWithExtras.hasTag( "one" ) );
CHECK( oneTagWithExtras.hasTag( "two" ) == false );
CHECK( oneTagWithExtras.getTags().size() == 1 );
}
SECTION( "start of a tag, but not closed", "" ) {
Catch::TestCase oneTagOpen = makeTestCase( NULL, "", "test", "[one", CATCH_INTERNAL_LINEINFO );
CHECK( oneTagOpen.getTestCaseInfo().description == "[one" );
CHECK( oneTagOpen.hasTag( "one" ) == false );
CHECK( oneTagOpen.getTags().size() == 0 );
}
SECTION( "hidden", "" ) {
Catch::TestCase oneTag = makeTestCase( NULL, "", "test", "[.]", CATCH_INTERNAL_LINEINFO );
CHECK( oneTag.getTestCaseInfo().description == "" );
CHECK( oneTag.hasTag( "." ) );
CHECK( oneTag.isHidden() );
CHECK( oneTag.matchesTags( "~[.]" ) == false );
}
}
TEST_CASE( "Long strings can be wrapped", "[wrap]" ) {

View File

@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
2656C2211925E7330040DB02 /* catch_test_spec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2656C2201925E7330040DB02 /* catch_test_spec.cpp */; };
2656C2251925EC870040DB02 /* catch_tags.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2656C2241925EC870040DB02 /* catch_tags.cpp */; };
266B06B816F3A60A004ED264 /* VariadicMacrosTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266B06B616F3A60A004ED264 /* VariadicMacrosTests.cpp */; };
266ECD74170F3C620030D735 /* BDDTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266ECD73170F3C620030D735 /* BDDTests.cpp */; };
26847E5F16BBADB40043B9C1 /* catch_message.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26847E5D16BBADB40043B9C1 /* catch_message.cpp */; };
@@ -31,7 +33,6 @@
4A6D0C3D149B3D9E00DB3EAA /* MiscTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A6D0C34149B3D9E00DB3EAA /* MiscTests.cpp */; };
4A6D0C3E149B3D9E00DB3EAA /* TestMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A6D0C35149B3D9E00DB3EAA /* TestMain.cpp */; };
4A6D0C3F149B3D9E00DB3EAA /* TrickyTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A6D0C36149B3D9E00DB3EAA /* TrickyTests.cpp */; };
4A8E4DD2160A352200194CBD /* catch_tags.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A8E4DD0160A352200194CBD /* catch_tags.cpp */; };
4AB3D99D1616216500C9A0F8 /* catch_interfaces_testcase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AB3D99C1616216500C9A0F8 /* catch_interfaces_testcase.cpp */; };
4AB3D9A01616219100C9A0F8 /* catch_interfaces_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AB3D99F1616219100C9A0F8 /* catch_interfaces_config.cpp */; };
4AB3D9A2161621B500C9A0F8 /* catch_interfaces_generators.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AB3D9A1161621B500C9A0F8 /* catch_interfaces_generators.cpp */; };
@@ -57,7 +58,6 @@
/* Begin PBXFileReference section */
261488FA184C81130041FBEB /* catch_test_spec.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_test_spec.hpp; sourceTree = "<group>"; };
261488FB184C83EA0041FBEB /* catch_tags.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_tags.h; sourceTree = "<group>"; };
261488FC184D1DC10041FBEB /* catch_stream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_stream.h; sourceTree = "<group>"; };
261488FD184D21290041FBEB /* catch_section_info.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_section_info.h; sourceTree = "<group>"; };
261488FE184DC32F0041FBEB /* catch_section.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_section.h; sourceTree = "<group>"; };
@@ -67,6 +67,10 @@
263FD06017AF8DF200988A20 /* catch_timer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_timer.hpp; sourceTree = "<group>"; };
263FD06117AF8DF200988A20 /* catch_timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_timer.h; sourceTree = "<group>"; };
2656C21F1925E5100040DB02 /* catch_test_spec_parser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_test_spec_parser.hpp; sourceTree = "<group>"; };
2656C2201925E7330040DB02 /* catch_test_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_test_spec.cpp; path = ../../../SelfTest/SurrogateCpps/catch_test_spec.cpp; sourceTree = "<group>"; };
2656C2221925EC6F0040DB02 /* catch_tags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_tags.h; sourceTree = "<group>"; };
2656C2231925EC6F0040DB02 /* catch_tags.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_tags.hpp; sourceTree = "<group>"; };
2656C2241925EC870040DB02 /* catch_tags.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_tags.cpp; path = ../../../SelfTest/SurrogateCpps/catch_tags.cpp; sourceTree = "<group>"; };
266B06B616F3A60A004ED264 /* VariadicMacrosTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VariadicMacrosTests.cpp; path = ../../../SelfTest/VariadicMacrosTests.cpp; sourceTree = "<group>"; };
266ECD73170F3C620030D735 /* BDDTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BDDTests.cpp; path = ../../../SelfTest/BDDTests.cpp; sourceTree = "<group>"; };
266ECD8C1713614B0030D735 /* catch_legacy_reporter_adapter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_legacy_reporter_adapter.hpp; sourceTree = "<group>"; };
@@ -153,8 +157,6 @@
4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_xml.hpp; sourceTree = "<group>"; };
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = "<group>"; };
4A7DB2CD1652FE4B00FA6523 /* catch_version.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = catch_version.h; path = ../../../../include/internal/catch_version.h; sourceTree = "<group>"; };
4A8E4DCC160A344100194CBD /* catch_tags.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tags.hpp; sourceTree = "<group>"; };
4A8E4DD0160A352200194CBD /* catch_tags.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_tags.cpp; path = ../../../SelfTest/SurrogateCpps/catch_tags.cpp; sourceTree = "<group>"; };
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_generators.h; sourceTree = "<group>"; };
4A90B59D15D24FE900EF71BC /* catch_assertionresult.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_assertionresult.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
4A90B59E15D2521E00EF71BC /* catch_expressionresult_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_expressionresult_builder.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
@@ -303,7 +305,8 @@
4A8E4DCF160A34E200194CBD /* SurrogateCpps */ = {
isa = PBXGroup;
children = (
4A8E4DD0160A352200194CBD /* catch_tags.cpp */,
2656C2241925EC870040DB02 /* catch_tags.cpp */,
2656C2201925E7330040DB02 /* catch_test_spec.cpp */,
4AEE031F16142F910071E950 /* catch_common.cpp */,
4AEE032216142FC70071E950 /* catch_debugger.cpp */,
4AEE032416142FF10071E950 /* catch_stream.cpp */,
@@ -385,6 +388,8 @@
4AC91CBF155C381600DC5117 /* Test execution */ = {
isa = PBXGroup;
children = (
2656C2221925EC6F0040DB02 /* catch_tags.h */,
2656C2231925EC6F0040DB02 /* catch_tags.hpp */,
2656C21F1925E5100040DB02 /* catch_test_spec_parser.hpp */,
4A6D0C4A149B3E3D00DB3EAA /* catch_config.hpp */,
4A6D0C51149B3E3D00DB3EAA /* catch_context.h */,
@@ -392,9 +397,7 @@
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */,
4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */,
4A084F1D15DAD15F0027E631 /* catch_test_spec.h */,
4A8E4DCC160A344100194CBD /* catch_tags.hpp */,
26948287179EF7F900ED166E /* catch_test_case_tracker.hpp */,
261488FB184C83EA0041FBEB /* catch_tags.h */,
);
name = "Test execution";
sourceTree = "<group>";
@@ -518,14 +521,15 @@
4A6D0C3D149B3D9E00DB3EAA /* MiscTests.cpp in Sources */,
4A6D0C3E149B3D9E00DB3EAA /* TestMain.cpp in Sources */,
4A6D0C3F149B3D9E00DB3EAA /* TrickyTests.cpp in Sources */,
4A8E4DD2160A352200194CBD /* catch_tags.cpp in Sources */,
4AEE032016142F910071E950 /* catch_common.cpp in Sources */,
4AEE032316142FC70071E950 /* catch_debugger.cpp in Sources */,
2656C2251925EC870040DB02 /* catch_tags.cpp in Sources */,
4AEE032516142FF10071E950 /* catch_stream.cpp in Sources */,
4AEE0328161434FD0071E950 /* catch_xmlwriter.cpp in Sources */,
4A45DA2416161EF9004F8D6B /* catch_console_colour.cpp in Sources */,
4A45DA2716161F1F004F8D6B /* catch_ptr.cpp in Sources */,
26E1B7D319213BC900812682 /* CmdLineTests.cpp in Sources */,
2656C2211925E7330040DB02 /* catch_test_spec.cpp in Sources */,
4A45DA2916161F3D004F8D6B /* catch_streambuf.cpp in Sources */,
4A45DA2B16161F79004F8D6B /* catch_interfaces_registry_hub.cpp in Sources */,
4A45DA2D16161FA2004F8D6B /* catch_interfaces_capture.cpp in Sources */,