020-TestCase-1.cpp 1.2 KB

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