the Compartmented Robust Posix C++ Unit Test system | hosted by |
---|
The easiest way to debug a single test, is to run it with the
-s
command line parameter, which prevents it from being spawned as
a separate process.
A break point can then be set on
testcasename::test()
Example: To debug the test case assert_eq_fails in
#include <crpcut.hpp> struct a { a(int val) : n(val) {} int n; operator int() const { return n; } }; TEST(assert_eq_succeeds) { a val1(3); int val2 = 5; ASSERT_EQ(val1, val2 - 2); } TEST(assert_eq_fails) { a val1(3); int val2 = 4; ASSERT_EQ(val1, val2 - 2); } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
run
bash > gdb ./test/assert_eq_fails GNU gdb 6.8 Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu"... (gdb) break assert_eq_fails::test() Breakpoint 1 at 0x407c25: file /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp, line 45. (gdb) run -s assert_eq_fails Starting program: /var/tmp/build/test/assert_eq_fails -s assert_eq_fails [Thread debugging using libthread_db enabled] [New Thread 0x2b7e009ff250 (LWP 22251)] [Switching to Thread 0x2b7e009ff250 (LWP 22251)] Breakpoint 1, assert_eq_fails::test (this=0x7fffe9a3ed20) at /home/bjorn/devel/crpcut/doc-src/samples/assert_eq_fails.cpp:45 45 a val1(3); (gdb) n 46 int val2 = 4; (gdb) n 47 ASSERT_EQ(val1, val2 - 2); (gdb) print val1 $1 = {n = 3} (gdb) print val2 - 2 $2 = 2 (gdb) quit The program is running. Exit anyway? (y or n)