瀏覽代碼

Switch to GoogleTest.
Fix a bug in C++14 return_ensures.
Cleanup printing messages

Sam Jaffe 6 年之前
父節點
當前提交
23ff3c944e
共有 6 個文件被更改,包括 292 次插入274 次删除
  1. 22 0
      expect-test/Info.plist
  2. 161 53
      expect.xcodeproj/project.pbxproj
  3. 8 6
      include/expect/expect.hpp
  4. 0 111
      test/expect.t.h
  5. 0 104
      test/expect_tc.cpp
  6. 101 0
      test/expect_test.cxx

+ 22 - 0
expect-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>

+ 161 - 53
expect.xcodeproj/project.pbxproj

@@ -7,33 +7,55 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		CD3A75F51E2597A8008C6DC2 /* expect_tc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3A75F31E2597A8008C6DC2 /* expect_tc.cpp */; };
+		CDEC1E92235248410091D9F2 /* expect_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD3A75E51E2596B9008C6DC2 /* expect_test.cxx */; };
+		CDEC1E94235248470091D9F2 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDEC1DAF2351673C0091D9F2 /* GoogleMock.framework */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXCopyFilesBuildPhase section */
-		CD3A75E91E259748008C6DC2 /* CopyFiles */ = {
-			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = /usr/share/man/man1/;
-			dstSubfolderSpec = 0;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 1;
+/* Begin PBXContainerItemProxy section */
+		CDEC1DAE2351673C0091D9F2 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = 05818F861A685AEA0072A469;
+			remoteInfo = GoogleMock;
+		};
+		CDEC1DB02351673C0091D9F2 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = 05E96ABD1A68600C00204102;
+			remoteInfo = gmock;
 		};
-/* End PBXCopyFilesBuildPhase section */
+		CDEC1DB22351673C0091D9F2 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = 05E96B1F1A68634900204102;
+			remoteInfo = gtest;
+		};
+		CDEC1DB42351673C0091D9F2 /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = 05818F901A685AEA0072A469;
+			remoteInfo = GoogleMockTests;
+		};
+/* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
-		CD3A75E51E2596B9008C6DC2 /* expect.t.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = expect.t.h; sourceTree = "<group>"; };
-		CD3A75EB1E259748008C6DC2 /* expect_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = expect_tc; sourceTree = BUILT_PRODUCTS_DIR; };
-		CD3A75F31E2597A8008C6DC2 /* expect_tc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = expect_tc.cpp; sourceTree = "<group>"; };
+		CD3A75E51E2596B9008C6DC2 /* expect_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = expect_test.cxx; sourceTree = "<group>"; };
 		CDAA170221A3A8AB007BBA11 /* expect */ = {isa = PBXFileReference; lastKnownFileType = folder; name = expect; path = include/expect; sourceTree = "<group>"; };
