Boost logo

Boost :

From: Ullrich Koethe (koethe_at_[hidden])
Date: 2000-12-07 18:03:14

Thomas Matelich wrote:
> I've just looked over unittest.h. It provides more structure than test_tools.hpp, a nice job of
> obtaining the minimal xUnit functionality. I think, considering boost's opinions of compiler
> support, the setjmp/longjmp and can't catch signals version should be able to be eliminated.

I don't see how the setjmp/longjmp version could be elimiated (it
probably needs some portability additions, though). The "can't-catch
variant" is present as a last resort for compilers that don't support a
mechanism to catch signals. I've found catching of signals very useful
to quickly locate out-of-bounds access to an array and the like. Without
the setjmp/longjmp, the test propgram would just crash without giving
further information about what happened.

> Here are the tests I would want to see in this tool:
> assert -- or should, accepts bool

This is provided by the current should().

> assertEquals -- with special overloads, esp. double w/ allowed error
> assertThrows -- perhaps templatized. I feel this is very
> important, especially for a library.

This can be added without problems. Currently, I'm doing

  // emulate assertEquals()
  should(int_result == 100);
  double epsilon = 0.00001;
  should(std::abs(double_result - 100.1) < epsilon);


  // emulate assertThrows()
     failTest("somethingThatThrows() failed to throw!");
  catch(MyException & e) // other exceptions are not expected here
     should(strcmp(e.what(), "my error message") == 0);

Of course, this could be further encapsulated. Up to now, I haven't felt
an urgent need to do so, but if "unittest.h" would be accepted into
boost, I certainly would be willing to consider this.


|                                                                |
| Ullrich Koethe  Universität Hamburg / University of Hamburg    |
|                 FB Informatik / Dept. of Computer Science      |
|                 AB Kognitive Systeme / Cognitive Systems Group |
|                                                                |
| Phone: +49 (0)40 42883-2573                Vogt-Koelln-Str. 30 |
| Fax:   +49 (0)40 42883-2572                D - 22527 Hamburg   |
| Email: u.koethe_at_[hidden]               Germany             |
|        koethe_at_[hidden]                        |
| WWW:      |

Boost list run by bdawes at, gregod at, cpdaniel at, john at