ra-12.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file ra-12.cc
  3. /// @brief Bug or not?
  4. // (c) Daniel Llorens - 2013-2015
  5. // This library is free software; you can redistribute it and/or modify it under
  6. // the terms of the GNU Lesser General Public License as published by the Free
  7. // Software Foundation; either version 3 of the License, or (at your option) any
  8. // later version.
  9. #include <iostream>
  10. #include "ra/format.hh"
  11. // -------------------------------------
  12. // bit from example/throw.cc which FIXME should be easier. Maybe an option in ra/macros.hh.
  13. struct ra_error: public std::exception
  14. {
  15. std::string s;
  16. template <class ... A> ra_error(A && ... a): s(ra::format(std::forward<A>(a) ...)) {}
  17. virtual char const * what() const throw ()
  18. {
  19. return s.c_str();
  20. }
  21. };
  22. #ifdef RA_ASSERT
  23. #error RA_ASSERT is already defined!
  24. #endif
  25. #define RA_ASSERT( cond, ... ) \
  26. { if (!( cond )) throw ra_error("ra:: assert [" STRINGIZE(cond) "]", ##__VA_ARGS__); }
  27. // -------------------------------------
  28. #include "ra/test.hh"
  29. #include "ra/ra.hh"
  30. using std::cout, std::endl, std::flush, ra::TestRecorder;
  31. int main()
  32. {
  33. TestRecorder tr(std::cout);
  34. tr.section("check rank errors with var rank");
  35. {
  36. int x = 0;
  37. try {
  38. ra::Big<int> a = 0;
  39. cout << a.size(0) << endl;
  40. x = 1;
  41. } catch (ra_error & e) {
  42. x = 2;
  43. }
  44. tr.info("caught error").test_eq(2, x);
  45. #undef EXPR
  46. }
  47. return tr.summary();
  48. }