mirror of
https://github.com/google/googletest.git
synced 2025-03-10 17:36:10 +00:00
Merge branch 'master' into python3-tests
This commit is contained in:
commit
a4f57cf49a
4
.clang-format
Normal file
4
.clang-format
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Run manually to reformat a file:
|
||||||
|
# clang-format -i --style=file <file>
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: Google
|
@ -18,8 +18,9 @@ matrix:
|
|||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
sudo : true
|
sudo : true
|
||||||
|
env: TEST_CLANG_FORMAT="yes"
|
||||||
install: ./ci/install-linux.sh && ./ci/log-config.sh
|
install: ./ci/install-linux.sh && ./ci/log-config.sh
|
||||||
script: ./ci/build-linux-bazel.sh
|
script: ./ci/test_format.sh && ./ci/build-linux-bazel.sh
|
||||||
- os: linux
|
- os: linux
|
||||||
group: deprecated-2017Q4
|
group: deprecated-2017Q4
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
@ -65,6 +66,7 @@ addons:
|
|||||||
packages:
|
packages:
|
||||||
- g++-4.9
|
- g++-4.9
|
||||||
- clang-3.9
|
- clang-3.9
|
||||||
|
- clang-format-3.9
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
@ -79,6 +79,7 @@ itself is a valuable contribution.
|
|||||||
To keep the source consistent, readable, diffable and easy to merge,
|
To keep the source consistent, readable, diffable and easy to merge,
|
||||||
we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected
|
we use a fairly rigid coding style, as defined by the [google-styleguide](https://github.com/google/styleguide) project. All patches will be expected
|
||||||
to conform to the style outlined [here](https://google.github.io/styleguide/cppguide.html).
|
to conform to the style outlined [here](https://google.github.io/styleguide/cppguide.html).
|
||||||
|
Use [.clang-format](https://github.com/google/googletest/blob/master/.clang-format) to check your formatting
|
||||||
|
|
||||||
## Requirements for Contributors ###
|
## Requirements for Contributors ###
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ package (as described below):
|
|||||||
* GNU-compatible Make or gmake
|
* GNU-compatible Make or gmake
|
||||||
* POSIX-standard shell
|
* POSIX-standard shell
|
||||||
* POSIX(-2) Regular Expressions (regex.h)
|
* POSIX(-2) Regular Expressions (regex.h)
|
||||||
* A C++98-standard-compliant compiler
|
* A C++11-standard-compliant compiler
|
||||||
|
|
||||||
### Windows Requirements ###
|
### Windows Requirements ###
|
||||||
|
|
||||||
|
33
ci/test_format.sh
Executable file
33
ci/test_format.sh
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "clang-format - checking Code Formatting..."
|
||||||
|
|
||||||
|
if [[ "${TRAVIS_OS_NAME}" == "linux" ]] && \
|
||||||
|
[[ "${TEST_CLANG_FORMAT}" == "yes" ]]; then
|
||||||
|
|
||||||
|
RETURN=0
|
||||||
|
CLANG_FORMAT="clang-format-3.9"
|
||||||
|
|
||||||
|
which clang-format-3.9
|
||||||
|
|
||||||
|
if [ ! -f ".clang-format" ]; then
|
||||||
|
echo ".clang-format file not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILES=`git diff master --name-only | grep -E "\.(cc|cpp|h)$"`
|
||||||
|
|
||||||
|
for FILE in $FILES; do
|
||||||
|
|
||||||
|
$CLANG_FORMAT $FILE | cmp $FILE >/dev/null
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "[!] Clang-Format Found INCORRECT FORMATTING. Please re-format and re-submit. The following file failed: $FILE" >&2
|
||||||
|
RETURN=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $RETURN
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
@ -1189,6 +1189,18 @@ class NativeArray {
|
|||||||
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
GTEST_DISALLOW_ASSIGN_(NativeArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AdditionalMessage {
|
||||||
|
public:
|
||||||
|
AdditionalMessage(const char* message) : msg(message) {}
|
||||||
|
void set(const std::string& message) { msg = message; }
|
||||||
|
operator bool() const { return true; }
|
||||||
|
|
||||||
|
const std::string& get() const { return msg; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string msg;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
@ -1216,43 +1228,58 @@ class NativeArray {
|
|||||||
|
|
||||||
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
if (::testing::internal::ConstCharPtr gtest_msg = "") { \
|
if (::testing::internal::AdditionalMessage message = "") { \
|
||||||
bool gtest_caught_expected = false; \
|
bool gtest_caught_expected = false; \
|
||||||
|
try { \
|
||||||
try { \
|
try { \
|
||||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
} \
|
} catch (expected_exception const&) { \
|
||||||
catch (expected_exception const&) { \
|
|
||||||
gtest_caught_expected = true; \
|
gtest_caught_expected = true; \
|
||||||
|
throw; \
|
||||||
} \
|
} \
|
||||||
catch (...) { \
|
} catch (const std::exception& e) { \
|
||||||
gtest_msg.value = \
|
if (!gtest_caught_expected) { \
|
||||||
"Expected: " #statement " throws an exception of type " \
|
message.set( \
|
||||||
#expected_exception ".\n Actual: it throws a different type."; \
|
"it throws a different type " \
|
||||||
|
"with message: " + \
|
||||||
|
std::string(e.what())); \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
|
} catch (...) { \
|
||||||
if (!gtest_caught_expected) { \
|
if (!gtest_caught_expected) { \
|
||||||
gtest_msg.value = \
|
message.set("it throws a different type."); \
|
||||||
"Expected: " #statement " throws an exception of type " \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||||
#expected_exception ".\n Actual: it throws nothing."; \
|
} \
|
||||||
|
} \
|
||||||
|
if (!gtest_caught_expected) { \
|
||||||
|
message.set("it throws nothing."); \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
} else \
|
} else \
|
||||||
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
|
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \
|
||||||
fail(gtest_msg.value)
|
: fail(("Expected: " #statement \
|
||||||
|
" throws an exception of type " #expected_exception \
|
||||||
|
".\n Actual: " + \
|
||||||
|
message.get()) \
|
||||||
|
.c_str())
|
||||||
|
|
||||||
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
#define GTEST_TEST_NO_THROW_(statement, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
if (::testing::internal::AlwaysTrue()) { \
|
if (::testing::internal::AdditionalMessage message = ".") { \
|
||||||
try { \
|
try { \
|
||||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
|
||||||
} \
|
} catch (const std::exception& e) { \
|
||||||
catch (...) { \
|
message.set(std::string(": ") + e.what()); \
|
||||||
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||||
|
} catch (...) { \
|
||||||
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
|
||||||
} \
|
} \
|
||||||
} else \
|
} else \
|
||||||
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
|
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__) \
|
||||||
fail("Expected: " #statement " doesn't throw an exception.\n" \
|
: fail(("Expected: " #statement " doesn't throw an exception.\n" \
|
||||||
" Actual: it throws.")
|
" Actual: it throws" + \
|
||||||
|
message.get()) \
|
||||||
|
.c_str())
|
||||||
|
|
||||||
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
#define GTEST_TEST_ANY_THROW_(statement, fail) \
|
||||||
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
|
||||||
|
@ -3328,6 +3328,7 @@ TEST_F(SingleEvaluationTest, OtherCases) {
|
|||||||
void ThrowAnInteger() {
|
void ThrowAnInteger() {
|
||||||
throw 1;
|
throw 1;
|
||||||
}
|
}
|
||||||
|
void ThrowAnException(const char* what) { throw std::runtime_error(what); }
|
||||||
|
|
||||||
// Tests that assertion arguments are evaluated exactly once.
|
// Tests that assertion arguments are evaluated exactly once.
|
||||||
TEST_F(SingleEvaluationTest, ExceptionTests) {
|
TEST_F(SingleEvaluationTest, ExceptionTests) {
|
||||||
@ -3370,6 +3371,26 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
|
|||||||
// failed EXPECT_ANY_THROW
|
// failed EXPECT_ANY_THROW
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
|
EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't");
|
||||||
EXPECT_EQ(7, a_);
|
EXPECT_EQ(7, a_);
|
||||||
|
|
||||||
|
// failed EXPECT_THROW std::exception, throws different
|
||||||
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(
|
||||||
|
{ // NOLINT
|
||||||
|
a_++;
|
||||||
|
ThrowAnInteger();
|
||||||
|
},
|
||||||
|
std::exception),
|
||||||
|
"throws a different type");
|
||||||
|
EXPECT_EQ(8, a_);
|
||||||
|
|
||||||
|
// failed EXPECT_THROW, throws std::exception
|
||||||
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(
|
||||||
|
{ // NOLINT
|
||||||
|
a_++;
|
||||||
|
ThrowAnException("blablubb");
|
||||||
|
},
|
||||||
|
bool),
|
||||||
|
"throws a different type with message: blablubb");
|
||||||
|
EXPECT_EQ(9, a_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GTEST_HAS_EXCEPTIONS
|
#endif // GTEST_HAS_EXCEPTIONS
|
||||||
@ -3802,6 +3823,11 @@ TEST(AssertionTest, ASSERT_THROW) {
|
|||||||
ASSERT_THROW(ThrowNothing(), bool),
|
ASSERT_THROW(ThrowNothing(), bool),
|
||||||
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
||||||
" Actual: it throws nothing.");
|
" Actual: it throws nothing.");
|
||||||
|
|
||||||
|
EXPECT_FATAL_FAILURE(
|
||||||
|
ASSERT_THROW(ThrowAnException("b"), bool),
|
||||||
|
"Expected: ThrowAnException(\"b\") throws an exception of type bool.\n"
|
||||||
|
" Actual: it throws a different type with message: b");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests ASSERT_NO_THROW.
|
// Tests ASSERT_NO_THROW.
|
||||||
@ -3810,6 +3836,9 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
|
|||||||
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
|
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()),
|
||||||
"Expected: ThrowAnInteger() doesn't throw an exception."
|
"Expected: ThrowAnInteger() doesn't throw an exception."
|
||||||
"\n Actual: it throws.");
|
"\n Actual: it throws.");
|
||||||
|
EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")),
|
||||||
|
"Expected: ThrowAnException(\"blablubb\") doesn't throw"
|
||||||
|
" an exception.\n Actual: it throws: blablubb");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests ASSERT_ANY_THROW.
|
// Tests ASSERT_ANY_THROW.
|
||||||
@ -4536,13 +4565,17 @@ TEST(ExpectTest, EXPECT_GT) {
|
|||||||
// Tests EXPECT_THROW.
|
// Tests EXPECT_THROW.
|
||||||
TEST(ExpectTest, EXPECT_THROW) {
|
TEST(ExpectTest, EXPECT_THROW) {
|
||||||
EXPECT_THROW(ThrowAnInteger(), int);
|
EXPECT_THROW(ThrowAnInteger(), int);
|
||||||
|
EXPECT_THROW(ThrowAnException(""), std::exception);
|
||||||
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool),
|
||||||
"Expected: ThrowAnInteger() throws an exception of "
|
"Expected: ThrowAnInteger() throws an exception of "
|
||||||
"type bool.\n Actual: it throws a different type.");
|
"type bool.\n Actual: it throws a different type.");
|
||||||
EXPECT_NONFATAL_FAILURE(
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool),
|
||||||
EXPECT_THROW(ThrowNothing(), bool),
|
"Expected: ThrowNothing() throws an exception of "
|
||||||
"Expected: ThrowNothing() throws an exception of type bool.\n"
|
"type bool.\n Actual: it throws nothing.");
|
||||||
" Actual: it throws nothing.");
|
EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool),
|
||||||
|
"Expected: ThrowAnException(\"buuh\") throws an "
|
||||||
|
"exception of type bool.\n Actual: "
|
||||||
|
"it throws a different type with message: buuh");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests EXPECT_NO_THROW.
|
// Tests EXPECT_NO_THROW.
|
||||||
@ -4551,6 +4584,9 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
|
|||||||
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
|
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()),
|
||||||
"Expected: ThrowAnInteger() doesn't throw an "
|
"Expected: ThrowAnInteger() doesn't throw an "
|
||||||
"exception.\n Actual: it throws.");
|
"exception.\n Actual: it throws.");
|
||||||
|
EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blah")),
|
||||||
|
"Expected: ThrowAnException(\"blah\") doesn't "
|
||||||
|
"throw an exception.\n Actual: it throws: blah");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests EXPECT_ANY_THROW.
|
// Tests EXPECT_ANY_THROW.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user