diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1ee3c3c41..11eec0b14 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,10 +79,5 @@ if(HepMC3_FOUND AND HepPDT_FOUND ) ) endif() -if (nlohmann_json_FOUND) - add_test(NAME convert_events COMMAND edm4hep2json edm4hep_events.root) - set_property(TEST convert_events PROPERTY DEPENDS write_events) - set_test_env(convert_events) -endif() - add_subdirectory(utils) +add_subdirectory(tools) diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt new file mode 100644 index 000000000..2d29513f2 --- /dev/null +++ b/test/tools/CMakeLists.txt @@ -0,0 +1,12 @@ +if (nlohmann_json_FOUND) + add_test(NAME convert_events + COMMAND edm4hep2json ${CMAKE_CURRENT_BINARY_DIR}/../edm4hep_events.root) + set_property(TEST convert_events PROPERTY DEPENDS write_events) + set_test_env(convert_events) + + add_test(NAME test_convert_all_collections + COMMAND python ${CMAKE_CURRENT_LIST_DIR}/test_all_collections.py + ${PROJECT_SOURCE_DIR}/edm4hep.yaml + ${PROJECT_SOURCE_DIR}/tools/include/edm4hep2json.hxx) + set_test_env(test_convert_all_collections) +endif() diff --git a/test/tools/test_all_collections.py b/test/tools/test_all_collections.py new file mode 100644 index 000000000..870ceeb67 --- /dev/null +++ b/test/tools/test_all_collections.py @@ -0,0 +1,44 @@ +''' +Tests if all collection header files are included in the cxx file. +''' + +import sys +import argparse +import yaml + + +def test(yamlfile_path, cxxfile_path): + ''' + Test itself. + Takes two parameters, Podio YAML file location and cxx file to be checked. + ''' + + with open(yamlfile_path, mode='r', encoding="utf-8") as yamlfile: + datamodel = yaml.safe_load(yamlfile) + + with open(cxxfile_path, mode='r', encoding="utf-8") as cxxfile: + cxxfile_lines = cxxfile.readlines() + + datatypes = datamodel['datatypes'] + + for collname in datatypes: + include_string = '#include "' + collname.replace('::', '/') + \ + 'Collection.h"' + include_found = False + for line in cxxfile_lines: + if include_string in line: + include_found = True + + if not include_found: + print('ERROR: Following collection not included in the cxx file.') + print(' ' + collname) + sys.exit(2) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Test all collections') + parser.add_argument('yamlfile') + parser.add_argument('cxxfile') + args = parser.parse_args() + + test(args.yamlfile, args.cxxfile) diff --git a/tools/src/edm4hep2json.cxx b/tools/src/edm4hep2json.cxx index a502e215f..075a656e4 100644 --- a/tools/src/edm4hep2json.cxx +++ b/tools/src/edm4hep2json.cxx @@ -105,7 +105,8 @@ int main(int argc, char** argv) { } if (!std::filesystem::exists(inFilePath)) { - std::cerr << "ERROR: Input .root file can't be read!" << std::endl; + std::cerr << "ERROR: Input .root file can't be read!\n " + << inFilePath << std::endl; return EXIT_FAILURE; }