2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 5/11/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include "catch_commandline.hpp"
|
2010-11-11 21:42:16 +01:00
|
|
|
#include <limits>
|
2010-11-11 21:56:38 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
2012-08-23 21:08:50 +02:00
|
|
|
inline bool matchesFilters( const std::vector<TestCaseFilters>& filters, const TestCaseInfo& testCase ) {
|
|
|
|
std::vector<TestCaseFilters>::const_iterator it = filters.begin();
|
|
|
|
std::vector<TestCaseFilters>::const_iterator itEnd = filters.end();
|
|
|
|
for(; it != itEnd; ++it )
|
|
|
|
if( !it->shouldInclude( testCase ) )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
inline void List( const ConfigData& config ) {
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-08-13 20:27:03 +02:00
|
|
|
if( config.listSpec & List::Reports ) {
|
2010-11-10 00:24:00 +01:00
|
|
|
std::cout << "Available reports:\n";
|
2012-08-07 08:58:34 +02:00
|
|
|
IReporterRegistry::FactoryMap::const_iterator it = getRegistryHub().getReporterRegistry().getFactories().begin();
|
|
|
|
IReporterRegistry::FactoryMap::const_iterator itEnd = getRegistryHub().getReporterRegistry().getFactories().end();
|
2012-05-16 00:58:23 +02:00
|
|
|
for(; it != itEnd; ++it ) {
|
2010-11-10 00:24:00 +01:00
|
|
|
// !TBD: consider listAs()
|
2010-12-28 14:31:22 +01:00
|
|
|
std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-08-13 20:27:03 +02:00
|
|
|
if( config.listSpec & List::Tests ) {
|
2012-08-23 21:08:50 +02:00
|
|
|
if( config.filters.empty() )
|
2012-08-24 09:23:50 +02:00
|
|
|
std::cout << "All available test cases:\n";
|
2012-08-23 21:08:50 +02:00
|
|
|
else
|
2012-08-24 09:23:50 +02:00
|
|
|
std::cout << "Matching test cases:\n";
|
2012-08-07 08:58:34 +02:00
|
|
|
std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
|
|
|
|
std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
|
2012-08-24 09:23:50 +02:00
|
|
|
std::size_t matchedTests = 0;
|
2012-05-16 00:58:23 +02:00
|
|
|
for(; it != itEnd; ++it ) {
|
2012-08-23 21:08:50 +02:00
|
|
|
if( matchesFilters( config.filters, *it ) ) {
|
2012-08-24 09:23:50 +02:00
|
|
|
matchedTests++;
|
2012-08-23 21:08:50 +02:00
|
|
|
// !TBD: consider listAs()
|
|
|
|
std::cout << "\t" << it->getName() << "\n";
|
|
|
|
if( ( config.listSpec & List::TestNames ) != List::TestNames )
|
|
|
|
std::cout << "\t\t '" << it->getDescription() << "'\n";
|
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2012-08-24 09:23:50 +02:00
|
|
|
if( config.filters.empty() )
|
|
|
|
std::cout << pluralise( matchedTests, "test case" ) << std::endl;
|
|
|
|
else
|
|
|
|
std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2012-05-16 00:58:23 +02:00
|
|
|
|
2012-08-13 20:27:03 +02:00
|
|
|
if( ( config.listSpec & List::All ) == 0 ) {
|
2012-08-23 21:08:50 +02:00
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Unknown list type";
|
|
|
|
throw std::domain_error( oss.str() );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
2010-11-11 21:42:16 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|