+		CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
+		CDEC1E8A235248390091D9F2 /* expect-test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "expect-test.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
+		CDEC1E8E235248390091D9F2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
-		CD3A75E81E259748008C6DC2 /* Frameworks */ = {
+		CDEC1E87235248390091D9F2 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDEC1E94235248470091D9F2 /* GoogleMock.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -43,16 +65,19 @@
 		CD2973BB1D7B67EF00E37217 = {
 			isa = PBXGroup;
 			children = (
+				CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */,
 				CDAA170221A3A8AB007BBA11 /* expect */,
 				CD3A75F61E25B2FB008C6DC2 /* test */,
+				CDEC1E8B235248390091D9F2 /* expect-test */,
 				CD2973C51D7B67EF00E37217 /* Products */,
+				CDEC1E93235248470091D9F2 /* Frameworks */,
 			);
 			sourceTree = "<group>";
 		};
 		CD2973C51D7B67EF00E37217 /* Products */ = {
 			isa = PBXGroup;
 			children = (
-				CD3A75EB1E259748008C6DC2 /* expect_tc */,
+				CDEC1E8A235248390091D9F2 /* expect-test.xctest */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -60,32 +85,56 @@
 		CD3A75F61E25B2FB008C6DC2 /* test */ = {
 			isa = PBXGroup;
 			children = (
-				CD3A75E51E2596B9008C6DC2 /* expect.t.h */,
-				CD3A75F31E2597A8008C6DC2 /* expect_tc.cpp */,
+				CD3A75E51E2596B9008C6DC2 /* expect_test.cxx */,
 			);
 			path = test;
 			sourceTree = "<group>";
 		};
+		CDEC1DA82351673C0091D9F2 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				CDEC1DAF2351673C0091D9F2 /* GoogleMock.framework */,
+				CDEC1DB12351673C0091D9F2 /* gmock.framework */,
+				CDEC1DB32351673C0091D9F2 /* gtest.framework */,
+				CDEC1DB52351673C0091D9F2 /* GoogleMockTests.xctest */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		CDEC1E8B235248390091D9F2 /* expect-test */ = {
+			isa = PBXGroup;
+			children = (
+				CDEC1E8E235248390091D9F2 /* Info.plist */,
+			);
+			path = "expect-test";
+			sourceTree = "<group>";
+		};
+		CDEC1E93235248470091D9F2 /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
-		CD3A75EA1E259748008C6DC2 /* expect_tc */ = {
+		CDEC1E89235248390091D9F2 /* expect-test */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = CD3A75EF1E259748008C6DC2 /* Build configuration list for PBXNativeTarget "expect_tc" */;
+			buildConfigurationList = CDEC1E8F235248390091D9F2 /* Build configuration list for PBXNativeTarget "expect-test" */;
 			buildPhases = (
-				CD3A75F21E259771008C6DC2 /* ShellScript */,
-				CD3A75E71E259748008C6DC2 /* Sources */,
-				CD3A75E81E259748008C6DC2 /* Frameworks */,
-				CD3A75E91E259748008C6DC2 /* CopyFiles */,
+				CDEC1E86235248390091D9F2 /* Sources */,
+				CDEC1E87235248390091D9F2 /* Frameworks */,
+				CDEC1E88235248390091D9F2 /* Resources */,
 			);
 			buildRules = (
 			);
 			dependencies = (
 			);
-			name = expect_tc;
-			productName = expect_tc;
-			productReference = CD3A75EB1E259748008C6DC2 /* expect_tc */;
-			productType = "com.apple.product-type.tool";
+			name = "expect-test";
+			productName = "expect-test";
+			productReference = CDEC1E8A235248390091D9F2 /* expect-test.xctest */;
+			productType = "com.apple.product-type.bundle.unit-test";
 		};
 /* End PBXNativeTarget section */
 
@@ -93,11 +142,12 @@
 		CD2973BC1D7B67EF00E37217 /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 1030;
+				LastUpgradeCheck = 1110;
 				ORGANIZATIONNAME = "Sam Jaffe";
 				TargetAttributes = {
-					CD3A75EA1E259748008C6DC2 = {
-						CreatedOnToolsVersion = 7.2.1;
+					CDEC1E89235248390091D9F2 = {
+						CreatedOnToolsVersion = 11.1;
+						ProvisioningStyle = Automatic;
 					};
 				};
 			};
@@ -112,37 +162,66 @@
 			mainGroup = CD2973BB1D7B67EF00E37217;
 			productRefGroup = CD2973C51D7B67EF00E37217 /* Products */;
 			projectDirPath = "";
+			projectReferences = (
+				{
+					ProductGroup = CDEC1DA82351673C0091D9F2 /* Products */;
+					ProjectRef = CDEC1DA72351673C0091D9F2 /* GoogleMock.xcodeproj */;
+				},
+			);
 			projectRoot = "";
 			targets = (
-				CD3A75EA1E259748008C6DC2 /* expect_tc */,
+				CDEC1E89235248390091D9F2 /* expect-test */,
 			);
 		};
 /* End PBXProject section */
 
-/* Begin PBXShellScriptBuildPhase section */
-		CD3A75F21E259771008C6DC2 /* ShellScript */ = {
-			isa = PBXShellScriptBuildPhase;
+/* Begin PBXReferenceProxy section */
+		CDEC1DAF2351673C0091D9F2 /* GoogleMock.framework */ = {
+			isa = PBXReferenceProxy;
+			fileType = wrapper.framework;
+			path = GoogleMock.framework;
+			remoteRef = CDEC1DAE2351673C0091D9F2 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+		CDEC1DB12351673C0091D9F2 /* gmock.framework */ = {
+			isa = PBXReferenceProxy;
+			fileType = wrapper.framework;
+			path = gmock.framework;
+			remoteRef = CDEC1DB02351673C0091D9F2 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+		CDEC1DB32351673C0091D9F2 /* gtest.framework */ = {
+			isa = PBXReferenceProxy;
+			fileType = wrapper.framework;
+			path = gtest.framework;
+			remoteRef = CDEC1DB22351673C0091D9F2 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+		CDEC1DB52351673C0091D9F2 /* GoogleMockTests.xctest */ = {
+			isa = PBXReferenceProxy;
+			fileType = wrapper.cfbundle;
+			path = GoogleMockTests.xctest;
+			remoteRef = CDEC1DB42351673C0091D9F2 /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+/* End PBXReferenceProxy section */
+
+/* Begin PBXResourcesBuildPhase section */
+		CDEC1E88235248390091D9F2 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
-			inputPaths = (
-				"$(SRCROOT)/expect.t.h",
-			);
-			outputPaths = (
-				"$(SRCROOT)/expect_tc.cpp",
-			);
 			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /bin/sh;
-			shellScript = "cd test\ncxxtestgen --error-printer -o expect_tc.cpp expect.t.h\n";
 		};
-/* End PBXShellScriptBuildPhase section */
+/* End PBXResourcesBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
-		CD3A75E71E259748008C6DC2 /* Sources */ = {
+		CDEC1E86235248390091D9F2 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				CD3A75F51E2597A8008C6DC2 /* expect_tc.cpp in Sources */,
+				CDEC1E92235248410091D9F2 /* expect_test.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -200,6 +279,7 @@
 				MTL_ENABLE_DEBUG_INFO = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
+				USER_HEADER_SEARCH_PATHS = ./include/;
 			};
 			name = Debug;
 		};
@@ -247,21 +327,49 @@
 				MACOSX_DEPLOYMENT_TARGET = 10.10;
 				MTL_ENABLE_DEBUG_INFO = NO;
 				SDKROOT = macosx;
+				USER_HEADER_SEARCH_PATHS = ./include/;
 			};
 			name = Release;
 		};
-		CD3A75F01E259748008C6DC2 /* Debug */ = {
+		CDEC1E90235248390091D9F2 /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				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 = "expect-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.expect-test";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Debug;
 		};
-		CD3A75F11E259748008C6DC2 /* Release */ = {
+		CDEC1E91235248390091D9F2 /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				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 = "expect-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.expect-test";
 				PRODUCT_NAME = "$(TARGET_NAME)";
 			};
 			name = Release;
@@ -278,11 +386,11 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		CD3A75EF1E259748008C6DC2 /* Build configuration list for PBXNativeTarget "expect_tc" */ = {
+		CDEC1E8F235248390091D9F2 /* Build configuration list for PBXNativeTarget "expect-test" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				CD3A75F01E259748008C6DC2 /* Debug */,
-				CD3A75F11E259748008C6DC2 /* Release */,
+				CDEC1E90235248390091D9F2 /* Debug */,
+				CDEC1E91235248390091D9F2 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;

+ 8 - 6
include/expect/expect.hpp

@@ -63,11 +63,13 @@ namespace contract {
 # define FUNCTION "???"
 #endif
 
+#define LOCATION_MSG ". in " FUNCTION "(" __FILE__ ":" STRING( __LINE__ ) ")"
+
 #define DEF_MSG( header, expr ) \
-  header " failed: " STRING(expr) ". in " FUNCTION "(" __FILE__ ":" STRING( __LINE__ ) ")"
+  header " failed: " STRING(expr) LOCATION_MSG
 
 #define SUB_MSG( header, bool_expr, rval_expr ) \
-  header " failed: " STRING(bool_expr) " [ with _ = " STRING(rval_expr) " ]. in " FUNCTION "(" __FILE__ ":" STRING( __LINE__ ) ")"
+  header " failed: " STRING(bool_expr) " [ with _ = " STRING(rval_expr) " ]" LOCATION_MSG
 
 /*
  * Usage: 
@@ -138,10 +140,10 @@ namespace contract {
 #else
 #define return_ensures( expr, cond, ... ) \
   [ _ = expr ]( ) { \
-    contract::_contract_impl<EXCEPT_T(__VA_ARGS__, std::runtime_error)>( \
-        FIRST(__VA_ARGS__), \
-        EXCEPT_MSG(__VA_ARGS__, \
-                   SUB_MSG("postcondition", FIRST(__VA_ARGS__), expr))); \
+    contract::_contract_impl<EXCEPT_T(-, ##__VA_ARGS__, std::runtime_error)>( \
+        cond, \
+        EXCEPT_MSG(cond, ##__VA_ARGS__, \
+                   SUB_MSG("postcondition", cond, expr))); \
     return _; \
   }( )
 #endif

+ 0 - 111
test/expect.t.h

@@ -1,111 +0,0 @@
-//
-//  expect.t.h
-//  expect
-//
-//  Created by Sam Jaffe on 1/10/17.
-//
-
-#pragma once
-
-#include <cxxtest/TestSuite.h>
-
-#include "expect.hpp"
-
-struct my_error : public std::logic_error {
-  using std::logic_error::logic_error;
-};
-
-class expect_TestSuite : public CxxTest::TestSuite {
-public:
-  void test_expect_simple( ) const {
-    int i = 1;
-    expects( i == 1 );
-  }
-  
-  void test_expect_fails( ) const {
-    int i = 1;
-    TS_ASSERT_THROWS( expects( i == 2 ), std::logic_error );
-  }
-  
-  void test_expect_fails_with_error_type( ) const {
-    int i = 1;
-    TS_ASSERT_THROWS( (expects( i == 2, my_error, "error" )), my_error );
-  }
-  
-  void test_expect_fails_with_error_message( ) const {
-    int i = 1;
-    try {
-      expects( i == 2 );
-      TS_FAIL( "expected exception" );
-    } catch ( std::exception const & e ) {
-      std::string emsg = e.what();
-      emsg = emsg.substr( 0, emsg.find(".") );
-      TS_ASSERT_EQUALS( emsg, "precondition failed: i == 2" );
-    }
-  }
-  
-  void test_expect_fails_with_custom_error_message( ) const {
-    int i = 1;
-    try {
-      expects( i == 2, "example error message" );
-      TS_FAIL( "expected exception" );
-    } catch ( std::exception const & e ) {
-      TS_ASSERT_EQUALS( e.what(), "example error message" );
-    }
-  }
-  
-  void test_expect_graceful( ) const {
-    int i = 1;
-    expects_graceful( i == 2 );
-    TS_FAIL( "expected return" );
-  }
-  
-  int impl_expect_graceful_rval( ) const {
-    int i = 1;
-    expects_graceful( i == 2, 7 );
-    return 1;
-  }
-  
-  void test_expect_graceful_rval( ) const {
-    TS_ASSERT_EQUALS( impl_expect_graceful_rval(), 7 );
-  }
-  
-  void test_return_ensure( ) const {
-    int i = 6;
-    TS_ASSERT_EQUALS( return_ensures( i + 1, _ > 5 ), 7 );
-  }
-
-  void test_return_ensure_throws( ) const {
-    TS_ASSERT_THROWS( return_ensures( 7, _ < 5 ), std::runtime_error );
-  }
-  
-  int impl_return_ensure_throws_message( ) const {
-    int i = 6;
-    return return_ensures( i + 1, _ < 5 );
-  }
-
-  void test_return_ensure_throws_message( ) const {
-    try {
-      (void) impl_return_ensure_throws_message();
-      TS_FAIL( "expected exception" );
-    } catch ( std::exception const & e ) {
-      std::string emsg = e.what();
-      emsg = emsg.substr( 0, emsg.find("].") + 1 );
-      TS_ASSERT_EQUALS( emsg, "postcondition failed: _ < 5 [ with _ = i + 1 ]")
-    }
-  }
-  
-  void test_return_ensure_throws_custom_message( ) const {
-    try {
-      (void) return_ensures( 7, _ < 5, "example error message" );
-      TS_FAIL( "expected exception" );
-    } catch ( std::exception const & e ) {
-      TS_ASSERT_EQUALS( e.what(), "example error message")
-    }
-  }
-  
-  void test_return_ensure_throws_custom( ) const {
-    TS_ASSERT_THROWS( return_ensures( 7, _ < 5, my_error, "error" ), my_error );
-  }
-
-};

+ 0 - 104
test/expect_tc.cpp

@@ -1,104 +0,0 @@
-/* Generated file, do not edit */
-
-#ifndef CXXTEST_RUNNING
-#define CXXTEST_RUNNING
-#endif
-
-#define _CXXTEST_HAVE_STD
-#define _CXXTEST_HAVE_EH
-#include <cxxtest/TestListener.h>
-#include <cxxtest/TestTracker.h>
-#include <cxxtest/TestRunner.h>
-#include <cxxtest/RealDescriptions.h>
-#include <cxxtest/TestMain.h>
-#include <cxxtest/ErrorPrinter.h>
-
-int main( int argc, char *argv[] ) {
- int status;
-    CxxTest::ErrorPrinter tmp;
-    CxxTest::RealWorldDescription::_worldName = "cxxtest";
-    status = CxxTest::Main< CxxTest::ErrorPrinter >( tmp, argc, argv );
-    return status;
-}
-bool suite_expect_TestSuite_init = false;
-#include "expect.t.h"
-
-static expect_TestSuite suite_expect_TestSuite;
-
-static CxxTest::List Tests_expect_TestSuite = { 0, 0 };
-CxxTest::StaticSuiteDescription suiteDescription_expect_TestSuite( "expect.t.h", 18, "expect_TestSuite", suite_expect_TestSuite, Tests_expect_TestSuite );
-
-static class TestDescription_suite_expect_TestSuite_test_expect_simple : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_simple() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 20, "test_expect_simple" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_simple(); }
-} testDescription_suite_expect_TestSuite_test_expect_simple;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_fails : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_fails() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 25, "test_expect_fails" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_fails(); }
-} testDescription_suite_expect_TestSuite_test_expect_fails;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_fails_with_error_type : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_fails_with_error_type() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 30, "test_expect_fails_with_error_type" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_fails_with_error_type(); }
-} testDescription_suite_expect_TestSuite_test_expect_fails_with_error_type;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_fails_with_error_message : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_fails_with_error_message() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 35, "test_expect_fails_with_error_message" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_fails_with_error_message(); }
-} testDescription_suite_expect_TestSuite_test_expect_fails_with_error_message;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_fails_with_custom_error_message : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_fails_with_custom_error_message() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 47, "test_expect_fails_with_custom_error_message" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_fails_with_custom_error_message(); }
-} testDescription_suite_expect_TestSuite_test_expect_fails_with_custom_error_message;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_graceful : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_graceful() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 57, "test_expect_graceful" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_graceful(); }
-} testDescription_suite_expect_TestSuite_test_expect_graceful;
-
-static class TestDescription_suite_expect_TestSuite_test_expect_graceful_rval : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_expect_graceful_rval() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 69, "test_expect_graceful_rval" ) {}
- void runTest() { suite_expect_TestSuite.test_expect_graceful_rval(); }
-} testDescription_suite_expect_TestSuite_test_expect_graceful_rval;
-
-static class TestDescription_suite_expect_TestSuite_test_return_ensure : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_return_ensure() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 73, "test_return_ensure" ) {}
- void runTest() { suite_expect_TestSuite.test_return_ensure(); }
-} testDescription_suite_expect_TestSuite_test_return_ensure;
-
-static class TestDescription_suite_expect_TestSuite_test_return_ensure_throws : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_return_ensure_throws() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 78, "test_return_ensure_throws" ) {}
- void runTest() { suite_expect_TestSuite.test_return_ensure_throws(); }
-} testDescription_suite_expect_TestSuite_test_return_ensure_throws;
-
-static class TestDescription_suite_expect_TestSuite_test_return_ensure_throws_message : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_return_ensure_throws_message() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 87, "test_return_ensure_throws_message" ) {}
- void runTest() { suite_expect_TestSuite.test_return_ensure_throws_message(); }
-} testDescription_suite_expect_TestSuite_test_return_ensure_throws_message;
-
-static class TestDescription_suite_expect_TestSuite_test_return_ensure_throws_custom_message : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_return_ensure_throws_custom_message() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 98, "test_return_ensure_throws_custom_message" ) {}
- void runTest() { suite_expect_TestSuite.test_return_ensure_throws_custom_message(); }
-} testDescription_suite_expect_TestSuite_test_return_ensure_throws_custom_message;
-
-static class TestDescription_suite_expect_TestSuite_test_return_ensure_throws_custom : public CxxTest::RealTestDescription {
-public:
- TestDescription_suite_expect_TestSuite_test_return_ensure_throws_custom() : CxxTest::RealTestDescription( Tests_expect_TestSuite, suiteDescription_expect_TestSuite, 107, "test_return_ensure_throws_custom" ) {}
- void runTest() { suite_expect_TestSuite.test_return_ensure_throws_custom(); }
-} testDescription_suite_expect_TestSuite_test_return_ensure_throws_custom;
-
-#include <cxxtest/Root.cpp>
-const char* CxxTest::RealWorldDescription::_worldName = "cxxtest";

