Skip to content

Instantly share code, notes, and snippets.

@martinmoene
Created December 26, 2014 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinmoene/59450eaa1371f7c25210 to your computer and use it in GitHub Desktop.
Save martinmoene/59450eaa1371f7c25210 to your computer and use it in GitHub Desktop.
Spread lest tests over multiple files
// C++11 - use multiple source files.
#include "lest.hpp"
lest::tests & specifications()
{
static lest::tests tests;
return tests;
}
int main( int argc, char * argv[] )
{
return lest::run( specifications(), lest::texts( argv + 1, argv + argc ) /*, std::cout */ );
}
// cl -nologo -W3 -EHsc -I.. -Felest-module.exe lest-module-1.cpp lest-module-2.cpp lest-module-3.cpp && lest-module
// g++ -Wall -Wextra -std=c++11 -I.. -o lest-module.exe lest-module-1.cpp lest-module-2.cpp lest-module-3.cpp && lest-module
// C++11 - use multiple source files.
#include "lest.hpp"
#include "lest-module.hpp"
const lest::test module[] = {
CASE( "A passing test" "[pass]" )
{
EXPECT( 42 == 42 );
}
};
extern lest::tests & specifications();
lest_ADD_MODULE( specifications(), module )
// C++11 - use multiple source files.
#include "lest.hpp"
#include "lest-module.hpp"
const lest::test module[] = {
CASE( "A failing test" "[fail]" )
{
EXPECT( 42 == 7 );
}
};
extern lest::tests & specifications();
lest_ADD_MODULE( specifications(), module )
// C++11 - use multiple source files.
#include "lest.hpp"
#define lest_ADD_MODULE( collection, module ) \
namespace { lest::module_registrar _( collection, module ); }
namespace lest {
struct module_registrar
{
template <std::size_t N>
module_registrar( lest::tests & collection, test const (&module)[N] )
{
collection.insert( collection.end(), std::begin( module ), std::end( module ) );
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment