From f823c2b90789248e96e1967e35b51f51b30213ad Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Fri, 1 Jul 2022 22:17:18 -0700 Subject: [PATCH] add cmake tests --- CMakeLists.txt | 12 ++++++++++++ src/Main.cc | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7231cc3..cd3e9e2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,18 @@ endif() +# Test configuration + +enable_testing() + +file(GLOB TestCases ${CMAKE_SOURCE_DIR}/tests/*.test.txt) + +foreach(TestCase IN ITEMS ${TestCases}) + add_test(NAME ${TestCase} COMMAND ${CMAKE_BUILD_DIR}/newserv --replay-log=${TestCase} --config=tests/config.json) +endforeach() + + + # Installation configuration install(TARGETS newserv DESTINATION bin) diff --git a/src/Main.cc b/src/Main.cc index 71b82b7c..a6945b86 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -221,6 +221,7 @@ int main(int argc, char** argv) { string quest_filename; string seed; string key_file_name; + const char* config_filename = "system/config.json"; bool parse_data = false; const char* replay_log_filename = nullptr; for (int x = 1; x < argc; x++) { @@ -257,6 +258,8 @@ int main(int argc, char** argv) { } else if (!strncmp(argv[x], "--replay-log=", 13)) { behavior = Behavior::REPLAY_LOG; replay_log_filename = &argv[x][13]; + } else if (!strncmp(argv[x], "--config=", 9)) { + config_filename = &argv[x][9]; } else { throw invalid_argument(string_printf("unknown option: %s", argv[x])); } @@ -342,7 +345,7 @@ int main(int argc, char** argv) { } config_log.info("Loading configuration"); - auto config_json = JSONObject::parse(load_file("system/config.json")); + auto config_json = JSONObject::parse(load_file(config_filename)); populate_state_from_config(state, config_json); config_log.info("Loading license list");