the Compartmented Robust Posix C++ Unit Test system

Debugging a test

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 0x407765: 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 0x2b0121043250 (LWP 18862)]
[Switching to Thread 0x2b0121043250 (LWP 18862)]

Breakpoint 1, assert_eq_fails::test (this=0x7fff1a3528d0)
    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)