Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ if(openPMD_BUILD_TESTING)
add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED)
target_link_libraries(openPMD::thirdparty::Catch2
INTERFACE Catch2::Catch2)
add_library(openPMD::thirdparty::Catch2WithMain INTERFACE IMPORTED)
target_link_libraries(openPMD::thirdparty::Catch2WithMain
INTERFACE Catch2::Catch2WithMain)
endif()

if(openPMD_HAVE_MPI)
Expand Down Expand Up @@ -770,14 +773,11 @@ if(openPMD_HAVE_PYTHON)
endif()

if(openPMD_BUILD_TESTING)
# compile Catch2 implementation part separately
add_library(CatchRunner ${_openpmd_lib_type}
test/CatchRunner.cpp) # Always MPI_Init with Serial Fallback
add_library(CatchMain ${_openpmd_lib_type}
test/CatchMain.cpp) # Serial only
# CatchRunner: custom main with MPI support for parallel tests
# In Catch2 v3, we link to Catch2 (not Catch2WithMain) since we provide our own main
add_library(CatchRunner ${_openpmd_lib_type} test/CatchRunner.cpp)
openpmd_cxx_required(CatchRunner)
openpmd_cxx_required(CatchMain)
set_target_properties(CatchRunner CatchMain PROPERTIES
set_target_properties(CatchRunner PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
Expand All @@ -788,7 +788,6 @@ if(openPMD_BUILD_TESTING)
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
set_target_properties(CatchRunner PROPERTIES COMPILE_PDB_NAME CatchRunner)
set_target_properties(CatchMain PROPERTIES COMPILE_PDB_NAME CatchMain)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
Expand All @@ -801,20 +800,10 @@ if(openPMD_BUILD_TESTING)
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PDB_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}/${CFG}
)
set_target_properties(CatchMain PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} CatchMain
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PDB_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}/${CFG}
)
endforeach()
endif()
target_compile_options(CatchRunner PUBLIC ${_msvc_options})
target_compile_options(CatchMain PUBLIC ${_msvc_options})
target_link_libraries(CatchRunner PUBLIC openPMD::thirdparty::Catch2)
target_link_libraries(CatchMain PUBLIC openPMD::thirdparty::Catch2)
if(openPMD_HAVE_MPI)
target_link_libraries(CatchRunner PUBLIC ${openPMD_MPI_TARGETS})
target_compile_definitions(CatchRunner PUBLIC openPMD_HAVE_MPI=1)
Expand Down Expand Up @@ -875,9 +864,11 @@ if(openPMD_BUILD_TESTING)
endif()
target_link_libraries(${testname}Tests PRIVATE openPMD)
if(${testname} MATCHES "Parallel.+$")
# Parallel tests use CatchRunner (custom main with MPI)
target_link_libraries(${testname}Tests PRIVATE CatchRunner)
else()
target_link_libraries(${testname}Tests PRIVATE CatchMain)
# Serial tests use Catch2WithMain (provides default main)
target_link_libraries(${testname}Tests PRIVATE openPMD::thirdparty::Catch2WithMain)
endif()