+ 101 - 0
test/expect_test.cxx

@@ -0,0 +1,101 @@
+//
+//  expect.t.h
+//  expect
+//
+//  Created by Sam Jaffe on 1/10/17.
+//
+
+#include <gmock/gmock.h>
+
+#include "expect/expect.hpp"
+
+struct my_error : public std::logic_error {
+  using std::logic_error::logic_error;
+};
+
+using ::testing::Eq;
+using ::testing::HasSubstr;
+using ::testing::StrEq;
+
+TEST(ExpectTest, ExpectTrueIsSafe) {
+  int i = 1;
+  EXPECT_NO_THROW(expects(i == 1));
+}
+
+TEST(ExpectTest, ExpectFalseThrows) {
+  int i = 1;
+  EXPECT_THROW(expects(i == 2), std::logic_error);
+}
+
+TEST(ExpectTest, CanProvideCustomErrorType) {
+  int i = 1;
+  EXPECT_THROW((expects(i == 2, my_error, "error")), my_error);
+}
+
+TEST(ExpectTest, FailsWithErrorMessageContainingExpr) {
+  int i = 1;
+  try {
+    expects(i == 2);
+    FAIL() << "expected exception";
+  } catch (std::exception const & e) {
+    EXPECT_THAT(e.what(), HasSubstr("i == 2"));
+  }
+}
+
+TEST(ExpectTest, CanProvideCustomErrorMessage) {
+  int i = 1;
+  try {
+    expects(i == 2, "example error message");
+    FAIL() << "expected exception";
+  } catch (std::exception const & e) {
+    EXPECT_THAT(e.what(), StrEq("example error message"));
+  }
+}
+
+TEST(ExpectGracefulTest, ReturnsEarly) {
+  int i = 1;
+  expects_graceful(i == 2);
+  FAIL() << "expected return";
+}
+
+TEST(ExpectGracefulTest, ReturnValueCanBeControlled) {
+  auto get_gracefully = [](bool no) {
+    expects_graceful(no, 7);
+    return 1;
+  };
+  EXPECT_THAT(get_gracefully(true), Eq(1));
+  EXPECT_THAT(get_gracefully(false), Eq(7));
+}
+
+TEST(ReturnEnsureTest, ReturnsFirstExprIfPassesLambda) {
+  int i = 6;
+  EXPECT_THAT(return_ensures(i + 1, _ > 5), Eq(7));
+}
+
+TEST(ReturnEnsureTest, ThrowsWhenFailingLambda) {
+  EXPECT_THROW(return_ensures(7, _ < 5), std::runtime_error);
+}
+
+TEST(ReturnEnsureTest, FailsWithErrorMessageContainingExprAndLambda) {
+  try {
+    int i = 6;
+    (void) return_ensures(i + 1, _ < 5);
+    FAIL() << "expected exception";
+  } catch (std::exception const & e) {
+    EXPECT_THAT(e.what(), HasSubstr("_ < 5"));
+    EXPECT_THAT(e.what(), HasSubstr("i + 1"));
+  }
+}
+
+TEST(ReturnEnsureTest, CanProvideCustomErrorMessage) {
+  try {
+    (void) return_ensures(7, _ < 5, "example error message");
+    FAIL() << "expected exception";
+  } catch (std::exception const & e) {
+    EXPECT_THAT(e.what(), StrEq("example error message"));
+  }
+}
+
+TEST(ReturnEnsureTest, CanProvideCustomErrorType) {
+  EXPECT_THROW(return_ensures(7, _ < 5, my_error, "error"), my_error);
+}