diff --git a/.vscode/settings.json b/.vscode/settings.json index cebeef1..c83a419 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -95,7 +95,8 @@ "regex": "cpp", "source_location": "cpp", "future": "cpp", - "typeindex": "cpp" + "typeindex": "cpp", + "*.in": "c" }, "C_Cpp.errorSquiggles": "enabled" } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b066915..2fcabd4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,15 +17,21 @@ set_target_properties(tests PROPERTIES include(CTest) include(Catch) -catch_discover_tests(tests) -if(AARE_TESTS) - set(TestSources - ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp - ) - target_sources(tests PRIVATE ${TestSources} ) +set(TestSources + ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp + ) +target_sources(tests PRIVATE ${TestSources} ) - #Work around to remove, this is not the way to do it =) - # target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common) - target_link_libraries(tests PRIVATE core aare_compiler_flags) -endif() \ No newline at end of file +#Work around to remove, this is not the way to do it =) +# target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common) +target_link_libraries(tests PRIVATE core aare_compiler_flags) + +catch_discover_tests(tests + # WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/data +) + +#configure a header to pass test file paths +get_filename_component(TEST_FILE_PATH ${PROJECT_SOURCE_DIR}/data ABSOLUTE) +configure_file(test_config.hpp.in test_config.hpp) +target_include_directories(tests PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp index 0191c08..bff163b 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1 +1,17 @@ -//Empty file to satisfy CMake when no other tests are added \ No newline at end of file +#include +#include +#include + +#include "test_config.hpp" + + +TEST_CASE("Test suite can find data assets"){ + auto fpath = test_data_path()/ "test_numpy_file.npy"; + REQUIRE(std::filesystem::exists(fpath)); +} + +TEST_CASE("Test suite can open data assets"){ + auto fpath = test_data_path()/ "test_numpy_file.npy"; + auto f = std::ifstream(fpath, std::ios::binary); + REQUIRE(f.is_open()); +} \ No newline at end of file diff --git a/tests/test_config.hpp.in b/tests/test_config.hpp.in new file mode 100644 index 0000000..7669d49 --- /dev/null +++ b/tests/test_config.hpp.in @@ -0,0 +1,7 @@ +#pragma once +#include + +static constexpr auto test_data_path_str = "@TEST_FILE_PATH@"; +inline auto test_data_path() { + return std::filesystem::path(test_data_path_str); +} \ No newline at end of file