Ver código fonte

Convert to GoogleTest, expand explicitness of clauses.

Sam Jaffe 6 anos atrás
pai
commit
8bc423f709
3 arquivos alterados com 185 adições e 98 exclusões
  1. 22 0
      case-matcher-test/Info.plist
  2. 82 50
      case-matcher.xcodeproj/project.pbxproj
  3. 81 48
      test/match_test.cxx

+ 22 - 0
case-matcher-test/Info.plist

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>$(DEVELOPMENT_LANGUAGE)</string>
+	<key>CFBundleExecutable</key>
+	<string>$(EXECUTABLE_NAME)</string>
+	<key>CFBundleIdentifier</key>
+	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>$(PRODUCT_NAME)</string>
+	<key>CFBundlePackageType</key>
+	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+</dict>
+</plist>

+ 82 - 50
case-matcher.xcodeproj/project.pbxproj

@@ -6,6 +6,11 @@
 	objectVersion = 46;
 	objects = {
 
+/* Begin PBXBuildFile section */
+		CDEC1E6523522E100091D9F2 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDEC1DA02351663A0091D9F2 /* GoogleMock.framework */; };
+		CDEC1E6623522E140091D9F2 /* match_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDEC1E5623522DB20091D9F2 /* match_test.cxx */; };
+/* End PBXBuildFile section */
+
 /* Begin PBXContainerItemProxy section */
 		CDEC1D9F2351663A0091D9F2 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -37,30 +42,20 @@
 		};
 /* End PBXContainerItemProxy section */
 
-/* Begin PBXCopyFilesBuildPhase section */
-		CD7820201E44DAD1001D22E5 /* CopyFiles */ = {
-			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = /usr/share/man/man1/;
-			dstSubfolderSpec = 0;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 1;
-		};
-/* End PBXCopyFilesBuildPhase section */
-
 /* Begin PBXFileReference section */
-		CD7820221E44DAD1001D22E5 /* case_matcher_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = case_matcher_tc; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDEC1D982351663A0091D9F2 /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 		CDEC1E5623522DB20091D9F2 /* match_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = match_test.cxx; sourceTree = "<group>"; };
 		CDEC1E5723522DBF0091D9F2 /* match */ = {isa = PBXFileReference; lastKnownFileType = folder; name = match; path = include/match; sourceTree = "<group>"; };
+		CDEC1E5C23522DF10091D9F2 /* case-matcher-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "case-matcher-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
+		CDEC1E6023522DF10091D9F2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
-		CD78201F1E44DAD1001D22E5 /* Frameworks */ = {
+		CDEC1E5923522DF10091D9F2 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDEC1E6523522E100091D9F2 /* GoogleMock.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -73,14 +68,16 @@
 				CDEC1D982351663A0091D9F2 /* GoogleMock.xcodeproj */,
 				CDEC1E5723522DBF0091D9F2 /* match */,
 				CDEC1E5523522DB20091D9F2 /* test */,
+				CDEC1E5D23522DF10091D9F2 /* case-matcher-test */,
 				CD6E2CDD1D84BF3C002C1FB3 /* Products */,
+				CDEC1E6423522E100091D9F2 /* Frameworks */,
 			);
 			sourceTree = "<group>";
 		};
 		CD6E2CDD1D84BF3C002C1FB3 /* Products */ = {
 			isa = PBXGroup;
 			children = (
-				CD7820221E44DAD1001D22E5 /* case_matcher_tc */,
+				CDEC1E5C23522DF10091D9F2 /* case-matcher-test.xctest */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -104,26 +101,40 @@
 			path = test;
 			sourceTree = "<group>";
 		};
+		CDEC1E5D23522DF10091D9F2 /* case-matcher-test */ = {
+			isa = PBXGroup;
+			children = (
+				CDEC1E6023522DF10091D9F2 /* Info.plist */,
+			);
+			path = "case-matcher-test";
+			sourceTree = "<group>";
+		};
+		CDEC1E6423522E100091D9F2 /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
-		CD7820211E44DAD1001D22E5 /* case_matcher_tc */ = {
+		CDEC1E5B23522DF10091D9F2 /* case-matcher-test */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = CD7820261E44DAD1001D22E5 /* Build configuration list for PBXNativeTarget "case_matcher_tc" */;
+			buildConfigurationList = CDEC1E6123522DF10091D9F2 /* Build configuration list for PBXNativeTarget "case-matcher-test" */;
 			buildPhases = (
-				CD78202C1E44DB3B001D22E5 /* ShellScript */,
-				CD78201E1E44DAD1001D22E5 /* Sources */,
-				CD78201F1E44DAD1001D22E5 /* Frameworks */,
-				CD7820201E44DAD1001D22E5 /* CopyFiles */,
+				CDEC1E5823522DF10091D9F2 /* Sources */,
+				CDEC1E5923522DF10091D9F2 /* Frameworks */,
+				CDEC1E5A23522DF10091D9F2 /* Resources */,
 			);
 			buildRules = (
 			);
 			dependencies = (
 			);
-			name = case_matcher_tc;
-			productName = case_matcher_tc;
-			productReference = CD7820221E44DAD1001D22E5 /* case_matcher_tc */;
-			productType = "com.apple.product-type.tool";
+			name = "case-matcher-test";
+			productName = "case-matcher-test";
+			productReference = CDEC1E5C23522DF10091D9F2 /* case-matcher-test.xctest */;
+			productType = "com.apple.product-type.bundle.unit-test";
 		};
 /* End PBXNativeTarget section */
 
@@ -134,8 +145,9 @@
 				LastUpgradeCheck = 1110;
 				ORGANIZATIONNAME = "Sam Jaffe";
 				TargetAttributes = {
-					CD7820211E44DAD1001D22E5 = {
-						CreatedOnToolsVersion = 7.2.1;
+					CDEC1E5B23522DF10091D9F2 = {
+						CreatedOnToolsVersion = 11.1;
+						ProvisioningStyle = Automatic;
 					};
 				};
 			};
@@ -158,7 +170,7 @@
 			);
 			projectRoot = "";
 			targets = (
-				CD7820211E44DAD1001D22E5 /* case_matcher_tc */,
+				CDEC1E5B23522DF10091D9F2 /* case-matcher-test */,
 			);
 		};
 /* End PBXProject section */
