From 967a6807d2c5c664579bd2aafbbc13dc3820128a Mon Sep 17 00:00:00 2001 From: Jez Higgins Date: Mon, 11 Jan 2010 17:02:11 +0000 Subject: [PATCH] started work on a JUnit/Ant style XML output format for hooking into Hudson and similar CI servers --- tests/CppUnit/Makefile.am | 5 ++++- tests/CppUnit/TestRunner.cpp | 13 +++++++++++++ tests/CppUnit/textui/TableTestResult.cpp | 4 +--- tests/CppUnit/textui/XmlTestResult.cpp | 9 +++++++++ tests/CppUnit/textui/XmlTestResult.hpp | 14 ++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 tests/CppUnit/textui/XmlTestResult.cpp create mode 100644 tests/CppUnit/textui/XmlTestResult.hpp diff --git a/tests/CppUnit/Makefile.am b/tests/CppUnit/Makefile.am index b461d38d..18619be8 100644 --- a/tests/CppUnit/Makefile.am +++ b/tests/CppUnit/Makefile.am @@ -17,7 +17,10 @@ cppunit_sources = framework/CppUnitException.h \ textui/TextTestResult.cpp \ textui/TextTestResult.h \ textui/TableTestResult.cpp \ - textui/TableTestResult.hpp + textui/TableTestResult.hpp \ + textui/XmlTestResult.cpp \ + textui/XmlTestResult.hpp + silly_string_sources = ../silly_string/silly_string.cpp \ ../silly_string/silly_string.hpp diff --git a/tests/CppUnit/TestRunner.cpp b/tests/CppUnit/TestRunner.cpp index 5455b016..4bf0d1b4 100644 --- a/tests/CppUnit/TestRunner.cpp +++ b/tests/CppUnit/TestRunner.cpp @@ -1,6 +1,7 @@ #include "TestRunner.hpp" #include "textui/TextTestResult.h" #include "textui/TableTestResult.hpp" +#include "textui/XmlTestResult.hpp" #include ////////////////////////////////////////// @@ -45,6 +46,11 @@ bool tablerun(const string& name, Test *test, bool verbose) return run(name, test, verbose); } // tablerun +bool xmlrun(const string& name, Test *test, bool verbose) +{ + return run(name, test, verbose); +} // xmlrun + void printBanner () @@ -85,6 +91,13 @@ bool TestRunner::run(int ac, const char **av) continue; } + if(string(av[i]) == "-xml") + { + runner = xmlrun; + ++opt; + continue; + } + testCase = av[i]; diff --git a/tests/CppUnit/textui/TableTestResult.cpp b/tests/CppUnit/textui/TableTestResult.cpp index a637136a..0515f9fe 100644 --- a/tests/CppUnit/textui/TableTestResult.cpp +++ b/tests/CppUnit/textui/TableTestResult.cpp @@ -1,5 +1,3 @@ - - #include "TableTestResult.hpp" void TableTestResult::print(std::ostream& stream) @@ -11,4 +9,4 @@ void TableTestResult::print(std::ostream& stream) << testFailures() << "\t" << testErrors() << "\t" << testSkips(); -} // print \ No newline at end of file +} // print diff --git a/tests/CppUnit/textui/XmlTestResult.cpp b/tests/CppUnit/textui/XmlTestResult.cpp new file mode 100644 index 00000000..792c7bb6 --- /dev/null +++ b/tests/CppUnit/textui/XmlTestResult.cpp @@ -0,0 +1,9 @@ +#include "XmlTestResult.hpp" + +void XmlTestResult::print(std::ostream& stream) +{ + stream << "\n" + + << ""; + +} // print diff --git a/tests/CppUnit/textui/XmlTestResult.hpp b/tests/CppUnit/textui/XmlTestResult.hpp new file mode 100644 index 00000000..fa1232a1 --- /dev/null +++ b/tests/CppUnit/textui/XmlTestResult.hpp @@ -0,0 +1,14 @@ +#ifndef CPPUNIT_XmlTestResult_HPP +#define CPPUNIT_XmlTestResult_HPP + +#include "TextTestResult.h" + +class XmlTestResult : public TextTestResult +{ +public: + XmlTestResult(const std::string& name, bool verbose) : TextTestResult(name, verbose) { } + + virtual void print(std::ostream& stream); +}; // XmlTestResult + +#endif