example22.run-fail.cpp 895 B

1234567891011121314151617181920212223242526272829303132333435
  1. // (C) Copyright Gennadiy Rozental 2011-2015.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //[example_code
  7. #define BOOST_TEST_MODULE example
  8. #include <boost/test/included/unit_test.hpp>
  9. extern void foo( int i );
  10. BOOST_AUTO_TEST_CASE( test_external_interface )
  11. {
  12. for( int i = 3; i >=0; i-- ) {
  13. BOOST_TEST_CHECKPOINT( "Calling 'foo' with i=" << i );
  14. foo( i );
  15. }
  16. }
  17. void goo( int value )
  18. {
  19. BOOST_TEST_CHECKPOINT( "Inside goo with value '" << value << "'");
  20. }
  21. void foo( int i )
  22. {
  23. if( i == 1 )
  24. throw std::runtime_error("Undefined Behaviour ahead!");
  25. // following line may not raise an exception on some compilers:
  26. // Undefined Behaviour is implementation specific
  27. goo( 2/(i-1) );
  28. }
  29. //]