/mordor/test/stdoutlistener.cpp
C++ | 84 lines | 71 code | 12 blank | 1 comment | 10 complexity | 0792e2e20a7ffca14e3cee5932d1679a MD5 | raw file
1// Copyright (c) 2009 - Mozy, Inc. 2 3#include "mordor/predef.h" 4#include "mordor/config.h" 5#include "stdoutlistener.h" 6 7#include <iostream> 8 9#include <boost/exception/all.hpp> 10 11using namespace Mordor; 12using namespace Mordor::Test; 13 14static ConfigVar<bool>::ptr g_include_startime = 15 Config::lookup<bool>("mordor.test.outputstarttime", true, "Print start time in test output"); 16 17StdoutListener::StdoutListener() 18: m_tests(0), 19 m_success(0), 20 m_skip(0) 21{} 22 23void 24StdoutListener::testStarted(const std::string &suite, const std::string &test) 25{ 26 if (test != "<invariant>") 27 ++m_tests; 28 std::cout << "Running "; 29 if( g_include_startime->val() ) 30 std::cout << "(" << time(NULL) << ") "; 31 std::cout << suite << "::" << test << ": "; 32 std::cout.flush(); 33} 34 35void 36StdoutListener::testComplete(const std::string &suite, const std::string &test) 37{ 38 if (test != "<invariant>") 39 ++m_success; 40 std::cout << "OK" << std::endl; 41} 42 43void 44StdoutListener::testSkipped(const std::string &suite, const std::string &test) 45{ 46 if (test != "<invariant>") { 47 ++m_skip; 48 --m_tests; 49 } 50 std::cout << "skipped" << std::endl; 51} 52 53void 54StdoutListener::testAsserted(const std::string &suite, const std::string &test, 55 const Assertion &assertion) 56{ 57 std::cerr << "Assertion: " 58 << boost::current_exception_diagnostic_information() << std::endl; 59 m_failures.push_back(std::make_pair(suite, test)); 60} 61 62void 63StdoutListener::testException(const std::string &suite, const std::string &test) 64{ 65 std::cerr << "Unexpected exception: " 66 << boost::current_exception_diagnostic_information() << std::endl; 67 m_failures.push_back(std::make_pair(suite, test)); 68} 69 70void 71StdoutListener::testsComplete() 72{ 73 std::cout << "Tests complete. " << m_success << "/" << m_tests 74 << " passed, " << m_skip << " skipped." << std::endl; 75 if (!m_failures.empty()) { 76 std::cout << "Failures:" << std::endl; 77 for (std::vector<std::pair<std::string, std::string> >::iterator 78 it = m_failures.begin(); 79 it != m_failures.end(); 80 ++it) 81 std::cout << '\t' << it->first << "::" << it->second 82 << std::endl; 83 } 84}