我是 Google Test 的新手,正在尝试提供的示例。我的问题是,当我引入失败并设置GTEST_BREAK_ON_FAILURE=1
(或使用命令行选项),GTest 将出现段错误。
我正在考虑这个例子 https://code.google.com/p/googletest/source/browse/trunk/samples/sample1_unittest.cc。如果我在任何测试中插入这样的内容,我将开始出现段错误:
EXPECT_EQ(8, 2*3);
只是重申一下,只有当我也设置了GTEST_BREAK_ON_FAILURE=1
。我已经从命令行运行,也使用 gdb 运行。如果未设置该环境变量,则会报告错误,但不会出现段错误。
有什么线索可能导致这个/我做错了什么吗?我一直在寻找类似的问题,但还没有遇到任何问题。
仅供参考,我正在使用在 64 位 CrunchBang Linux 11“Waldorf”上运行的 Google Test 版本 1.7.0。
edit代码示例:
// Tests factorial of positive numbers.
TEST(FactorialTest, Positive) {
EXPECT_EQ(1, Factorial(1));
EXPECT_EQ(2, Factorial(2));
EXPECT_EQ(6, Factorial(3));
EXPECT_EQ(40320, Factorial(8));
}
调试器输出:
(gdb) run
Starting program: /home/yourfavoriteprotein/bin/cpp_unit_test_frameworks/gtest-1.7.0/samples/mytest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Running main() from test_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN ] FactorialTest.Negative
[ OK ] FactorialTest.Negative (0 ms)
[ RUN ] FactorialTest.Zero
[ OK ] FactorialTest.Zero (0 ms)
[ RUN ] FactorialTest.Positive
sample1_unittest.cc:112: Failure
Value of: 2*3
Actual: 6
Expected: 8
Program received signal SIGSEGV, Segmentation fault.
0x0000000000413427 in testing::UnitTest::AddTestPartResult(testing::TestPartResult::Type, char const*, int, std::string const&, std::string const&) ()
(gdb) quit