3730 |
10 Apr 18 |
peter |
// $Id$ |
3730 |
10 Apr 18 |
peter |
2 |
|
3730 |
10 Apr 18 |
peter |
3 |
/* |
3730 |
10 Apr 18 |
peter |
Copyright (C) 2018 Peter Johansson |
3730 |
10 Apr 18 |
peter |
5 |
|
3730 |
10 Apr 18 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3730 |
10 Apr 18 |
peter |
7 |
|
3730 |
10 Apr 18 |
peter |
The yat library is free software; you can redistribute it and/or |
3730 |
10 Apr 18 |
peter |
modify it under the terms of the GNU General Public License as |
3730 |
10 Apr 18 |
peter |
published by the Free Software Foundation; either version 3 of the |
3730 |
10 Apr 18 |
peter |
License, or (at your option) any later version. |
3730 |
10 Apr 18 |
peter |
12 |
|
3730 |
10 Apr 18 |
peter |
The yat library is distributed in the hope that it will be useful, |
3730 |
10 Apr 18 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3730 |
10 Apr 18 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3730 |
10 Apr 18 |
peter |
General Public License for more details. |
3730 |
10 Apr 18 |
peter |
17 |
|
3730 |
10 Apr 18 |
peter |
You should have received a copy of the GNU General Public License |
3730 |
10 Apr 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3730 |
10 Apr 18 |
peter |
20 |
*/ |
3730 |
10 Apr 18 |
peter |
21 |
|
3730 |
10 Apr 18 |
peter |
22 |
#include <config.h> |
3730 |
10 Apr 18 |
peter |
23 |
|
3730 |
10 Apr 18 |
peter |
24 |
#include "Suite.h" |
3730 |
10 Apr 18 |
peter |
25 |
|
3730 |
10 Apr 18 |
peter |
26 |
#include "yat/utility/utility.h" |
3730 |
10 Apr 18 |
peter |
27 |
|
3730 |
10 Apr 18 |
peter |
28 |
#include <exception> |
3730 |
10 Apr 18 |
peter |
29 |
#include <sstream> |
3730 |
10 Apr 18 |
peter |
30 |
|
3730 |
10 Apr 18 |
peter |
31 |
void foo(void); |
3730 |
10 Apr 18 |
peter |
32 |
void bar(void); |
3730 |
10 Apr 18 |
peter |
33 |
|
3730 |
10 Apr 18 |
peter |
34 |
int main(int argc,char* argv[]) |
3730 |
10 Apr 18 |
peter |
35 |
{ |
3730 |
10 Apr 18 |
peter |
36 |
theplu::yat::test::Suite suite(argc, argv); |
3730 |
10 Apr 18 |
peter |
37 |
|
3730 |
10 Apr 18 |
peter |
38 |
bool exception_caught = false; |
3730 |
10 Apr 18 |
peter |
39 |
std::ostringstream os; |
3730 |
10 Apr 18 |
peter |
40 |
try { |
3730 |
10 Apr 18 |
peter |
41 |
foo(); |
3730 |
10 Apr 18 |
peter |
42 |
} |
3730 |
10 Apr 18 |
peter |
43 |
catch (std::exception& error) { |
3730 |
10 Apr 18 |
peter |
44 |
suite.out() << "expected exception caught\n"; |
3730 |
10 Apr 18 |
peter |
45 |
theplu::yat::utility::print_what(error, os); |
3730 |
10 Apr 18 |
peter |
46 |
exception_caught = true; |
3730 |
10 Apr 18 |
peter |
47 |
} |
3730 |
10 Apr 18 |
peter |
48 |
|
3730 |
10 Apr 18 |
peter |
49 |
if (!exception_caught) { |
3730 |
10 Apr 18 |
peter |
50 |
suite.add(false); |
3730 |
10 Apr 18 |
peter |
51 |
suite.err() << "error: no exception thrown\n"; |
3730 |
10 Apr 18 |
peter |
52 |
} |
3730 |
10 Apr 18 |
peter |
53 |
else { |
3730 |
10 Apr 18 |
peter |
54 |
suite.out() << "what():" << os.str(); |
3730 |
10 Apr 18 |
peter |
55 |
std::string message = "Foo Fah\nAge Bar\n"; |
3730 |
10 Apr 18 |
peter |
56 |
if (os.str() != message) { |
3730 |
10 Apr 18 |
peter |
57 |
suite.add(false); |
3730 |
10 Apr 18 |
peter |
58 |
suite.err() << "error: expected: " << message; |
3730 |
10 Apr 18 |
peter |
59 |
} |
3730 |
10 Apr 18 |
peter |
60 |
} |
3730 |
10 Apr 18 |
peter |
61 |
return suite.return_value(); |
3730 |
10 Apr 18 |
peter |
62 |
} |
3730 |
10 Apr 18 |
peter |
63 |
|
3730 |
10 Apr 18 |
peter |
64 |
void foo(void) |
3730 |
10 Apr 18 |
peter |
65 |
{ |
3730 |
10 Apr 18 |
peter |
66 |
try { |
3730 |
10 Apr 18 |
peter |
67 |
bar(); |
3730 |
10 Apr 18 |
peter |
68 |
} |
3730 |
10 Apr 18 |
peter |
69 |
catch (std::exception& e) { |
3730 |
10 Apr 18 |
peter |
70 |
std::throw_with_nested(std::runtime_error("Foo Fah")); |
3730 |
10 Apr 18 |
peter |
71 |
} |
3730 |
10 Apr 18 |
peter |
72 |
} |
3730 |
10 Apr 18 |
peter |
73 |
|
3730 |
10 Apr 18 |
peter |
74 |
|
3730 |
10 Apr 18 |
peter |
75 |
void bar(void) |
3730 |
10 Apr 18 |
peter |
76 |
{ |
3730 |
10 Apr 18 |
peter |
77 |
throw std::runtime_error("Age Bar"); |
3730 |
10 Apr 18 |
peter |
78 |
} |