• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 020-TestCase-1.cpp
2 
3 // In a Catch project with multiple files, dedicate one file to compile the
4 // source code of Catch itself and reuse the resulting object file for linking.
5 
6 // Let Catch provide main():
7 #define CATCH_CONFIG_MAIN
8 
9 #include <catch2/catch.hpp>
10 
11 TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) {
12 }
13 
14 // ^^^
15 // Normally no TEST_CASEs in this file.
16 // Here just to show there are two source files via option --list-tests.
17 
18 // Compile & run:
19 // - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp
20 // - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 020-TestCase TestCase-1.o 020-TestCase-2.cpp && 020-TestCase --success
21 //
22 // - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 020-TestCase-1.cpp
23 // - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -Fe020-TestCase.exe 020-TestCase-1.obj 020-TestCase-2.cpp && 020-TestCase --success
24 
25 // Expected test case listing:
26 //
27 // prompt> 020-TestCase --list-tests *
28 // Matching test cases:
29 //   1: All test cases reside in other .cpp files (empty)
30 //       [multi-file:1]
31 //   2: Factorial of 0 is computed (fail)
32 //       [multi-file:2]
33 //   2: Factorials of 1 and higher are computed (pass)
34 //       [multi-file:2]
35 // 3 matching test cases
36