X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftest.cpp;h=b4693b294ea57cfaa54194ebf33e79fd0335813a;hb=refs%2Fheads%2Fmaster;hp=ab6e05234302604fa84435c1f147546d39761b31;hpb=1d09b14f91000e9e62bd2a0e7f0be53f2077e59c;p=libs%2Ftest.git diff --git a/source/test.cpp b/source/test.cpp index ab6e052..b4693b2 100644 --- a/source/test.cpp +++ b/source/test.cpp @@ -70,6 +70,7 @@ void Test::run(bool verbose) { detail_info = string(); detail_debug = string(); + fail_reason = string(); passed = false; start_test((*i)->get_description()); const ExceptionCheck *exc_check = (*i)->get_exception_check(); @@ -87,14 +88,26 @@ void Test::run(bool verbose) } catch(const exception &e) { - if(exc_check && exc_check->check(e)) + if(exc_check) { - pass_test(); - debug(Debug::demangle(typeid(e).name())); - debug(e.what()); + if(exc_check->check(e)) + { + pass_test(); + debug(Debug::demangle(typeid(e).name())); + debug(e.what()); + } + else + { + fail_test("Exception of incorrect type thrown"); + debug(format("%s (expected %s)", Debug::demangle(typeid(e).name()), Debug::demangle(exc_check->get_type_info().name()))); + debug(e.what()); + } } else + { + debug(Debug::demangle(typeid(e).name())); fail_test(e.what()); + } } catch(...) { @@ -103,6 +116,13 @@ void Test::run(bool verbose) if(verbose) detail_info += detail_debug; + if(!passed) + { + if(fail_reason.empty()) + detail_info += "Failed without reason"; + else + detail_info += fail_reason; + } if(!detail_info.empty()) { vector lines = split(detail_info, '\n'); @@ -126,13 +146,13 @@ void Test::start_test(const string &descr) void Test::pass_test() { IO::print("\033[32mok\033[0m\n"); - ++passed; + passed = true; } void Test::fail_test(const string &why) { IO::print("\033[31mfailed\033[0m\n"); - IO::print(" %s\n", why); + fail_reason = why; } void Test::expect(bool cond, const string &expr) @@ -152,6 +172,11 @@ void Test::debug(const string &str) detail_debug += format("%s\n", str); } +void Test::fail(const string &why) +{ + throw test_failed(why); +} + Test::Factory::Factory() {