ソースを参照

Make test failures report properly in XCode.

Sam Jaffe 4 年 前
コミット
8b1b748212

+ 2 - 0
dice-roll.xcodeproj/project.pbxproj

@@ -115,6 +115,7 @@
 		CDED6A3021B2F2DC00AB91D0 /* die.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = die.cxx; sourceTree = "<group>"; };
 		CDED6A6021B2F89900AB91D0 /* libshared_random_generator.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libshared_random_generator.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDEE78D225B333A700F195F9 /* dice-roll */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "dice-roll"; path = "include/dice-roll"; sourceTree = "<group>"; };
+		CDEE78ED25B3350B00F195F9 /* xcode_gtest_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xcode_gtest_helper.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -232,6 +233,7 @@
 				CD38F53421C87799007A732C /* dice_test.cxx */,
 				CD38F53821C922E2007A732C /* roll_test.cxx */,
 				CD38F53A21C928B4007A732C /* exception_test.cxx */,
+				CDEE78ED25B3350B00F195F9 /* xcode_gtest_helper.h */,
 			);
 			path = test;
 			sourceTree = "<group>";

+ 1 - 1
test/dice_test.cxx

@@ -8,7 +8,7 @@
 
 #include <sstream>
 
-#include <gmock/gmock.h>
+#include "xcode_gtest_helper.h"
 
 #include "dice-roll/die.h"
 #include "dice-roll/exception.h"

+ 1 - 1
test/exception_test.cxx

@@ -6,7 +6,7 @@
 //  Copyright © 2018 Sam Jaffe. All rights reserved.
 //
 
-#include <gmock/gmock.h>
+#include "xcode_gtest_helper.h"
 
 #include "dice-roll/die.h"
 #include "dice-roll/exception.h"

+ 1 - 2
test/roll_test.cxx

@@ -6,8 +6,7 @@
 //  Copyright © 2018 Sam Jaffe. All rights reserved.
 //
 
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include "xcode_gtest_helper.h"
 
 #include "shared_random_generator/random_impl.h"
 

+ 33 - 0
test/xcode_gtest_helper.h

@@ -0,0 +1,33 @@
+//
+//  xcode_gtest_helper.h
+//  tax-calculator-test
+//
+//  Created by Sam Jaffe on 11/25/20.
+//  Copyright © 2020 Sam Jaffe. All rights reserved.
+//
+
+#pragma once
+
+#if defined(__APPLE__)
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#if defined(TARGET_OS_OSX)
+// This is a hack to allow XCode to properly display failures when running
+// unit tests.
+#undef EXPECT_THAT
+#define EXPECT_THAT ASSERT_THAT
+#undef EXPECT_THROW
+#define EXPECT_THROW ASSERT_THROW
+#undef EXPECT_ANY_THROW
+#define EXPECT_ANY_THROW ASSERT_ANY_THROW
+#undef EXPECT_NO_THROW
+#define EXPECT_NO_THROW ASSERT_NO_THROW
+#undef EXPECT_TRUE
+#define EXPECT_TRUE ASSERT_TRUE
+#undef EXPECT_FALSE
+#define EXPECT_FALSE ASSERT_FALSE
+
+#endif
+#endif