]> git.tdb.fi Git - libs/test.git/commitdiff
Display failure reason after other test output
authorMikko Rasa <tdb@tdb.fi>
Fri, 6 Jul 2012 12:11:57 +0000 (15:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Jul 2012 12:11:57 +0000 (15:11 +0300)
source/test.cpp
source/test.h

index 910853f28da5dcf6da2e42a3ebde74b806bce513..0c2081bf0303c68f4306e5ccce65dfdfafa50bb2 100644 (file)
@@ -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();
@@ -103,6 +104,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<string> lines = split(detail_info, '\n');
@@ -132,7 +140,7 @@ void Test::pass_test()
 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)
index d410377c4793102bb90525d6246fe77e5ca31b80..a6dad93f2dede3c7c6f0460cfec4c7ccd5c1d45c 100644 (file)
@@ -43,6 +43,7 @@ private:
        std::list<Function *> functions;
        std::string detail_info;
        std::string detail_debug;
+       std::string fail_reason;
        bool passed;
 
 protected: