Enables the Python tests to run with 2.3 (necessary for testing on Mac OS X Tiger); also fixes gtest_output_test when built with xcode.

This commit is contained in:
shiqian 2008-11-24 20:13:22 +00:00
parent 514265c415
commit c440a6923a
6 changed files with 95 additions and 16 deletions

View File

@ -29,13 +29,13 @@ AC_PROG_LIBTOOL
# TODO(chandlerc@google.com): Currently we aren't running the Python tests # TODO(chandlerc@google.com): Currently we aren't running the Python tests
# against the interpreter detected by AM_PATH_PYTHON, and so we condition # against the interpreter detected by AM_PATH_PYTHON, and so we condition
# HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's # HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's
# version to be >= 2.4. This will allow the scripts to use a "/usr/bin/env" # version to be >= 2.3. This will allow the scripts to use a "/usr/bin/env"
# hashbang. # hashbang.
#AM_PATH_PYTHON([2.4],,[:]) #AM_PATH_PYTHON([2.3],,[:])
PYTHON= # We *do not* allow the user to specify a python interpreter PYTHON= # We *do not* allow the user to specify a python interpreter
AC_PATH_PROG([PYTHON],[python],[:]) AC_PATH_PROG([PYTHON],[python],[:])
AS_IF([test "$PYTHON" != ":"], AS_IF([test "$PYTHON" != ":"],
[AM_PYTHON_CHECK_VERSION([$PYTHON],[2.4],[:],[PYTHON=":"])]) [AM_PYTHON_CHECK_VERSION([$PYTHON],[2.3],[:],[PYTHON=":"])])
AM_CONDITIONAL([HAVE_PYTHON],[test "$PYTHON" != ":"]) AM_CONDITIONAL([HAVE_PYTHON],[test "$PYTHON" != ":"])
# TODO(chandlerc@google.com) Check for the necessary system headers. # TODO(chandlerc@google.com) Check for the necessary system headers.

View File

@ -1259,8 +1259,18 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// EXPECT_TRUE(foo.StatusIsOK()); // EXPECT_TRUE(foo.StatusIsOK());
// } // }
// Note that we call GetTestTypeId() instead of GetTypeId<
// ::testing::Test>() here to get the type ID of testing::Test. This
// is to work around a suspected linker bug when using Google Test as
// a framework on Mac OS X. The bug causes GetTypeId<
// ::testing::Test>() to return different values depending on whether
// the call is from the Google Test framework itself or from user test
// code. GetTestTypeId() is guaranteed to always return the same
// value, as it always calls GetTypeId<>() from the Google Test
// framework.
#define TEST(test_case_name, test_name)\ #define TEST(test_case_name, test_name)\
GTEST_TEST_(test_case_name, test_name, ::testing::Test) GTEST_TEST_(test_case_name, test_name,\
::testing::Test, ::testing::internal::GetTestTypeId())
// Defines a test that uses a test fixture. // Defines a test that uses a test fixture.
@ -1290,7 +1300,8 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2,
// } // }
#define TEST_F(test_fixture, test_name)\ #define TEST_F(test_fixture, test_name)\
GTEST_TEST_(test_fixture, test_name, test_fixture) GTEST_TEST_(test_fixture, test_name, test_fixture,\
::testing::internal::GetTypeId<test_fixture>())
// Use this macro in main() to run all tests. It returns 0 if all // Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise. // tests are successful, or 1 otherwise.

View File

