Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
7c598c4f
Commit
7c598c4f
authored
Jul 26, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds ADD_FAILURE_AT (by Zhanyong Wan); disables -Wswitch-default (by Vlad Losev).
parent
598fe228
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
11 deletions
+52
-11
internal_utils.cmake
cmake/internal_utils.cmake
+1
-1
gtest.h
include/gtest/gtest.h
+6
-0
gtest-internal.h
include/gtest/internal/gtest-internal.h
+5
-2
gtest_output_test_.cc
test/gtest_output_test_.cc
+4
-0
gtest_output_test_golden_lin.txt
test/gtest_output_test_golden_lin.txt
+11
-4
gtest_output_test_golden_win.txt
test/gtest_output_test_golden_win.txt
+10
-4
gtest_unittest.cc
test/gtest_unittest.cc
+15
-0
No files found.
cmake/internal_utils.cmake
View file @
7c598c4f
...
@@ -54,7 +54,7 @@ elseif (CMAKE_COMPILER_IS_GNUCXX)
...
@@ -54,7 +54,7 @@ elseif (CMAKE_COMPILER_IS_GNUCXX)
# whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
# whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
# explicitly.
# explicitly.
set
(
cxx_no_rtti_flags
"-fno-rtti -DGTEST_HAS_RTTI=0"
)
set
(
cxx_no_rtti_flags
"-fno-rtti -DGTEST_HAS_RTTI=0"
)
set
(
cxx_strict_flags
"-Wextra
-Wswitch-default
"
)
set
(
cxx_strict_flags
"-Wextra"
)
elseif
(
CMAKE_CXX_COMPILER_ID STREQUAL
"SunPro"
)
elseif
(
CMAKE_CXX_COMPILER_ID STREQUAL
"SunPro"
)
set
(
cxx_exception_flags
"-features=except"
)
set
(
cxx_exception_flags
"-features=except"
)
# Sun Pro doesn't provide macros to indicate whether exceptions and
# Sun Pro doesn't provide macros to indicate whether exceptions and
...
...
include/gtest/gtest.h
View file @
7c598c4f
...
@@ -1627,6 +1627,12 @@ const T* TestWithParam<T>::parameter_ = NULL;
...
@@ -1627,6 +1627,12 @@ const T* TestWithParam<T>::parameter_ = NULL;
// Generates a nonfatal failure with a generic message.
// Generates a nonfatal failure with a generic message.
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
// Generates a nonfatal failure at the given source file location with
// a generic message.
#define ADD_FAILURE_AT(file, line) \
GTEST_MESSAGE_AT_(file, line, "Failed", \
::testing::TestPartResult::kNonFatalFailure)
// Generates a fatal failure with a generic message.
// Generates a fatal failure with a generic message.
#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
...
...
include/gtest/internal/gtest-internal.h
View file @
7c598c4f
...
@@ -1064,10 +1064,13 @@ class NativeArray {
...
@@ -1064,10 +1064,13 @@ class NativeArray {
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
#define GTEST_MESSAGE_
(
message, result_type) \
#define GTEST_MESSAGE_
AT_(file, line,
message, result_type) \
::testing::internal::AssertHelper(result_type,
__FILE__, __LINE__
, message) \
::testing::internal::AssertHelper(result_type,
file, line
, message) \
= ::testing::Message()
= ::testing::Message()
#define GTEST_MESSAGE_(message, result_type) \
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
#define GTEST_FATAL_FAILURE_(message) \
#define GTEST_FATAL_FAILURE_(message) \
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
...
...
test/gtest_output_test_.cc
View file @
7c598c4f
...
@@ -441,6 +441,10 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) {
...
@@ -441,6 +441,10 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) {
<<
"We should never get here, as SetUp() failed."
;
<<
"We should never get here, as SetUp() failed."
;
}
}
TEST
(
AddFailureAtTest
,
MessageContainsSpecifiedFileAndLineNumber
)
{
ADD_FAILURE_AT
(
"foo.cc"
,
42
)
<<
"Expected failure in foo.cc"
;
}
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
// This group of tests verifies that Google Test handles SEH and C++
// This group of tests verifies that Google Test handles SEH and C++
...
...
test/gtest_output_test_golden_lin.txt
View file @
7c598c4f
...
@@ -7,7 +7,7 @@ Expected: true
...
@@ -7,7 +7,7 @@ Expected: true
gtest_output_test_.cc:#: Failure
gtest_output_test_.cc:#: Failure
Value of: 3
Value of: 3
Expected: 2
Expected: 2
[0;32m[==========] [mRunning 6
1 tests from 26
test cases.
[0;32m[==========] [mRunning 6
2 tests from 27
test cases.
[0;32m[----------] [mGlobal test environment set-up.
[0;32m[----------] [mGlobal test environment set-up.
FooEnvironment::SetUp() called.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
...
@@ -235,6 +235,12 @@ gtest_output_test_.cc:#: Failure
...
@@ -235,6 +235,12 @@ gtest_output_test_.cc:#: Failure
Failed
Failed
Expected failure #3, in the test fixture d'tor.
Expected failure #3, in the test fixture d'tor.
[0;31m[ FAILED ] [mFatalFailureInSetUpTest.FailureInSetUp
[0;31m[ FAILED ] [mFatalFailureInSetUpTest.FailureInSetUp
[0;32m[----------] [m1 test from AddFailureAtTest
[0;32m[ RUN ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
foo.cc:42: Failure
Failed
Expected failure in foo.cc
[0;31m[ FAILED ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[0;32m[----------] [m4 tests from MixedUpTestCaseTest
[0;32m[----------] [m4 tests from MixedUpTestCaseTest
[0;32m[ RUN ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
[0;32m[ RUN ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
[0;32m[ OK ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
[0;32m[ OK ] [mMixedUpTestCaseTest.FirstTestFromNamespaceFoo
...
@@ -580,9 +586,9 @@ FooEnvironment::TearDown() called.
...
@@ -580,9 +586,9 @@ FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
gtest_output_test_.cc:#: Failure
Failed
Failed
Expected fatal failure.
Expected fatal failure.
[0;32m[==========] [m6
1 tests from 26
test cases ran.
[0;32m[==========] [m6
2 tests from 27
test cases ran.
[0;32m[ PASSED ] [m21 tests.
[0;32m[ PASSED ] [m21 tests.
[0;31m[ FAILED ] [m4
0
tests, listed below:
[0;31m[ FAILED ] [m4
1
tests, listed below:
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInNestedSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInNestedSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.NonfatalFailureInSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.NonfatalFailureInSubroutine
...
@@ -597,6 +603,7 @@ Expected fatal failure.
...
@@ -597,6 +603,7 @@ Expected fatal failure.
[0;31m[ FAILED ] [mFatalFailureInFixtureConstructorTest.FailureInConstructor
[0;31m[ FAILED ] [mFatalFailureInFixtureConstructorTest.FailureInConstructor
[0;31m[ FAILED ] [mNonFatalFailureInSetUpTest.FailureInSetUp
[0;31m[ FAILED ] [mNonFatalFailureInSetUpTest.FailureInSetUp
[0;31m[ FAILED ] [mFatalFailureInSetUpTest.FailureInSetUp
[0;31m[ FAILED ] [mFatalFailureInSetUpTest.FailureInSetUp
[0;31m[ FAILED ] [mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
...
@@ -624,7 +631,7 @@ Expected fatal failure.
...
@@ -624,7 +631,7 @@ Expected fatal failure.
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
4
0
FAILED TESTS
4
1
FAILED TESTS
[0;33m YOU HAVE 1 DISABLED TEST
[0;33m YOU HAVE 1 DISABLED TEST
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
...
...
test/gtest_output_test_golden_win.txt
View file @
7c598c4f
...
@@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false
...
@@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false
Expected: true
Expected: true
gtest_output_test_.cc:#: error: Value of: 3
gtest_output_test_.cc:#: error: Value of: 3
Expected: 2
Expected: 2
[==========] Running 6
2 tests from 28
test cases.
[==========] Running 6
3 tests from 29
test cases.
[----------] Global test environment set-up.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
...
@@ -173,6 +173,11 @@ Expected failure #2, in TearDown().
...
@@ -173,6 +173,11 @@ Expected failure #2, in TearDown().
gtest_output_test_.cc:#: error: Failed
gtest_output_test_.cc:#: error: Failed
Expected failure #3, in the test fixture d'tor.
Expected failure #3, in the test fixture d'tor.
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[----------] 1 test from AddFailureAtTest
[ RUN ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
foo.cc(42): error: Failed
Expected failure in foo.cc
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[----------] 1 test from ExceptionInFixtureCtorTest
[----------] 1 test from ExceptionInFixtureCtorTest
[ RUN ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
[ RUN ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
(expecting a failure on thrown exception in the test fixture's constructor)
(expecting a failure on thrown exception in the test fixture's constructor)
...
@@ -492,9 +497,9 @@ Expected non-fatal failure.
...
@@ -492,9 +497,9 @@ Expected non-fatal failure.
FooEnvironment::TearDown() called.
FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
gtest_output_test_.cc:#: error: Failed
Expected fatal failure.
Expected fatal failure.
[==========] 6
2 tests from 28
test cases ran.
[==========] 6
3 tests from 29
test cases ran.
[ PASSED ] 21 tests.
[ PASSED ] 21 tests.
[ FAILED ] 4
1
tests, listed below:
[ FAILED ] 4
2
tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
...
@@ -508,6 +513,7 @@ Expected fatal failure.
...
@@ -508,6 +513,7 @@ Expected fatal failure.
[ FAILED ] FatalFailureInFixtureConstructorTest.FailureInConstructor
[ FAILED ] FatalFailureInFixtureConstructorTest.FailureInConstructor
[ FAILED ] NonFatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] NonFatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
[ FAILED ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
[ FAILED ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
[ FAILED ] ExceptionInSetUpTest.ExceptionInSetUp
[ FAILED ] ExceptionInSetUpTest.ExceptionInSetUp
[ FAILED ] ExceptionInTestFunctionTest.SEH
[ FAILED ] ExceptionInTestFunctionTest.SEH
...
@@ -537,7 +543,7 @@ Expected fatal failure.
...
@@ -537,7 +543,7 @@ Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
4
1
FAILED TESTS
4
2
FAILED TESTS
YOU HAVE 1 DISABLED TEST
YOU HAVE 1 DISABLED TEST
Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
...
...
test/gtest_unittest.cc
View file @
7c598c4f
...
@@ -4393,6 +4393,21 @@ TEST(MacroTest, ADD_FAILURE) {
...
@@ -4393,6 +4393,21 @@ TEST(MacroTest, ADD_FAILURE) {
EXPECT_FALSE
(
aborted
);
EXPECT_FALSE
(
aborted
);
}
}
// Tests ADD_FAILURE_AT.
TEST
(
MacroTest
,
ADD_FAILURE_AT
)
{
// Verifies that ADD_FAILURE_AT does generate a nonfatal failure and
// the failure message contains the user-streamed part.
EXPECT_NONFATAL_FAILURE
(
ADD_FAILURE_AT
(
"foo.cc"
,
42
)
<<
"Wrong!"
,
"Wrong!"
);
// Verifies that the user-streamed part is optional.
EXPECT_NONFATAL_FAILURE
(
ADD_FAILURE_AT
(
"foo.cc"
,
42
),
"Failed"
);
// Unfortunately, we cannot verify that the failure message contains
// the right file path and line number the same way, as
// EXPECT_NONFATAL_FAILURE() doesn't get to see the file path and
// line number. Instead, we do that in gtest_output_test_.cc.
}
// Tests FAIL.
// Tests FAIL.
TEST
(
MacroTest
,
FAIL
)
{
TEST
(
MacroTest
,
FAIL
)
{
EXPECT_FATAL_FAILURE
(
FAIL
(),
EXPECT_FATAL_FAILURE
(
FAIL
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment