Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_executable(catch catch.cpp)
add_test(NAME catch COMMAND $<TARGET_FILE:catch> --reporter=xml -s --out=${CMAKE_CURRENT_BINARY_DIR}/catch_log.xml)

add_executable(catch2 catch2.cpp)
add_test(NAME catch2 COMMAND $<TARGET_FILE:catch> --reporter=xml -s --out=${CMAKE_CURRENT_BINARY_DIR}/catch2_log.xml)
add_test(NAME catch2 COMMAND $<TARGET_FILE:catch2> --reporter=xml -s --out=${CMAKE_CURRENT_BINARY_DIR}/catch2_log.xml)
22 changes: 12 additions & 10 deletions test/catch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ TEST_CASE("Factorials are computed", "[factorial]" )
TEST_CASE( "vectors can be sized and resized", "[vector][!mayfail]" )
{

std::vector<int> v( 5 );
FAIL("Foobar");
std::vector<int> v( 6 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );

SECTION( "resizing bigger changes size and capacity" )
{
v.resize( 10 );
v.resize( 9 );

REQUIRE( v.size() == 6 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
v.resize( 1 );

REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
Expand All @@ -44,47 +43,50 @@ TEST_CASE( "vectors can be sized and resized", "[vector][!mayfail]" )
REQUIRE( v.capacity() >= 10 );
}
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
v.reserve( 10 );

REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
}

FAIL("This fails");

}

SCENARIO( "vectors can be sized and resized", "[vector]" ) {

GIVEN( "A vector with some items" ) {
std::vector<int> v( 5 );
std::vector<int> v( 9 );

REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );

WHEN( "the size is increased" ) {
v.resize( 10 );
v.resize( 9 );

THEN( "the size and capacity change" ) {
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
}
}
WHEN( "the size is reduced" ) {
v.resize( 0 );
v.resize( 1 );

THEN( "the size changes but not capacity" ) {
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
}
}
WHEN( "more capacity is reserved" ) {
v.reserve( 10 );
v.reserve( 12 );

THEN( "the capacity changes but not the size" ) {
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
}
}
WHEN( "less capacity is reserved" ) {
v.reserve( 0 );
v.reserve( 1 );

THEN( "neither size nor capacity are changed" ) {
REQUIRE( v.size() == 5 );
Expand Down
5 changes: 3 additions & 2 deletions test/catch2.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_RUNTIME_STATIC_REQUIRE
#include <catch2/catch.hpp>
#include <type_traits>

TEST_CASE("STATIC_REQUIRE showcase", "[traits]")
{
STATIC_REQUIRE( std::is_void<void>::value );
STATIC_REQUIRE_FALSE( std::is_void<int>::value );
STATIC_REQUIRE( std::is_void<int>::value );
STATIC_REQUIRE_FALSE( std::is_void<void>::value );
}