@ -485,20 +485,39 @@ typedef FloatingPoint<double> Double;
// used to hold such IDs. The user should treat TypeId as an opaque // used to hold such IDs. The user should treat TypeId as an opaque
// type: the only operation allowed on TypeId values is to compare // type: the only operation allowed on TypeId values is to compare
// them for equality using the == operator. // them for equality using the == operator.
typedef void* TypeId; typedef const void* TypeId;
template <typename T>
class TypeIdHelper {
public:
// dummy_ must not have a const type. Otherwise an overly eager
// compiler (e.g. MSVC 7.1 & 8.0) may try to merge
// TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
static bool dummy_;
};
template <typename T>
bool TypeIdHelper<T>::dummy_ = false;
// GetTypeId<T>() returns the ID of type T. Different values will be // GetTypeId<T>() returns the ID of type T. Different values will be
// returned for different types. Calling the function twice with the // returned for different types. Calling the function twice with the
// same type argument is guaranteed to return the same ID. // same type argument is guaranteed to return the same ID.
template <typename T> template <typename T>
inline TypeId GetTypeId() { TypeId GetTypeId() {
static bool dummy = false; // The compiler is required to allocate a different
// The compiler is required to create an instance of the static // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
// variable dummy for each T used to instantiate the template. // the template. Therefore, the address of dummy_ is guaranteed to
// Therefore, the address of dummy is guaranteed to be unique. // be unique.
return &dummy; return &(TypeIdHelper<T>::dummy_);
} }
// Returns the type ID of ::testing::Test. Always call this instead
// of GetTypeId< ::testing::Test>() to get the type ID of
// ::testing::Test, as the latter may give the wrong result due to a
// suspected linker bug when compiling Google Test as a Mac OS X
// framework.
TypeId GetTestTypeId();
// Defines the abstract factory interface that creates instances // Defines the abstract factory interface that creates instances
// of a Test object. // of a Test object.
class TestFactoryBase { class TestFactoryBase {
@ -829,7 +848,7 @@ int GetFailedPartCount(const TestResult* result);
test_case_name##_##test_name##_Test test_case_name##_##test_name##_Test
// Helper macro for defining tests. // Helper macro for defining tests.
#define GTEST_TEST_(test_case_name, test_name, parent_class)\ #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
public:\ public:\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
@ -844,7 +863,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
::test_info_ =\ ::test_info_ =\
::testing::internal::MakeAndRegisterTestInfo(\ ::testing::internal::MakeAndRegisterTestInfo(\
#test_case_name, #test_name, "", "", \ #test_case_name, #test_name, "", "", \
::testing::internal::GetTypeId< parent_class >(), \ (parent_id), \
parent_class::SetUpTestCase, \ parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \ parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<\ new ::testing::internal::TestFactoryImpl<\

View File

@ -76,6 +76,10 @@ GTEST_DECLARE_bool_(show_internal_stack_frames);
namespace internal { namespace internal {
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
extern const TypeId kTestTypeIdInGoogleTest;
// Names of the flags (needed for parsing Google Test flags). // Names of the flags (needed for parsing Google Test flags).
const char kBreakOnFailureFlag[] = "break_on_failure"; const char kBreakOnFailureFlag[] = "break_on_failure";
const char kCatchExceptionsFlag[] = "catch_exceptions"; const char kCatchExceptionsFlag[] = "catch_exceptions";

View File

@ -515,6 +515,23 @@ void ScopedFakeTestPartResultReporter::ReportTestPartResult(
namespace internal { namespace internal {
// Returns the type ID of ::testing::Test. We should always call this
// instead of GetTypeId< ::testing::Test>() to get the type ID of
// testing::Test. This is to work around a suspected linker bug when
// using Google Test as a framework on Mac OS X. The bug causes
// GetTypeId< ::testing::Test>() to return different values depending
// on whether the call is from the Google Test framework itself or
// from user test code. GetTestTypeId() is guaranteed to always
// return the same value, as it always calls GetTypeId<>() from the
// gtest.cc, which is within the Google Test framework.
TypeId GetTestTypeId() {
return GetTypeId<Test>();
}
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
// This predicate-formatter checks that 'results' contains a test part // This predicate-formatter checks that 'results' contains a test part
// failure of the given type and that the failure message contains the // failure of the given type and that the failure message contains the
// given substring. // given substring.
@ -1924,9 +1941,9 @@ bool Test::HasSameFixtureClass() {
if (this_fixture_id != first_fixture_id) { if (this_fixture_id != first_fixture_id) {
// Is the first test defined using TEST? // Is the first test defined using TEST?
const bool first_is_TEST = first_fixture_id == internal::GetTypeId<Test>(); const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
// Is this test defined using TEST? // Is this test defined using TEST?
const bool this_is_TEST = this_fixture_id == internal::GetTypeId<Test>(); const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
if (first_is_TEST || this_is_TEST) { if (first_is_TEST || this_is_TEST) {
// The user mixed TEST and TEST_F in this test case - we'll tell // The user mixed TEST and TEST_F in this test case - we'll tell

View File

@ -105,12 +105,15 @@ using testing::TPRT_FATAL_FAILURE;
using testing::TPRT_NONFATAL_FAILURE; using testing::TPRT_NONFATAL_FAILURE;
using testing::TPRT_SUCCESS; using testing::TPRT_SUCCESS;
using testing::UnitTest; using testing::UnitTest;
using testing::internal::kTestTypeIdInGoogleTest;
using testing::internal::AppendUserMessage; using testing::internal::AppendUserMessage;
using testing::internal::CodePointToUtf8; using testing::internal::CodePointToUtf8;
using testing::internal::EqFailure; using testing::internal::EqFailure;
using testing::internal::FloatingPoint; using testing::internal::FloatingPoint;
using testing::internal::GetCurrentOsStackTraceExceptTop; using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetFailedPartCount; using testing::internal::GetFailedPartCount;
using testing::internal::GetTestTypeId;
using testing::internal::GetTypeId;
using testing::internal::GTestFlagSaver; using testing::internal::GTestFlagSaver;
using testing::internal::Int32; using testing::internal::Int32;
using testing::internal::List; using testing::internal::List;
@ -126,6 +129,31 @@ using testing::internal::WideStringToUtf8;
// This line tests that we can define tests in an unnamed namespace. // This line tests that we can define tests in an unnamed namespace.
namespace { namespace {
// Tests GetTypeId.
TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
EXPECT_EQ(GetTypeId<int>(), GetTypeId<int>());
EXPECT_EQ(GetTypeId<Test>(), GetTypeId<Test>());
}
class SubClassOfTest : public Test {};
class AnotherSubClassOfTest : public Test {};
TEST(GetTypeIdTest, ReturnsDifferentValuesForDifferentTypes) {
EXPECT_NE(GetTypeId<int>(), GetTypeId<const int>());
EXPECT_NE(GetTypeId<int>(), GetTypeId<char>());
EXPECT_NE(GetTypeId<int>(), GetTestTypeId());
EXPECT_NE(GetTypeId<SubClassOfTest>(), GetTestTypeId());
EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTestTypeId());
EXPECT_NE(GetTypeId<AnotherSubClassOfTest>(), GetTypeId<SubClassOfTest>());
}
// Verifies that GetTestTypeId() returns the same value, no matter it
// is called from inside Google Test or outside of it.
TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
EXPECT_EQ(kTestTypeIdInGoogleTest, GetTestTypeId());
}
// Tests FormatTimeInMillisAsSeconds(). // Tests FormatTimeInMillisAsSeconds().
TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) { TEST(FormatTimeInMillisAsSecondsTest, FormatsZero) {