Skip to content

Commit

Permalink
Fuzzers do not require Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sparus committed Feb 15, 2024
1 parent f381e49 commit 0f24d39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(immer_BUILD_TESTS "Build tests" ON)
option(immer_BUILD_EXAMPLES "Build examples" ON)
option(immer_BUILD_DOCS "Build docs" ON)
option(immer_BUILD_EXTRAS "Build extras" ON)
option(immer_INSTALL_FUZZERS "Install fuzzers" off)

set(CXX_STANDARD 14 CACHE STRING "c++ standard number")

Expand Down Expand Up @@ -136,16 +137,16 @@ endif()
# Testing
# =======

if (immer_BUILD_TESTS OR immer_BUILD_EXAMPLES OR immer_BUILD_EXTRAS)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Build and run all the tests and examples.")
endif()

if (immer_BUILD_TESTS)
enable_testing()

find_package(Catch2 REQUIRED)

add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Build and run all the tests and examples.")

add_subdirectory(test)
add_subdirectory(benchmark)
endif()
Expand Down
3 changes: 3 additions & 0 deletions extra/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ foreach(_file IN LISTS immer_fuzzers)
if (CHECK_FUZZERS)
add_test("fuzzer/${_output}" ${_output} -max_total_time=1)
endif()
if (immer_INSTALL_FUZZERS)
install(TARGETS ${_target} DESTINATION bin)
endif()
endforeach()
11 changes: 6 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
};
};

inherit (self.packages.${system}) unit-tests;
inherit (self.packages.${system}) unit-tests fuzzers-debug;
}
// pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
unit-tests-valgrind = self.packages.${system}.unit-tests.overrideAttrs (prev: {
Expand Down Expand Up @@ -94,18 +94,19 @@
default = self.packages.${system}.immer;

fuzzers-debug = (withLLVM self.packages.${system}.immer).overrideAttrs (prev: {
buildInputs = with pkgs; [catch2_3 boehmgc boost fmt];
name = "immer-fuzzers";
# Fuzzers should be built with minimal dependencies to use them easily with OSS-Fuzz
buildInputs = with pkgs; [boehmgc];
nativeBuildInputs = with pkgs; [cmake ninja];
dontBuild = false;
dontStrip = true;
# fuzzers target is not built by default
ninjaFlags = ["fuzzers"];
cmakeBuildType = "Debug";
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Debug"
"-DENABLE_ASAN=ON"
"-Dimmer_BUILD_TESTS=OFF"
"-Dimmer_BUILD_EXAMPLES=OFF"
"-Dimmer_INSTALL_FUZZERS=ON"
"-DENABLE_ASAN=ON"
];
});

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_custom_target(tests
COMMENT "Build all the unit tests.")
add_dependencies(check tests)

find_package(Catch2 REQUIRED)
include(CTest)

file(GLOB_RECURSE immer_unit_tests "*.cpp")
Expand Down

0 comments on commit 0f24d39

Please sign in to comment.