Kea 2.7.5
run_all.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <stdlib.h>
10
11#include <iostream>
12#include <iomanip>
13
14#include <gtest/gtest.h>
17
18namespace isc {
19namespace util {
20namespace unittests {
21
22int
24 int ret = 0;
25
26 // The catching of exceptions generated in tests is controlled by the
27 // KEATEST_CATCH_EXCEPTION environment variable. Setting this to
28 // 1 enables the catching of exceptions; setting it to 0 disables it.
29 // Anything else causes a message to be printed to stderr and the default
30 // taken. (The default is to catch exceptions if compiling with clang
31 // and false if not.)
32#ifdef __clang__
33 bool catch_exception = true;
34#else
35 bool catch_exception = false;
36#endif
37
38 const char* keatest_catch_exception = getenv("KEATEST_CATCH_EXCEPTION");
39 if (keatest_catch_exception != NULL) {
40 if (strcmp(keatest_catch_exception, "1") == 0) {
41 catch_exception = true;
42 } else if (strcmp(keatest_catch_exception, "0") == 0) {
43 catch_exception = false;
44 } else {
45 std::cerr << "***ERROR: KEATEST_CATCH_EXCEPTION is '"
46 << keatest_catch_exception
47 << "': allowed values are '1' or '0'.\n"
48 << " The default value of "
49 << (catch_exception ?
50 "1 (exception catching enabled)":
51 "0 (exception catching disabled)")
52 << " will be used.\n";
53 }
54 }
55
56 // Actually run the code
57 if (catch_exception) {
58 try {
59 ret = RUN_ALL_TESTS();
60 } catch (const isc::Exception& ex) {
61 // Could output more information with typeid(), but there is no
62 // guarantee that all compilers will support it without an explicit
63 // flag on the command line.
64 std::cerr << "*** Exception derived from isc::exception thrown:\n"
65 << " file: " << ex.getFile() << "\n"
66 << " line: " << ex.getLine() << "\n"
67 << " what: " << ex.what() << std::endl;
68 throw;
69 } catch (const std::exception& ex) {
70 std::cerr << "*** Exception derived from std::exception thrown:\n"
71 << " what: " << ex.what() << std::endl;
72 throw;
73 }
74 } else {
75 // This is a separate path for the case where the exception is not
76 // being caught. Although the other code path re-throws the exception
77 // after catching it, there is no guarantee that the state of the
78 // stack is preserved - a compiler might have unwound the stack to
79 // the point at which the exception is caught. This would prove
80 // awkward if trying to debug the program using a debugger.
81 ret = RUN_ALL_TESTS();
82 }
83
84 return (ret);
85}
86
87} // namespace unittests
88} // namespace util
89} // namespace isc
This is a base class for exceptions thrown from the DNS library module.
int run_all()
Run All Tests.
Definition run_all.cc:23
Defines the logger used by the top-level component of kea-lfc.