Skip to content

Commit

Permalink
Update VSCode settings and README for Catch2 version handling and con…
Browse files Browse the repository at this point in the history
…figuration
  • Loading branch information
timetravelCat committed Dec 14, 2024
1 parent 65e3583 commit cd9f883
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"c-cpp-flylint.cppcheck.enable": true,
"c-cpp-flylint.flawfinder.enable": true,
"c-cpp-flylint.lizard.enable": true,

"c-cpp-flylint.defines": [ ],
"c-cpp-flylint.defines": [ "Catch2_VERSION_MAJOR=2" ], // "NDEBUG"
"c-cpp-flylint.undefines": [ ],
"c-cpp-flylint.includePaths": [
"${workspaceFolder}/include",
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ This template is designed with a primary focus on enabling individuals to set up
- Check **GitHub Pages** and Select **Deploy from a branch**, Branch as **gh-pages**, **/(root)**.
- Check [***docs workflow***](.github/workflows/docs.yml), [***mkdocs configuration***](mkdocs.yml)

5. Adjust VSCode workspace settings (Optional)
- "c-cpp-flylint.defines"
- "c-cpp-flylint.standard"

---

## 📜 License
Expand Down
9 changes: 8 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ if(NOT Catch2_FOUND)
return()
endif()

set(LibCatch2 Catch2::Catch2)

if(${Catch2_VERSION_MAJOR} GREATER_EQUAL 3)
set(LibCatch2 Catch2::Catch2WithMain)
endif()

# This is a workaround for Catch2 2.13.8
include(Catch)
set(CATCH_BUILD_TESTING OFF CACHE BOOL "Build Catch2's own tests" FORCE)
Expand All @@ -32,8 +38,9 @@ foreach(target ${src})
get_filename_component(target_name ${target} NAME_WE)
add_executable(${target_name} ${target})
target_link_libraries(${target_name} PRIVATE
Catch2::Catch2 # WARN Catch2::Catch2WithMain if you are using newer version of Catch2
${LibCatch2}
${PROJECT_NAME})
target_compile_definitions(${target_name} PRIVATE Catch2_VERSION_MAJOR=${Catch2_VERSION_MAJOR})
add_test(NAME ${target_name} COMMAND ${target_name})
catch_discover_tests(${target_name})
endforeach(target)
8 changes: 7 additions & 1 deletion test/test_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#if defined(Catch2_VERSION_MAJOR) && Catch2_VERSION_MAJOR == 2
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#elif defined(Catch2_VERSION_MAJOR) && Catch2_VERSION_MAJOR == 3
#include <catch2/catch_test_macros.hpp>
#else
#error "Unsupported Catch2 version"
#endif

unsigned int Factorial(unsigned int number) {
return number <= 1 ? number : Factorial(number - 1) * number;
Expand Down

0 comments on commit cd9f883

Please sign in to comment.