Catch — demo

// A fully working Catch example.
// This shows two ways of performing set-up in Catch.
// Catch is available at https://github.com/philsquared/Catch

#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do this in one cpp file
#include <catch.hpp>
#include <sstream>

TEST_CASE( "sstream", "[s1]" )
{
  std::ostringstream s;
  s << "0";
  
  SECTION("T1") {
    s << ".T1";
    REQUIRE(s.str() == "0.T1");
  }
  
  SECTION("T2") {
    s << ".T2";
    REQUIRE(s.str() == "0.T2");
  }
  
  SECTION("T3") {
    s << ".T3";
    
    SECTION("TA") {
      s << ".TA";
      REQUIRE(s.str() == "0.T3.TA");
    }
    
    SECTION("TB") {
      s << ".TB";
      REQUIRE(s.str() == "0.T3.TB");
    }
  }
}

struct Fx
{
  std::string s;
  Fx() { s.push_back('1'); }
  ~Fx() { /* */ }
};

TEST_CASE_METHOD(Fx, "string", "[s2]")
{
  REQUIRE(s == "1");
  
  SECTION("S1") {
    s += ".S1";
    REQUIRE(s == "1.S1");
  }
  
  SECTION("S2") {
    s += ".S2";
    
    SECTION("S1") {
      s += ".S1";
      REQUIRE(s == "1.S2.S1");
    }
    
    SECTION("S2") {
      s += ".S2";
      REQUIRE(s == "1.S2.S2");
    }
  }
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.