@@ -194,29 +206,22 @@
 		};
 /* End PBXReferenceProxy section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		CD78202C1E44DB3B001D22E5 /* ShellScript */ = {
-			isa = PBXShellScriptBuildPhase;
+/* Begin PBXResourcesBuildPhase section */
+		CDEC1E5A23522DF10091D9F2 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
-			inputPaths = (
-				"$(SRCROOT)/match.t.h",
-			);
-			outputPaths = (
-				"$(SRCROOT)/case_matcher_tc.cpp",
-			);
 			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "cxxtestgen --error-printer -o case_matcher_tc.cpp match.t.h";
 		};
-/* End PBXShellScriptBuildPhase section */
+/* End PBXResourcesBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
-		CD78201E1E44DAD1001D22E5 /* Sources */ = {
+		CDEC1E5823522DF10091D9F2 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDEC1E6623522E140091D9F2 /* match_test.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -274,6 +279,7 @@
 				MTL_ENABLE_DEBUG_INFO = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
+				USER_HEADER_SEARCH_PATHS = ./include/;
 			};
 			name = Debug;
 		};
@@ -321,23 +327,49 @@
 				MACOSX_DEPLOYMENT_TARGET = 10.10;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = macosx;
+				USER_HEADER_SEARCH_PATHS = ./include/;
 			};
 			name = Release;
 		};
-		CD7820271E44DAD1001D22E5 /* Debug */ = {
+		CDEC1E6223522DF10091D9F2 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				CODE_SIGN_IDENTITY = "-";
-				HEADER_SEARCH_PATHS = /usr/local/include/;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				COMBINE_HIDPI_IMAGES = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				INFOPLIST_FILE = "case-matcher-test/Info.plist";
+				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+				MACOSX_DEPLOYMENT_TARGET = 10.14;
+				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+				MTL_FAST_MATH = YES;
+				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.case-matcher-test";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
 		};
-		CD7820281E44DAD1001D22E5 /* Release */ = {
+		CDEC1E6323522DF10091D9F2 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				CODE_SIGN_IDENTITY = "-";
-				HEADER_SEARCH_PATHS = /usr/local/include/;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CODE_SIGN_STYLE = Automatic;
+				COMBINE_HIDPI_IMAGES = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				INFOPLIST_FILE = "case-matcher-test/Info.plist";
+				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+				MACOSX_DEPLOYMENT_TARGET = 10.14;
+				MTL_FAST_MATH = YES;
+				PRODUCT_BUNDLE_IDENTIFIER = "leumasjaffe.case-matcher-test";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;
@@ -354,11 +386,11 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		CD7820261E44DAD1001D22E5 /* Build configuration list for PBXNativeTarget "case_matcher_tc" */ = {
+		CDEC1E6123522DF10091D9F2 /* Build configuration list for PBXNativeTarget "case-matcher-test" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				CD7820271E44DAD1001D22E5 /* Debug */,
-				CD7820281E44DAD1001D22E5 /* Release */,
+				CDEC1E6223522DF10091D9F2 /* Debug */,
+				CDEC1E6323522DF10091D9F2 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;

+ 81 - 48
test/match_test.cxx

@@ -5,11 +5,9 @@
 //  Created by Sam Jaffe on 2/3/17.
 //
 
-#pragma once
+#include <gmock/gmock.h>
 
-#include "match.hpp"
-
-#include <cxxtest/TestSuite.h>
+#include "match/match.hpp"
 
 struct example {
   example(long in) : i(in) {}
@@ -20,64 +18,99 @@ bool operator==(example const & a, example const & b) {
   return a.i == b.i;
 }
 
-class case_matcher_TestSuite : public CxxTest::TestSuite {
-public:
+struct CaseMatcherTest : public testing::Test {
   example const ex{1};
   bool const b{true};
-public:
-  void test_match_explicit_case() {
-    match(ex, b) {
-      with(example{1}, true) {}
-      nomatch() { TS_FAIL("Unable to match"); }
-      TS_ASSERT( ! _matcher_local.unmatched() );
+};
+
+using ::testing::Eq;
+
+TEST_F(CaseMatcherTest, MatchesCorrectValue) {
+  match(ex, b) {
+    with(example{1}, true) {
+      EXPECT_FALSE(_matcher_local.unmatched());
+    } nomatch() {
+      FAIL() << "Unable to match";
     }
+    EXPECT_FALSE(_matcher_local.unmatched());
+  } else {
+    FAIL() << "Unable to construct matcher";
   }
-  
-  void test_nomatch_incorrect_case() {
-    match(ex, b) {
-      with(example{1}, false) { TS_FAIL("Incorrect match!"); }
-      TS_ASSERT( _matcher_local.unmatched() );
+}
+
+TEST_F(CaseMatcherTest, NonMatchingClauseLeavesUnmatched) {
+  match(ex, b) {
+    with(example{1}, false) {
+      FAIL() << "Incorrect match!";
     }
+    EXPECT_TRUE(_matcher_local.unmatched());
+  } else {
+     FAIL() << "Unable to construct matcher";
   }
-  
-  void test_match_fallback_case() {
-    match(ex, b) {
-      with(example{1}, false) { TS_FAIL("Incorrect match!"); }
-      with(example{1}, true) {}
-      TS_ASSERT( !_matcher_local.unmatched() );
+}
+
+TEST_F(CaseMatcherTest, CanPassMatchingWithSecondClauseListing) {
+  match(ex, b) {
+    with(example{1}, false) {
+      FAIL() << "Incorrect match!";
     }
+    EXPECT_TRUE(_matcher_local.unmatched());
+    with(example{1}, true) {
+      EXPECT_FALSE(_matcher_local.unmatched());
+    }
+    EXPECT_FALSE(_matcher_local.unmatched());
+  } else {
+     FAIL() << "Unable to construct matcher";
   }
-  
-  void test_match_any_case() {
-    match(ex, b) {
-      with(example{1}, false) { TS_FAIL("Incorrect match!"); }
-      with(matcher::any, true) {}
-      TS_ASSERT( !_matcher_local.unmatched() );
+}
+
+TEST_F(CaseMatcherTest, CanMatchWithWildcard) {
+  match(ex, b) {
+    with(example{1}, false) {
+      FAIL() << "Incorrect match!";
+    }
+    with(matcher::any, true) {
+      EXPECT_FALSE(_matcher_local.unmatched());
     }
+    EXPECT_FALSE(_matcher_local.unmatched());
+  } else {
+      FAIL() << "Unable to construct matcher";
   }
-  
-  void test_match_multiple_cases() {
-    int hits{0};
-    match(ex, b) {
-      with(matcher::any, true) { ++hits; }
-      and_with(example{1}, matcher::any) { ++hits; }
+}
+
+TEST_F(CaseMatcherTest, CanMatchMultipleUnlinkedClauses) {
+  int hits{0};
+  match(ex, b) {
+    with(matcher::any, true) {
+      ++hits;
+    }
+    and_with(example{1}, matcher::any) {
+      ++hits;
     }
-    TS_ASSERT_EQUALS(hits, 2);
+  } else {
+     FAIL() << "Unable to construct matcher";
   }
-  
-  void test_match_any_of_list() {
-    match(ex, b) {
-      with(matcher::any_of(example{1}, example{0xDEADBEEF}), true) {}
-      nomatch() { TS_FAIL("Unable to match with choice"); }
+  EXPECT_THAT(hits, Eq(2));
+}
+
+TEST_F(CaseMatcherTest, CanMatchCompoundList) {
+  match(ex, b) {
+    with(matcher::any_of(example{1}, example{0xDEADBEEF}), true) {
+    } nomatch() {
+      FAIL() << "Unable to match with choice";
     }
+  } else {
+      FAIL() << "Unable to construct matcher";
   }
+}
 
-  void test_nomatch_any_of_list_without_self() {
-    match(ex, b) {
-      with(matcher::any_of(example{0}, example{0xDEADBEEF}), true) {
-        TS_FAIL("Incorrect match!");
-      }
-      TS_ASSERT( _matcher_local.unmatched() );
+TEST_F(CaseMatcherTest, nomatch_any_of_list_without_self) {
+  match(ex, b) {
+    with(matcher::any_of(example{0}, example{0xDEADBEEF}), true) {
+       FAIL() << "Incorrect match!";
     }
+    EXPECT_TRUE(_matcher_local.unmatched());
+  } else {
+      FAIL() << "Unable to construct matcher";
   }
-};
+}