if(${testname} STREQUAL JSON)
Expand Down
15 changes: 11 additions & 4 deletions cmake/dependencies/catch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ function(find_catch2)
if(TARGET Catch2::Catch2)
# nothing to do, target already exists in the superbuild
elseif(openPMD_USE_INTERNAL_CATCH AND openPMD_catch_src)
# Ensure Catch2 is built with PIC so it can be linked into shared libraries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${openPMD_catch_src} _deps/localCatch2-build/)
elseif(openPMD_USE_INTERNAL_CATCH AND (openPMD_catch_tar OR openPMD_catch_branch))
include(FetchContent)
# Ensure Catch2 is built with PIC so it can be linked into shared libraries
# Set as cache variable (only if not already set) so it's picked up by Catch2's CMakeLists.txt
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "Position independent code")
endif()
if(openPMD_catch_tar)
FetchContent_Declare(fetchedCatch2
URL ${openPMD_catch_tar}
Expand All @@ -45,7 +52,7 @@ function(find_catch2)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
#mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FETCHEDCatch2)
elseif(NOT openPMD_USE_INTERNAL_CATCH)
find_package(Catch2 2.13.10 CONFIG REQUIRED)
find_package(Catch2 3.0.0 CONFIG REQUIRED)
message(STATUS "Catch2: Found version '${Catch2_VERSION}'")
endif()
endfunction()
Expand All @@ -56,18 +63,18 @@ set(openPMD_catch_src ""
"Local path to Catch2 source directory (preferred if set)")

# tarball fetcher
set(openPMD_catch_tar "https://github.com/catchorg/Catch2/archive/refs/tags/v2.13.10.tar.gz"
set(openPMD_catch_tar "https://github.com/catchorg/Catch2/archive/refs/tags/v3.11.0.tar.gz"
CACHE STRING
"Remote tarball link to pull and build Catch2 from if(openPMD_USE_INTERNAL_CATCH)")
set(openPMD_catch_tar_hash "SHA256=d54a712b7b1d7708bc7a819a8e6e47b2fde9536f487b89ccbca295072a7d9943"
set(openPMD_catch_tar_hash "SHA256=82fa1cb59dc28bab220935923f7469b997b259eb192fb9355db62da03c2a3137"
CACHE STRING
"Hash checksum of the tarball of Catch2 if(openPMD_USE_INTERNAL_CATCH)")

# Git fetcher
set(openPMD_catch_repo "https://github.com/catchorg/Catch2.git"
CACHE STRING
"Repository URI to pull and build Catch2 from if(openPMD_USE_INTERNAL_CATCH)")
set(openPMD_catch_branch "v2.13.10"
set(openPMD_catch_branch "v3.11.0"
CACHE STRING
"Repository branch for openPMD_catch_repo if(openPMD_USE_INTERNAL_CATCH)")

Expand Down
2 changes: 1 addition & 1 deletion test/AuxiliaryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "openPMD/backend/Writable.hpp"
#include "openPMD/config.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

#include <array>
#include <exception>
Expand Down
22 changes: 0 additions & 22 deletions test/CatchMain.cpp

This file was deleted.

21 changes: 7 additions & 14 deletions test/CatchRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <catch2/catch_session.hpp>

#if openPMD_HAVE_MPI
#include <mpi.h>
Expand All @@ -29,13 +28,10 @@ int main(int argc, char *argv[])
MPI_Init(&argc, &argv);

Catch::Session session;
int result = 0;
int result = session.applyCommandLine(argc, argv);
if (result == 0)
{
// Indicates a command line parsing
result = session.applyCommandLine(argc, argv);
// RT tests
if (result == 0)
result = session.run();
result = session.run();
}
MPI_Finalize();
return result;
Expand All @@ -44,13 +40,10 @@ int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
Catch::Session session;
int result = 0;
int result = session.applyCommandLine(argc, argv);
if (result == 0)
{
// Indicates a command line parsing
result = session.applyCommandLine(argc, argv);
// RT tests
if (result == 0)
result = session.run();
result = session.run();
}
return result;
}
Expand Down
26 changes: 14 additions & 12 deletions test/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include "openPMD/auxiliary/Memory_internal.hpp"
#include "openPMD/auxiliary/UniquePtr.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -1100,7 +1101,7 @@ TEST_CASE("wrapper_test", "[core]")
// it once? value = 43.; mrc2.makeConstant(value);
REQUIRE_THROWS_WITH(
mrc2.makeConstant(value),
Catch::Equals(
Catch::Matchers::Equals(
"A recordComponent can not (yet) be made constant after "
"it has been written."));
std::array<double, 1> moreData = {{112233.}};
Expand All @@ -1121,7 +1122,7 @@ TEST_CASE("wrapper_test", "[core]")
int wrongData = 42;
REQUIRE_THROWS_WITH(
o.iterations[5].meshes["E"]["y"].storeChunkRaw(&wrongData, {0}, {1}),
Catch::Equals(
Catch::Matchers::Equals(
"Datatypes of chunk data (INT) and record component "
"(DOUBLE) do not match."));
std::shared_ptr<double> storeData = std::make_shared<double>(44);
Expand Down Expand Up @@ -1192,7 +1193,7 @@ TEST_CASE("wrapper_test", "[core]")
.particles["electrons"]
.particlePatches["numParticles"][RecordComponent::SCALAR]
.store(idx + 1, 42.),
Catch::Equals(
Catch::Matchers::Equals(
"Datatypes of patch data (DOUBLE) and dataset (" + u64str.str() +
") do not match."));
o.iterations[6]
Expand Down Expand Up @@ -1285,7 +1286,7 @@ TEST_CASE("empty_record_test", "[core]")
"No assumption about contained RecordComponents will be made");
REQUIRE_THROWS_WITH(
o.flush(),
Catch::Equals(
Catch::Matchers::Equals(
"A Record can not be written without any contained "
"RecordComponents: E"));
o.iterations[1].meshes["E"][RecordComponent::SCALAR].resetDataset(
Expand All @@ -1302,28 +1303,29 @@ TEST_CASE("zero_extent_component", "[core]")
auto E_x = o.iterations[1].meshes["E"]["x"];
E_x.setComment("Datasets must contain dimensions.");
// REQUIRE_THROWS_WITH(E_x.resetDataset(Dataset(Datatype::LONG, {})),
// Catch::Equals("Dataset extent must be at least 1D."));
// Catch::Matchers::Equals("Dataset extent must be at
// least 1D."));
REQUIRE_THROWS_WITH(
E_x.makeEmpty<int>(0),
Catch::Equals("Dataset extent must be at least 1D."));
Catch::Matchers::Equals("Dataset extent must be at least 1D."));
E_x.resetDataset(Dataset(Datatype::DOUBLE, {1}));
}

TEST_CASE("no_file_ending", "[core]")
{
REQUIRE_THROWS_WITH(
Series("./new_openpmd_output", Access::CREATE),
Catch::Equals(
Catch::Matchers::Equals(
"Unknown file format! Did you specify a file ending? "
"Specified file name was './new_openpmd_output'."));
REQUIRE_THROWS_WITH(
Series("./new_openpmd_output_%T", Access::CREATE),
Catch::Equals(
Catch::Matchers::Equals(
"Unknown file format! Did you specify a file ending? "
"Specified file name was './new_openpmd_output_%T'."));
REQUIRE_THROWS_WITH(
Series("./new_openpmd_output_%05T", Access::CREATE),
Catch::Equals(
Catch::Matchers::Equals(
"Unknown file format! Did you specify a file ending? "
"Specified file name was './new_openpmd_output_%05T'."));
{
Expand Down Expand Up @@ -1625,7 +1627,7 @@ TEST_CASE("load_chunk_wrong_datatype", "[core]")
read.iterations[0]
.meshes["rho"][RecordComponent::SCALAR]
.loadChunk<double>({0}, {10}),
Catch::Equals(err_msg));
Catch::Matchers::Equals(err_msg));
}
}

Expand Down Expand Up @@ -1694,7 +1696,7 @@ TEST_CASE("DoConvert_single_value_to_vector", "[core]")
REQUIRE(attr.get<std::array<int, 7>>() == arrayint);
REQUIRE_THROWS_WITH(
(attr.get<std::array<int, 8>>()),
Catch::Equals(
Catch::Matchers::Equals(
"getCast: no vector to array conversion possible "
"(wrong requested array size)."));
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/Files_Core/automatic_variable_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#include "CoreTests.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

namespace automatic_variable_encoding
{
Expand Down
2 changes: 1 addition & 1 deletion test/Files_ParallelIO/iterate_nonstreaming_series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "openPMD/IO/ADIOS/macros.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <mpi.h>

namespace iterate_nonstreaming_series
Expand Down
2 changes: 1 addition & 1 deletion test/Files_ParallelIO/read_variablebased_randomaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <numeric>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <optional>

#if openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI
Expand Down
2 changes: 1 addition & 1 deletion test/Files_SerialIO/close_and_reopen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "openPMD/Series.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

namespace close_and_reopen_test
{
Expand Down
2 changes: 1 addition & 1 deletion test/Files_SerialIO/components_without_extent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "openPMD/openPMD.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

#include <memory>
#include <numeric>
Expand Down
3 changes: 2 additions & 1 deletion test/JSONTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include "openPMD/helper/list_series.hpp"
#include "openPMD/openPMD.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

#include <algorithm>
#include <fstream>
Expand Down
3 changes: 2 additions & 1 deletion test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "openPMD/openPMD.hpp"
// @todo change includes
#include "openPMD/auxiliary/OneDimensionalBlockSlicer.hpp"
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

#if !openPMD_HAVE_MPI
TEST_CASE("none", "[parallel]")
Expand Down
7 changes: 4 additions & 3 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/openPMD.hpp"

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -2260,7 +2261,7 @@ inline void fileBased_write_test(const std::string &backend)
Series(
"../samples/subdir/serial_fileBased_write%T." + backend,
Access::READ_WRITE),
Catch::Equals(
Catch::Matchers::Equals(
"Cannot write to a series with inconsistent iteration padding. "
"Please specify '%0<N>T' or open as read-only."));

Expand Down Expand Up @@ -7227,7 +7228,7 @@ TEST_CASE("late_setting_of_iterationencoding", "[serial]")
REQUIRE_THROWS_WITH(
series.setIterationEncoding(
::openPMD::IterationEncoding::fileBased),
Catch::Equals(
Catch::Matchers::Equals(
"Wrong API usage: For fileBased formats the "
"iteration expansion pattern %T must "
"be included in the file name"));
Expand Down
Loading