Skip to content
Snippets Groups Projects
Commit a9294731 authored by Sam Yates's avatar Sam Yates
Browse files

Better support tests in out-of-tree build.

Add path to data directory by preprocessor definition so that
unit tests can be run from any directory.
parent 9ada48a5
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ set(VALIDATION_SOURCES ...@@ -39,6 +39,7 @@ set(VALIDATION_SOURCES
validate.cpp validate.cpp
) )
add_definitions("-DDATADIR=\"${CMAKE_SOURCE_DIR}/data\"")
add_executable(test.exe ${TEST_SOURCES} ${HEADERS}) add_executable(test.exe ${TEST_SOURCES} ${HEADERS})
add_executable(validate.exe ${VALIDATION_SOURCES} ${HEADERS}) add_executable(validate.exe ${VALIDATION_SOURCES} ${HEADERS})
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include <cell.hpp> #include <cell.hpp>
#include <swcio.hpp> #include <swcio.hpp>
// Path to data directory can be overriden at compile time.
#if !defined(DATADIR)
#define DATADIR "../data"
#endif
// SWC tests // SWC tests
void expect_record_equals(const nest::mc::io::swc_record &expected, void expect_record_equals(const nest::mc::io::swc_record &expected,
const nest::mc::io::swc_record &actual) const nest::mc::io::swc_record &actual)
...@@ -227,7 +232,8 @@ TEST(swc_parser, from_allen_db) ...@@ -227,7 +232,8 @@ TEST(swc_parser, from_allen_db)
{ {
using namespace nest::mc; using namespace nest::mc;
auto fname = "../data/example.swc"; std::string datadir{DATADIR};
auto fname = datadir+"/example.swc";
std::ifstream fid(fname); std::ifstream fid(fname);
if(!fid.is_open()) { if(!fid.is_open()) {
std::cerr << "unable to open file " << fname << "... skipping test\n"; std::cerr << "unable to open file " << fname << "... skipping test\n";
...@@ -493,7 +499,8 @@ TEST(swc_io, cell_construction) ...@@ -493,7 +499,8 @@ TEST(swc_io, cell_construction)
// the one generated with the C++ interface // the one generated with the C++ interface
TEST(swc_parser, from_file_ball_and_stick) TEST(swc_parser, from_file_ball_and_stick)
{ {
auto fname = "../data/ball_and_stick.swc"; std::string datadir{DATADIR};
auto fname = datadir+"/ball_and_stick.swc";
std::ifstream fid(fname); std::ifstream fid(fname);
if(!fid.is_open()) { if(!fid.is_open()) {
std::cerr << "unable to open file " << fname << "... skipping test\n"; std::cerr << "unable to open file " << fname << "... skipping test\n";
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#include <cell_tree.hpp> #include <cell_tree.hpp>
#include "json/src/json.hpp" #include "json/src/json.hpp"
// Path to data directory can be overriden at compile time.
#if !defined(DATADIR)
#define DATADIR "../data"
#endif
using json = nlohmann::json; using json = nlohmann::json;
using range = memory::Range; using range = memory::Range;
...@@ -287,7 +292,10 @@ TEST(cell_tree, balance) { ...@@ -287,7 +292,10 @@ TEST(cell_tree, balance) {
TEST(cell_tree, json_load) TEST(cell_tree, json_load)
{ {
json cell_data; json cell_data;
std::ifstream("../data/cells_small.json") >> cell_data; std::string path{DATADIR};
path += "/cells_small.json";
std::ifstream(path) >> cell_data;
for(auto c : range(0,cell_data.size())) { for(auto c : range(0,cell_data.size())) {
std::vector<int> parent_index = cell_data[c]["parent_index"]; std::vector<int> parent_index = cell_data[c]["parent_index"];
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment