diff options
author | Tor Lillqvist <tml@collabora.com> | 2014-04-24 10:32:38 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2014-04-24 10:43:56 +0300 |
commit | ca54d372453fbbea136592bbab2e64d44af46373 (patch) | |
tree | 24cedf8c749e273f0aa9a16893bee0a58a727e47 /sal/cppunittester | |
parent | 70c773d30c1c84da24de4c2c3ddc936575996662 (diff) |
Add a test listener that outputs failures to stderr as they happen
Makes them intermix properly with debugging output from the tested
functionality.
After the test has run, don't repeat the failure messages, just print a short
summary.
Change-Id: I6b491d3a34094df2da11df5e404adb63299de342
Diffstat (limited to 'sal/cppunittester')
-rw-r--r-- | sal/cppunittester/cppunittester.cxx | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx index 68858febcbb8..0888d1bd7836 100644 --- a/sal/cppunittester/cppunittester.cxx +++ b/sal/cppunittester/cppunittester.cxx @@ -37,6 +37,8 @@ #include "sal/main.h" #include "cppunit/CompilerOutputter.h" +#include "cppunit/Exception.h" +#include "cppunit/TestFailure.h" #include "cppunit/TestResult.h" #include "cppunit/TestResultCollector.h" #include "cppunit/TestRunner.h" @@ -130,6 +132,37 @@ public: }; #endif +class LogFailuresAsTheyHappen : public CppUnit::TestListener +{ +public: + virtual void addFailure( const CppUnit::TestFailure &failure ) SAL_OVERRIDE + { + printFailureLocation( failure.sourceLine() ); + printFailedTestName( failure ); + printFailureMessage( failure ); + } + +private: + void printFailureLocation( const CppUnit::SourceLine &sourceLine ) + { + if ( !sourceLine.isValid() ) + std::cerr << "unknown:0:"; + else + std::cerr << sourceLine.fileName() << ":" << sourceLine.lineNumber() << ":"; + } + + void printFailedTestName( const CppUnit::TestFailure &failure ) + { + std::cerr << failure.failedTestName() << std::endl; + } + + void printFailureMessage( const CppUnit::TestFailure &failure ) + { + std::cerr << failure.thrownException()->message().shortDescription() << std::endl; + std::cerr << failure.thrownException()->message().details() << std::endl; + } +}; + //Allow the whole uniting testing framework to be run inside a "Protector" //which knows about uno exceptions, so it can print the content of the //exception before falling over and dying @@ -182,6 +215,9 @@ public: CppUnit::TestResultCollector collector; result.addListener(&collector); + LogFailuresAsTheyHappen logger; + result.addListener(&logger); + #ifdef TIMETESTS TimingListener timer; result.addListener(&timer); @@ -199,7 +235,10 @@ public: for (size_t i = 0; i < protectors.size(); ++i) result.popProtector(); - CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).write(); + if (collector.wasSuccessful()) + CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).printSuccess(); + else + CppUnit::CompilerOutputter(&collector, CppUnit::stdCErr()).printStatistics(); return collector.wasSuccessful(); } virtual bool operator()() const SAL_OVERRIDE |