Renames the TestPartResult type enums and adjusts the order of methods in the event listener interface (by Vlad Losev).
This commit is contained in:
parent
9f894c2b36
commit
e5373af0cb
@ -97,12 +97,12 @@ class SingleFailureChecker {
|
|||||||
public:
|
public:
|
||||||
// The constructor remembers the arguments.
|
// The constructor remembers the arguments.
|
||||||
SingleFailureChecker(const TestPartResultArray* results,
|
SingleFailureChecker(const TestPartResultArray* results,
|
||||||
TestPartResultType type,
|
TestPartResult::Type type,
|
||||||
const char* substr);
|
const char* substr);
|
||||||
~SingleFailureChecker();
|
~SingleFailureChecker();
|
||||||
private:
|
private:
|
||||||
const TestPartResultArray* const results_;
|
const TestPartResultArray* const results_;
|
||||||
const TestPartResultType type_;
|
const TestPartResult::Type type_;
|
||||||
const String substr_;
|
const String substr_;
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
|
||||||
@ -143,7 +143,7 @@ class SingleFailureChecker {
|
|||||||
};\
|
};\
|
||||||
::testing::TestPartResultArray gtest_failures;\
|
::testing::TestPartResultArray gtest_failures;\
|
||||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||||
>est_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\
|
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
|
||||||
{\
|
{\
|
||||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||||
::testing::ScopedFakeTestPartResultReporter:: \
|
::testing::ScopedFakeTestPartResultReporter:: \
|
||||||
@ -160,7 +160,7 @@ class SingleFailureChecker {
|
|||||||
};\
|
};\
|
||||||
::testing::TestPartResultArray gtest_failures;\
|
::testing::TestPartResultArray gtest_failures;\
|
||||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||||
>est_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\
|
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
|
||||||
{\
|
{\
|
||||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||||
::testing::ScopedFakeTestPartResultReporter:: \
|
::testing::ScopedFakeTestPartResultReporter:: \
|
||||||
@ -196,7 +196,8 @@ class SingleFailureChecker {
|
|||||||
do {\
|
do {\
|
||||||
::testing::TestPartResultArray gtest_failures;\
|
::testing::TestPartResultArray gtest_failures;\
|
||||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||||
>est_failures, ::testing::TPRT_NONFATAL_FAILURE, (substr));\
|
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
|
||||||
|
(substr));\
|
||||||
{\
|
{\
|
||||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||||
::testing::ScopedFakeTestPartResultReporter:: \
|
::testing::ScopedFakeTestPartResultReporter:: \
|
||||||
@ -209,7 +210,8 @@ class SingleFailureChecker {
|
|||||||
do {\
|
do {\
|
||||||
::testing::TestPartResultArray gtest_failures;\
|
::testing::TestPartResultArray gtest_failures;\
|
||||||
::testing::internal::SingleFailureChecker gtest_checker(\
|
::testing::internal::SingleFailureChecker gtest_checker(\
|
||||||
>est_failures, ::testing::TPRT_NONFATAL_FAILURE, (substr));\
|
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
|
||||||
|
(substr));\
|
||||||
{\
|
{\
|
||||||
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
|
||||||
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
|
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
|
||||||
|
@ -39,27 +39,24 @@
|
|||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
// The possible outcomes of a test part (i.e. an assertion or an
|
|
||||||
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
|
|
||||||
// TODO(vladl@google.com): Rename the enum values to kSuccess,
|
|
||||||
// kNonFatalFailure, and kFatalFailure before publishing the event listener
|
|
||||||
// API (see issue http://code.google.com/p/googletest/issues/detail?id=165).
|
|
||||||
enum TestPartResultType {
|
|
||||||
TPRT_SUCCESS, // Succeeded.
|
|
||||||
TPRT_NONFATAL_FAILURE, // Failed but the test can continue.
|
|
||||||
TPRT_FATAL_FAILURE // Failed and the test should be terminated.
|
|
||||||
};
|
|
||||||
|
|
||||||
// A copyable object representing the result of a test part (i.e. an
|
// A copyable object representing the result of a test part (i.e. an
|
||||||
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
|
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
|
||||||
//
|
//
|
||||||
// Don't inherit from TestPartResult as its destructor is not virtual.
|
// Don't inherit from TestPartResult as its destructor is not virtual.
|
||||||
class TestPartResult {
|
class TestPartResult {
|
||||||
public:
|
public:
|
||||||
|
// The possible outcomes of a test part (i.e. an assertion or an
|
||||||
|
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
|
||||||
|
enum Type {
|
||||||
|
kSuccess, // Succeeded.
|
||||||
|
kNonFatalFailure, // Failed but the test can continue.
|
||||||
|
kFatalFailure // Failed and the test should be terminated.
|
||||||
|
};
|
||||||
|
|
||||||
// C'tor. TestPartResult does NOT have a default constructor.
|
// C'tor. TestPartResult does NOT have a default constructor.
|
||||||
// Always use this constructor (with parameters) to create a
|
// Always use this constructor (with parameters) to create a
|
||||||
// TestPartResult object.
|
// TestPartResult object.
|
||||||
TestPartResult(TestPartResultType type,
|
TestPartResult(Type type,
|
||||||
const char* file_name,
|
const char* file_name,
|
||||||
int line_number,
|
int line_number,
|
||||||
const char* message)
|
const char* message)
|
||||||
@ -71,7 +68,7 @@ class TestPartResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gets the outcome of the test part.
|
// Gets the outcome of the test part.
|
||||||
TestPartResultType type() const { return type_; }
|
Type type() const { return type_; }
|
||||||
|
|
||||||
// Gets the name of the source file where the test part took place, or
|
// Gets the name of the source file where the test part took place, or
|
||||||
// NULL if it's unknown.
|
// NULL if it's unknown.
|
||||||
@ -88,18 +85,18 @@ class TestPartResult {
|
|||||||
const char* message() const { return message_.c_str(); }
|
const char* message() const { return message_.c_str(); }
|
||||||
|
|
||||||
// Returns true iff the test part passed.
|
// Returns true iff the test part passed.
|
||||||
bool passed() const { return type_ == TPRT_SUCCESS; }
|
bool passed() const { return type_ == kSuccess; }
|
||||||
|
|
||||||
// Returns true iff the test part failed.
|
// Returns true iff the test part failed.
|
||||||
bool failed() const { return type_ != TPRT_SUCCESS; }
|
bool failed() const { return type_ != kSuccess; }
|
||||||
|
|
||||||
// Returns true iff the test part non-fatally failed.
|
// Returns true iff the test part non-fatally failed.
|
||||||
bool nonfatally_failed() const { return type_ == TPRT_NONFATAL_FAILURE; }
|
bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
|
||||||
|
|
||||||
// Returns true iff the test part fatally failed.
|
// Returns true iff the test part fatally failed.
|
||||||
bool fatally_failed() const { return type_ == TPRT_FATAL_FAILURE; }
|
bool fatally_failed() const { return type_ == kFatalFailure; }
|
||||||
private:
|
private:
|
||||||
TestPartResultType type_;
|
Type type_;
|
||||||
|
|
||||||
// Gets the summary of the failure message by omitting the stack
|
// Gets the summary of the failure message by omitting the stack
|
||||||
// trace in it.
|
// trace in it.
|
||||||
|
@ -161,7 +161,7 @@ class UnitTestAccessor;
|
|||||||
class TestEventRepeater;
|
class TestEventRepeater;
|
||||||
class WindowsDeathTest;
|
class WindowsDeathTest;
|
||||||
class UnitTestImpl* GetUnitTestImpl();
|
class UnitTestImpl* GetUnitTestImpl();
|
||||||
void ReportFailureInUnknownLocation(TestPartResultType result_type,
|
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
||||||
const String& message);
|
const String& message);
|
||||||
class PrettyUnitTestResultPrinter;
|
class PrettyUnitTestResultPrinter;
|
||||||
class XmlUnitTestResultPrinter;
|
class XmlUnitTestResultPrinter;
|
||||||
@ -773,58 +773,54 @@ class Environment {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
// TODO(vladl@google.com): Order the methods the way they are invoked by
|
// The interface for tracing execution of tests. The methods are organized in
|
||||||
// Google Test.
|
// the order the corresponding events are fired.
|
||||||
// The interface for tracing execution of tests.
|
|
||||||
class UnitTestEventListenerInterface {
|
class UnitTestEventListenerInterface {
|
||||||
public:
|
public:
|
||||||
virtual ~UnitTestEventListenerInterface() {}
|
virtual ~UnitTestEventListenerInterface() {}
|
||||||
|
|
||||||
// TODO(vladl@google.com): Add tests for OnTestIterationStart and
|
|
||||||
// OnTestIterationEnd.
|
|
||||||
|
|
||||||
// Fired before any test activity starts.
|
// Fired before any test activity starts.
|
||||||
virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
|
virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired after all test activities have ended.
|
|
||||||
virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
|
|
||||||
|
|
||||||
// Fired before each iteration of tests starts. There may be more than
|
// Fired before each iteration of tests starts. There may be more than
|
||||||
// one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
|
// one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
|
||||||
// index, starting from 0.
|
// index, starting from 0.
|
||||||
virtual void OnTestIterationStart(const UnitTest& unit_test,
|
virtual void OnTestIterationStart(const UnitTest& unit_test,
|
||||||
int iteration) = 0;
|
int iteration) = 0;
|
||||||
|
|
||||||
// Fired after each iteration of tests finishes.
|
|
||||||
virtual void OnTestIterationEnd(const UnitTest& unit_test,
|
|
||||||
int iteration) = 0;
|
|
||||||
|
|
||||||
// Fired before environment set-up for each iteration of tests starts.
|
// Fired before environment set-up for each iteration of tests starts.
|
||||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired after environment set-up for each iteration of tests ends.
|
// Fired after environment set-up for each iteration of tests ends.
|
||||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
|
// Fired before the test case starts.
|
||||||
|
virtual void OnTestCaseStart(const TestCase& test_case) = 0;
|
||||||
|
|
||||||
|
// Fired before the test starts.
|
||||||
|
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||||
|
|
||||||
|
// Fired after a failed assertion or a SUCCESS().
|
||||||
|
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
|
||||||
|
|
||||||
|
// Fired after the test ends.
|
||||||
|
virtual void OnTestEnd(const TestInfo& test_info) = 0;
|
||||||
|
|
||||||
|
// Fired after the test case ends.
|
||||||
|
virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
|
||||||
|
|
||||||
// Fired before environment tear-down for each iteration of tests starts.
|
// Fired before environment tear-down for each iteration of tests starts.
|
||||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired after environment tear-down for each iteration of tests ends.
|
// Fired after environment tear-down for each iteration of tests ends.
|
||||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired before the test case starts.
|
// Fired after each iteration of tests finishes.
|
||||||
virtual void OnTestCaseStart(const TestCase& test_case) = 0;
|
virtual void OnTestIterationEnd(const UnitTest& unit_test,
|
||||||
|
int iteration) = 0;
|
||||||
|
|
||||||
// Fired after the test case ends.
|
// Fired after all test activities have ended.
|
||||||
virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
|
virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired before the test starts.
|
|
||||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
|
||||||
|
|
||||||
// Fired after the test ends.
|
|
||||||
virtual void OnTestEnd(const TestInfo& test_info) = 0;
|
|
||||||
|
|
||||||
// Fired after a failed assertion or a SUCCESS().
|
|
||||||
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The convenience class for users who need to override just one or two
|
// The convenience class for users who need to override just one or two
|
||||||
@ -835,20 +831,20 @@ class UnitTestEventListenerInterface {
|
|||||||
class EmptyTestEventListener : public UnitTestEventListenerInterface {
|
class EmptyTestEventListener : public UnitTestEventListenerInterface {
|
||||||
public:
|
public:
|
||||||
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
|
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
|
|
||||||
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
|
||||||
int /*iteration*/) {}
|
int /*iteration*/) {}
|
||||||
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
|
||||||
int /*iteration*/) {}
|
|
||||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
|
||||||
|
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
|
||||||
|
virtual void OnTestStart(const TestInfo& /*test_info*/) {}
|
||||||
|
virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
|
||||||
|
virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
|
||||||
|
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
|
||||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
|
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||||
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
|
int /*iteration*/) {}
|
||||||
virtual void OnTestStart(const TestInfo& /*test_info*/) {}
|
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
|
|
||||||
virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EventListeners lets users add listeners to track events in Google Test.
|
// EventListeners lets users add listeners to track events in Google Test.
|
||||||
@ -996,7 +992,7 @@ class UnitTest {
|
|||||||
// Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
|
// Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
|
||||||
// eventually call this to report their results. The user code
|
// eventually call this to report their results. The user code
|
||||||
// should use the assertion macros instead of calling this directly.
|
// should use the assertion macros instead of calling this directly.
|
||||||
void AddTestPartResult(TestPartResultType result_type,
|
void AddTestPartResult(TestPartResult::Type result_type,
|
||||||
const char* file_name,
|
const char* file_name,
|
||||||
int line_number,
|
int line_number,
|
||||||
const internal::String& message,
|
const internal::String& message,
|
||||||
@ -1066,7 +1062,7 @@ class UnitTest {
|
|||||||
friend class internal::AssertHelper;
|
friend class internal::AssertHelper;
|
||||||
friend class Test;
|
friend class Test;
|
||||||
friend void internal::ReportFailureInUnknownLocation(
|
friend void internal::ReportFailureInUnknownLocation(
|
||||||
TestPartResultType result_type,
|
TestPartResult::Type result_type,
|
||||||
const internal::String& message);
|
const internal::String& message);
|
||||||
// TODO(vladl@google.com): Remove these when publishing the new accessors.
|
// TODO(vladl@google.com): Remove these when publishing the new accessors.
|
||||||
friend class internal::PrettyUnitTestResultPrinter;
|
friend class internal::PrettyUnitTestResultPrinter;
|
||||||
@ -1470,7 +1466,9 @@ AssertionResult DoubleNearPredFormat(const char* expr1,
|
|||||||
class AssertHelper {
|
class AssertHelper {
|
||||||
public:
|
public:
|
||||||
// Constructor.
|
// Constructor.
|
||||||
AssertHelper(TestPartResultType type, const char* file, int line,
|
AssertHelper(TestPartResult::Type type,
|
||||||
|
const char* file,
|
||||||
|
int line,
|
||||||
const char* message);
|
const char* message);
|
||||||
~AssertHelper();
|
~AssertHelper();
|
||||||
|
|
||||||
@ -1484,11 +1482,13 @@ class AssertHelper {
|
|||||||
// re-using stack space even for temporary variables, so every EXPECT_EQ
|
// re-using stack space even for temporary variables, so every EXPECT_EQ
|
||||||
// reserves stack space for another AssertHelper.
|
// reserves stack space for another AssertHelper.
|
||||||
struct AssertHelperData {
|
struct AssertHelperData {
|
||||||
AssertHelperData(TestPartResultType t, const char* srcfile, int line_num,
|
AssertHelperData(TestPartResult::Type t,
|
||||||
|
const char* srcfile,
|
||||||
|
int line_num,
|
||||||
const char* msg)
|
const char* msg)
|
||||||
: type(t), file(srcfile), line(line_num), message(msg) { }
|
: type(t), file(srcfile), line(line_num), message(msg) { }
|
||||||
|
|
||||||
TestPartResultType const type;
|
TestPartResult::Type const type;
|
||||||
const char* const file;
|
const char* const file;
|
||||||
int const line;
|
int const line;
|
||||||
String const message;
|
String const message;
|
||||||
|
@ -756,13 +756,13 @@ bool AlwaysTrue();
|
|||||||
= ::testing::Message()
|
= ::testing::Message()
|
||||||
|
|
||||||
#define GTEST_FATAL_FAILURE_(message) \
|
#define GTEST_FATAL_FAILURE_(message) \
|
||||||
return GTEST_MESSAGE_(message, ::testing::TPRT_FATAL_FAILURE)
|
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
|
||||||
|
|
||||||
#define GTEST_NONFATAL_FAILURE_(message) \
|
#define GTEST_NONFATAL_FAILURE_(message) \
|
||||||
GTEST_MESSAGE_(message, ::testing::TPRT_NONFATAL_FAILURE)
|
GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
|
||||||
|
|
||||||
#define GTEST_SUCCESS_(message) \
|
#define GTEST_SUCCESS_(message) \
|
||||||
GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS)
|
GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
|
||||||
|
|
||||||
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
|
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
|
||||||
// statement if it returns or throws (or doesn't return or throw in some
|
// statement if it returns or throws (or doesn't return or throw in some
|
||||||
|
@ -95,15 +95,6 @@ class TersePrinter : public EmptyTestEventListener {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called after a test ends.
|
|
||||||
virtual void OnTestEnd(const TestInfo& test_info) {
|
|
||||||
fprintf(stdout,
|
|
||||||
"*** Test %s.%s ending.\n",
|
|
||||||
test_info.test_case_name(),
|
|
||||||
test_info.name());
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called after a failed assertion or a SUCCESS().
|
// Called after a failed assertion or a SUCCESS().
|
||||||
virtual void OnTestPartResult(const TestPartResult& test_part_result) {
|
virtual void OnTestPartResult(const TestPartResult& test_part_result) {
|
||||||
fprintf(stdout,
|
fprintf(stdout,
|
||||||
@ -114,6 +105,15 @@ class TersePrinter : public EmptyTestEventListener {
|
|||||||
test_part_result.summary());
|
test_part_result.summary());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called after a test ends.
|
||||||
|
virtual void OnTestEnd(const TestInfo& test_info) {
|
||||||
|
fprintf(stdout,
|
||||||
|
"*** Test %s.%s ending.\n",
|
||||||
|
test_info.test_case_name(),
|
||||||
|
test_info.name());
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
}; // class TersePrinter
|
}; // class TersePrinter
|
||||||
|
|
||||||
TEST(CustomOutputTest, PrintsMessage) {
|
TEST(CustomOutputTest, PrintsMessage) {
|
||||||
|
@ -56,10 +56,10 @@ internal::String TestPartResult::ExtractSummary(const char* message) {
|
|||||||
|
|
||||||
// Prints a TestPartResult object.
|
// Prints a TestPartResult object.
|
||||||
std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
|
std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
|
||||||
return os << result.file_name() << ":"
|
return os
|
||||||
<< result.line_number() << ": "
|
<< result.file_name() << ":" << result.line_number() << ": "
|
||||||
<< (result.type() == TPRT_SUCCESS ? "Success" :
|
<< (result.type() == TestPartResult::kSuccess ? "Success" :
|
||||||
result.type() == TPRT_FATAL_FAILURE ? "Fatal failure" :
|
result.type() == TestPartResult::kFatalFailure ? "Fatal failure" :
|
||||||
"Non-fatal failure") << ":\n"
|
"Non-fatal failure") << ":\n"
|
||||||
<< result.message() << std::endl;
|
<< result.message() << std::endl;
|
||||||
}
|
}
|
||||||
|
102
src/gtest.cc
102
src/gtest.cc
@ -304,8 +304,10 @@ static bool ShouldRunTestCase(const TestCase* test_case) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AssertHelper constructor.
|
// AssertHelper constructor.
|
||||||
AssertHelper::AssertHelper(TestPartResultType type, const char* file,
|
AssertHelper::AssertHelper(TestPartResult::Type type,
|
||||||
int line, const char* message)
|
const char* file,
|
||||||
|
int line,
|
||||||
|
const char* message)
|
||||||
: data_(new AssertHelperData(type, file, line, message)) {
|
: data_(new AssertHelperData(type, file, line, message)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,10 +560,10 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
|
|||||||
const char* /* type_expr */,
|
const char* /* type_expr */,
|
||||||
const char* /* substr_expr */,
|
const char* /* substr_expr */,
|
||||||
const TestPartResultArray& results,
|
const TestPartResultArray& results,
|
||||||
TestPartResultType type,
|
TestPartResult::Type type,
|
||||||
const char* substr) {
|
const char* substr) {
|
||||||
const String expected(
|
const String expected(type == TestPartResult::kFatalFailure ?
|
||||||
type == TPRT_FATAL_FAILURE ? "1 fatal failure" :
|
"1 fatal failure" :
|
||||||
"1 non-fatal failure");
|
"1 non-fatal failure");
|
||||||
Message msg;
|
Message msg;
|
||||||
if (results.size() != 1) {
|
if (results.size() != 1) {
|
||||||
@ -597,7 +599,7 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
|
|||||||
// substring the failure message should contain.
|
// substring the failure message should contain.
|
||||||
SingleFailureChecker:: SingleFailureChecker(
|
SingleFailureChecker:: SingleFailureChecker(
|
||||||
const TestPartResultArray* results,
|
const TestPartResultArray* results,
|
||||||
TestPartResultType type,
|
TestPartResult::Type type,
|
||||||
const char* substr)
|
const char* substr)
|
||||||
: results_(results),
|
: results_(results),
|
||||||
type_(type),
|
type_(type),
|
||||||
@ -1908,7 +1910,7 @@ void Test::RecordProperty(const char* key, int value) {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
void ReportFailureInUnknownLocation(TestPartResultType result_type,
|
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
||||||
const String& message) {
|
const String& message) {
|
||||||
// This function is a friend of UnitTest and as such has access to
|
// This function is a friend of UnitTest and as such has access to
|
||||||
// AddTestPartResult.
|
// AddTestPartResult.
|
||||||
@ -1932,7 +1934,7 @@ static void AddExceptionThrownFailure(DWORD exception_code,
|
|||||||
message << "Exception thrown with code 0x" << std::setbase(16) <<
|
message << "Exception thrown with code 0x" << std::setbase(16) <<
|
||||||
exception_code << std::setbase(10) << " in " << location << ".";
|
exception_code << std::setbase(10) << " in " << location << ".";
|
||||||
|
|
||||||
internal::ReportFailureInUnknownLocation(TPRT_FATAL_FAILURE,
|
internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,
|
||||||
message.GetString());
|
message.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2430,17 +2432,17 @@ static internal::String FormatTestCaseCount(int test_case_count) {
|
|||||||
return FormatCountableNoun(test_case_count, "test case", "test cases");
|
return FormatCountableNoun(test_case_count, "test case", "test cases");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts a TestPartResultType enum to human-friendly string
|
// Converts a TestPartResult::Type enum to human-friendly string
|
||||||
// representation. Both TPRT_NONFATAL_FAILURE and TPRT_FATAL_FAILURE
|
// representation. Both kNonFatalFailure and kFatalFailure are translated
|
||||||
// are translated to "Failure", as the user usually doesn't care about
|
// to "Failure", as the user usually doesn't care about the difference
|
||||||
// the difference between the two when viewing the test result.
|
// between the two when viewing the test result.
|
||||||
static const char * TestPartResultTypeToString(TestPartResultType type) {
|
static const char * TestPartResultTypeToString(TestPartResult::Type type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TPRT_SUCCESS:
|
case TestPartResult::kSuccess:
|
||||||
return "Success";
|
return "Success";
|
||||||
|
|
||||||
case TPRT_NONFATAL_FAILURE:
|
case TestPartResult::kNonFatalFailure:
|
||||||
case TPRT_FATAL_FAILURE:
|
case TestPartResult::kFatalFailure:
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
return "error: ";
|
return "error: ";
|
||||||
#else
|
#else
|
||||||
@ -2611,10 +2613,10 @@ class PrettyUnitTestResultPrinter : public UnitTestEventListenerInterface {
|
|||||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
|
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
|
||||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnTestCaseStart(const TestCase& test_case);
|
virtual void OnTestCaseStart(const TestCase& test_case);
|
||||||
virtual void OnTestCaseEnd(const TestCase& test_case);
|
|
||||||
virtual void OnTestStart(const TestInfo& test_info);
|
virtual void OnTestStart(const TestInfo& test_info);
|
||||||
virtual void OnTestPartResult(const TestPartResult& result);
|
virtual void OnTestPartResult(const TestPartResult& result);
|
||||||
virtual void OnTestEnd(const TestInfo& test_info);
|
virtual void OnTestEnd(const TestInfo& test_info);
|
||||||
|
virtual void OnTestCaseEnd(const TestCase& test_case);
|
||||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
|
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
|
||||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
|
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
|
||||||
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
|
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
|
||||||
@ -2682,19 +2684,6 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {
|
|
||||||
if (!GTEST_FLAG(print_time)) return;
|
|
||||||
|
|
||||||
test_case_name_ = test_case.name();
|
|
||||||
const internal::String counts =
|
|
||||||
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
|
|
||||||
ColoredPrintf(COLOR_GREEN, "[----------] ");
|
|
||||||
printf("%s from %s (%s ms total)\n\n",
|
|
||||||
counts.c_str(), test_case_name_.c_str(),
|
|
||||||
internal::StreamableToString(test_case.elapsed_time()).c_str());
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
|
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
|
||||||
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
|
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
|
||||||
PrintTestName(test_case_name_.c_str(), test_info.name());
|
PrintTestName(test_case_name_.c_str(), test_info.name());
|
||||||
@ -2706,6 +2695,18 @@ void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called after an assertion failure.
|
||||||
|
void PrettyUnitTestResultPrinter::OnTestPartResult(
|
||||||
|
const TestPartResult& result) {
|
||||||
|
// If the test part succeeded, we don't need to do anything.
|
||||||
|
if (result.type() == TestPartResult::kSuccess)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Print failure message from the assertion (e.g. expected this and got that).
|
||||||
|
PrintTestPartResult(result);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
|
void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
|
||||||
if (test_info.result()->Passed()) {
|
if (test_info.result()->Passed()) {
|
||||||
ColoredPrintf(COLOR_GREEN, "[ OK ] ");
|
ColoredPrintf(COLOR_GREEN, "[ OK ] ");
|
||||||
@ -2722,15 +2723,16 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called after an assertion failure.
|
void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {
|
||||||
void PrettyUnitTestResultPrinter::OnTestPartResult(
|
if (!GTEST_FLAG(print_time)) return;
|
||||||
const TestPartResult& result) {
|
|
||||||
// If the test part succeeded, we don't need to do anything.
|
|
||||||
if (result.type() == TPRT_SUCCESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Print failure message from the assertion (e.g. expected this and got that).
|
test_case_name_ = test_case.name();
|
||||||
PrintTestPartResult(result);
|
const internal::String counts =
|
||||||
|
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
|
||||||
|
ColoredPrintf(COLOR_GREEN, "[----------] ");
|
||||||
|
printf("%s from %s (%s ms total)\n\n",
|
||||||
|
counts.c_str(), test_case_name_.c_str(),
|
||||||
|
internal::StreamableToString(test_case.elapsed_time()).c_str());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2830,18 +2832,18 @@ class TestEventRepeater : public UnitTestEventListenerInterface {
|
|||||||
void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
|
void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
|
||||||
|
|
||||||
virtual void OnTestProgramStart(const UnitTest& unit_test);
|
virtual void OnTestProgramStart(const UnitTest& unit_test);
|
||||||
virtual void OnTestProgramEnd(const UnitTest& unit_test);
|
|
||||||
virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
|
virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
|
||||||
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
|
|
||||||
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
|
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
|
||||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);
|
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);
|
||||||
|
virtual void OnTestCaseStart(const TestCase& test_case);
|
||||||
|
virtual void OnTestStart(const TestInfo& test_info);
|
||||||
|
virtual void OnTestPartResult(const TestPartResult& result);
|
||||||
|
virtual void OnTestEnd(const TestInfo& test_info);
|
||||||
|
virtual void OnTestCaseEnd(const TestCase& test_case);
|
||||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
|
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
|
||||||
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);
|
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);
|
||||||
virtual void OnTestCaseStart(const TestCase& test_case);
|
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
|
||||||
virtual void OnTestCaseEnd(const TestCase& test_case);
|
virtual void OnTestProgramEnd(const UnitTest& unit_test);
|
||||||
virtual void OnTestStart(const TestInfo& test_info);
|
|
||||||
virtual void OnTestEnd(const TestInfo& test_info);
|
|
||||||
virtual void OnTestPartResult(const TestPartResult& result);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Controls whether events will be forwarded to listeners_. Set to false
|
// Controls whether events will be forwarded to listeners_. Set to false
|
||||||
@ -2899,15 +2901,15 @@ void TestEventRepeater::Name(const Type& parameter) { \
|
|||||||
|
|
||||||
GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
|
GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
|
||||||
GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
|
GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
|
||||||
GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
|
|
||||||
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)
|
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)
|
||||||
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
|
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
|
||||||
GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
|
GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
|
||||||
GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
|
GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
|
||||||
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
|
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
|
||||||
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
|
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
|
||||||
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
|
|
||||||
GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
|
GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
|
||||||
|
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
|
||||||
|
GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
|
||||||
|
|
||||||
#undef GTEST_REPEATER_METHOD_
|
#undef GTEST_REPEATER_METHOD_
|
||||||
#undef GTEST_REVERSE_REPEATER_METHOD_
|
#undef GTEST_REVERSE_REPEATER_METHOD_
|
||||||
@ -3454,7 +3456,7 @@ class GoogleTestFailureException : public ::std::runtime_error {
|
|||||||
// this to report their results. The user code should use the
|
// this to report their results. The user code should use the
|
||||||
// assertion macros instead of calling this directly.
|
// assertion macros instead of calling this directly.
|
||||||
// L < mutex_
|
// L < mutex_
|
||||||
void UnitTest::AddTestPartResult(TestPartResultType result_type,
|
void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
|
||||||
const char* file_name,
|
const char* file_name,
|
||||||
int line_number,
|
int line_number,
|
||||||
const internal::String& message,
|
const internal::String& message,
|
||||||
@ -3484,7 +3486,7 @@ void UnitTest::AddTestPartResult(TestPartResultType result_type,
|
|||||||
impl_->GetTestPartResultReporterForCurrentThread()->
|
impl_->GetTestPartResultReporterForCurrentThread()->
|
||||||
ReportTestPartResult(result);
|
ReportTestPartResult(result);
|
||||||
|
|
||||||
if (result_type != TPRT_SUCCESS) {
|
if (result_type != TestPartResult::kSuccess) {
|
||||||
// gtest_break_on_failure takes precedence over
|
// gtest_break_on_failure takes precedence over
|
||||||
// gtest_throw_on_failure. This allows a user to set the latter
|
// gtest_throw_on_failure. This allows a user to set the latter
|
||||||
// in the code (perhaps in order to use Google Test assertions
|
// in the code (perhaps in order to use Google Test assertions
|
||||||
|
@ -38,10 +38,6 @@ using testing::Test;
|
|||||||
using testing::TestPartResult;
|
using testing::TestPartResult;
|
||||||
using testing::TestPartResultArray;
|
using testing::TestPartResultArray;
|
||||||
|
|
||||||
using testing::TPRT_FATAL_FAILURE;
|
|
||||||
using testing::TPRT_NONFATAL_FAILURE;
|
|
||||||
using testing::TPRT_SUCCESS;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Tests the TestPartResult class.
|
// Tests the TestPartResult class.
|
||||||
@ -50,18 +46,18 @@ namespace {
|
|||||||
class TestPartResultTest : public Test {
|
class TestPartResultTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
TestPartResultTest()
|
TestPartResultTest()
|
||||||
: r1_(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!"),
|
: r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"),
|
||||||
r2_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure!"),
|
r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"),
|
||||||
r3_(TPRT_FATAL_FAILURE, NULL, -1, "Failure!") {}
|
r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {}
|
||||||
|
|
||||||
TestPartResult r1_, r2_, r3_;
|
TestPartResult r1_, r2_, r3_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tests TestPartResult::type().
|
// Tests TestPartResult::type().
|
||||||
TEST_F(TestPartResultTest, type) {
|
TEST_F(TestPartResultTest, type) {
|
||||||
EXPECT_EQ(TPRT_SUCCESS, r1_.type());
|
EXPECT_EQ(TestPartResult::kSuccess, r1_.type());
|
||||||
EXPECT_EQ(TPRT_NONFATAL_FAILURE, r2_.type());
|
EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type());
|
||||||
EXPECT_EQ(TPRT_FATAL_FAILURE, r3_.type());
|
EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests TestPartResult::file_name().
|
// Tests TestPartResult::file_name().
|
||||||
@ -114,8 +110,8 @@ TEST_F(TestPartResultTest, NonfatallyFailed) {
|
|||||||
class TestPartResultArrayTest : public Test {
|
class TestPartResultArrayTest : public Test {
|
||||||
protected:
|
protected:
|
||||||
TestPartResultArrayTest()
|
TestPartResultArrayTest()
|
||||||
: r1_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure 1"),
|
: r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"),
|
||||||
r2_(TPRT_FATAL_FAILURE, "foo/bar.cc", -1, "Failure 2") {}
|
r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {}
|
||||||
|
|
||||||
const TestPartResult r1_, r2_;
|
const TestPartResult r1_, r2_;
|
||||||
};
|
};
|
||||||
|
@ -152,9 +152,6 @@ using testing::IsSubstring;
|
|||||||
using testing::Message;
|
using testing::Message;
|
||||||
using testing::ScopedFakeTestPartResultReporter;
|
using testing::ScopedFakeTestPartResultReporter;
|
||||||
using testing::StaticAssertTypeEq;
|
using testing::StaticAssertTypeEq;
|
||||||
using testing::TPRT_FATAL_FAILURE;
|
|
||||||
using testing::TPRT_NONFATAL_FAILURE;
|
|
||||||
using testing::TPRT_SUCCESS;
|
|
||||||
using testing::Test;
|
using testing::Test;
|
||||||
using testing::TestPartResult;
|
using testing::TestPartResult;
|
||||||
using testing::TestPartResultArray;
|
using testing::TestPartResultArray;
|
||||||
@ -1404,12 +1401,12 @@ TEST(TestPartResultTest, ConstructorWorks) {
|
|||||||
message << static_cast<const char*>(testing::internal::kStackTraceMarker);
|
message << static_cast<const char*>(testing::internal::kStackTraceMarker);
|
||||||
message << "some unimportant stack trace";
|
message << "some unimportant stack trace";
|
||||||
|
|
||||||
const TestPartResult result(TPRT_NONFATAL_FAILURE,
|
const TestPartResult result(TestPartResult::kNonFatalFailure,
|
||||||
"some_file.cc",
|
"some_file.cc",
|
||||||
42,
|
42,
|
||||||
message.GetString().c_str());
|
message.GetString().c_str());
|
||||||
|
|
||||||
EXPECT_EQ(TPRT_NONFATAL_FAILURE, result.type());
|
EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type());
|
||||||
EXPECT_STREQ("some_file.cc", result.file_name());
|
EXPECT_STREQ("some_file.cc", result.file_name());
|
||||||
EXPECT_EQ(42, result.line_number());
|
EXPECT_EQ(42, result.line_number());
|
||||||
EXPECT_STREQ(message.GetString().c_str(), result.message());
|
EXPECT_STREQ(message.GetString().c_str(), result.message());
|
||||||
@ -1417,13 +1414,16 @@ TEST(TestPartResultTest, ConstructorWorks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TestPartResultTest, ResultAccessorsWork) {
|
TEST(TestPartResultTest, ResultAccessorsWork) {
|
||||||
const TestPartResult success(TPRT_SUCCESS, "file.cc", 42, "message");
|
const TestPartResult success(TestPartResult::kSuccess,
|
||||||
|
"file.cc",
|
||||||
|
42,
|
||||||
|
"message");
|
||||||
EXPECT_TRUE(success.passed());
|
EXPECT_TRUE(success.passed());
|
||||||
EXPECT_FALSE(success.failed());
|
EXPECT_FALSE(success.failed());
|
||||||
EXPECT_FALSE(success.nonfatally_failed());
|
EXPECT_FALSE(success.nonfatally_failed());
|
||||||
EXPECT_FALSE(success.fatally_failed());
|
EXPECT_FALSE(success.fatally_failed());
|
||||||
|
|
||||||
const TestPartResult nonfatal_failure(TPRT_NONFATAL_FAILURE,
|
const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure,
|
||||||
"file.cc",
|
"file.cc",
|
||||||
42,
|
42,
|
||||||
"message");
|
"message");
|
||||||
@ -1432,7 +1432,7 @@ TEST(TestPartResultTest, ResultAccessorsWork) {
|
|||||||
EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
|
EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
|
||||||
EXPECT_FALSE(nonfatal_failure.fatally_failed());
|
EXPECT_FALSE(nonfatal_failure.fatally_failed());
|
||||||
|
|
||||||
const TestPartResult fatal_failure(TPRT_FATAL_FAILURE,
|
const TestPartResult fatal_failure(TestPartResult::kFatalFailure,
|
||||||
"file.cc",
|
"file.cc",
|
||||||
42,
|
42,
|
||||||
"message");
|
"message");
|
||||||
@ -1457,10 +1457,14 @@ class TestResultTest : public Test {
|
|||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
// pr1 is for success.
|
// pr1 is for success.
|
||||||
pr1 = new TestPartResult(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!");
|
pr1 = new TestPartResult(TestPartResult::kSuccess,
|
||||||
|
"foo/bar.cc",
|
||||||
|
10,
|
||||||
|
"Success!");
|
||||||
|
|
||||||
// pr2 is for fatal failure.
|
// pr2 is for fatal failure.
|
||||||
pr2 = new TestPartResult(TPRT_FATAL_FAILURE, "foo/bar.cc",
|
pr2 = new TestPartResult(TestPartResult::kFatalFailure,
|
||||||
|
"foo/bar.cc",
|
||||||
-1, // This line number means "unknown"
|
-1, // This line number means "unknown"
|
||||||
"Failure!");
|
"Failure!");
|
||||||
|
|
||||||
@ -3334,9 +3338,9 @@ TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
|
|||||||
DoAssertNoFatalFailureOnFails();
|
DoAssertNoFatalFailureOnFails();
|
||||||
}
|
}
|
||||||
ASSERT_EQ(2, gtest_failures.size());
|
ASSERT_EQ(2, gtest_failures.size());
|
||||||
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(0).type());
|
gtest_failures.GetTestPartResult(0).type());
|
||||||
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(1).type());
|
gtest_failures.GetTestPartResult(1).type());
|
||||||
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
|
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
|
||||||
gtest_failures.GetTestPartResult(0).message());
|
gtest_failures.GetTestPartResult(0).message());
|
||||||
@ -3351,11 +3355,11 @@ TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
|
|||||||
DoExpectNoFatalFailureOnFails();
|
DoExpectNoFatalFailureOnFails();
|
||||||
}
|
}
|
||||||
ASSERT_EQ(3, gtest_failures.size());
|
ASSERT_EQ(3, gtest_failures.size());
|
||||||
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(0).type());
|
gtest_failures.GetTestPartResult(0).type());
|
||||||
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kNonFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(1).type());
|
gtest_failures.GetTestPartResult(1).type());
|
||||||
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kNonFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(2).type());
|
gtest_failures.GetTestPartResult(2).type());
|
||||||
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
|
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
|
||||||
gtest_failures.GetTestPartResult(0).message());
|
gtest_failures.GetTestPartResult(0).message());
|
||||||
@ -3372,9 +3376,9 @@ TEST_F(NoFatalFailureTest, MessageIsStreamable) {
|
|||||||
EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message";
|
EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message";
|
||||||
}
|
}
|
||||||
ASSERT_EQ(2, gtest_failures.size());
|
ASSERT_EQ(2, gtest_failures.size());
|
||||||
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kNonFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(0).type());
|
gtest_failures.GetTestPartResult(0).type());
|
||||||
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
|
EXPECT_EQ(TestPartResult::kNonFatalFailure,
|
||||||
gtest_failures.GetTestPartResult(1).type());
|
gtest_failures.GetTestPartResult(1).type());
|
||||||
EXPECT_PRED_FORMAT2(testing::IsSubstring, "foo",
|
EXPECT_PRED_FORMAT2(testing::IsSubstring, "foo",
|
||||||
gtest_failures.GetTestPartResult(0).message());
|
gtest_failures.GetTestPartResult(0).message());
|
||||||
|
Loading…
Reference in New Issue
Block a user