Skip to content

Commit 0ee18f0

Browse files
committed
Add support for CTest (better IDE compatibility)
1 parent f915510 commit 0ee18f0

File tree

14 files changed

+61
-4
lines changed

14 files changed

+61
-4
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,6 @@ if (SQFVM_BUILD_STATIC_LIBRARY_SQC_SUPPORT)
274274
/W4>)
275275
SET_TARGET_PROPERTIES(slibsqfvm_sqc PROPERTIES PREFIX "")
276276
endif ()
277+
278+
enable_testing()
279+
add_subdirectory(tests)

src/cli/cli.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ int cli::cli_from_file(const char* arg0, std::filesystem::path path)
336336
}
337337
catch (std::runtime_error& err)
338338
{
339-
std::cout << err.what() << std::endl;
339+
std::cerr << err.what() << std::endl;
340+
return -1;
341+
}
342+
catch (...)
343+
{
344+
std::cerr << "Unknown exception" << std::endl;
340345
return -1;
341346
}
342347
}

src/cli/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ int main(int argc, char** argv)
106106
auto res = main_actual(argc, argv);
107107
return res;
108108
}
109+
109110
int main_actual(int argc, char** argv)
110111
{
111112
#ifdef WIN32
@@ -126,6 +127,13 @@ int main_actual(int argc, char** argv)
126127
}
127128
#endif // DF__CLI_PRINT_INPUT_ARGS
128129

129-
cli command_line_interface;
130-
return command_line_interface.run(argc, const_cast<const char**>(argv));
130+
try {
131+
cli command_line_interface;
132+
return command_line_interface.run(argc, const_cast<const char**>(argv));
133+
}
134+
catch (std::exception& ex)
135+
{
136+
std::cerr << ex.what() << std::endl;
137+
return -1;
138+
}
131139
}

src/runtime/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ namespace logmessage::runtime
27642764
}
27652765
std::string ContextValuePrint::formatMessage() const
27662766
{
2767-
const auto messageA = "Context droped with return value `"sv;
2767+
const auto messageA = "Context dropped with return value `"sv;
27682768
const auto messageB = "`."sv;
27692769
auto value_sqf = value.to_string_sqf();
27702770

tests/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Register all .sqf tests
2+
3+
set(TEST_CONFIG_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/config.cpp)
4+
5+
function(add_sqf_run_test test_full_path)
6+
get_filename_component(test_name ${test_full_path} NAME_WE)
7+
set(test_full_name run.${test_name})
8+
9+
message("Registering test " ${test_full_path} " as " ${test_full_name})
10+
add_test(
11+
NAME "${test_full_name}"
12+
COMMAND sqfvm -a -V --no-execute-print --input-sqf ${test_full_path} --input-config ${TEST_CONFIG_LOCATION} --max-runtime 10000
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
14+
)
15+
set_tests_properties(${test_full_name} PROPERTIES TIMEOUT 11)
16+
endfunction()
17+
18+
function(add_sqf_preprocess_test test_full_path)
19+
get_filename_component(test_name ${test_full_path} NAME_WE)
20+
set(test_full_name preprocess.${test_name})
21+
22+
message("Registering test " ${test_full_path} " as " ${test_full_name})
23+
add_test(
24+
NAME "${test_full_name}"
25+
COMMAND sqfvm -a -V --no-execute-print --preprocess-file ${test_full_path} --input-config ${TEST_CONFIG_LOCATION} --max-runtime 10000
26+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
27+
)
28+
endfunction()
29+
30+
add_subdirectory(sqf)
31+
add_subdirectory(preprocess)
32+
add_subdirectory(cba)

tests/cba/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_sqf_run_test(${CMAKE_CURRENT_SOURCE_DIR}/cba_a3.sqf)
File renamed without changes.
File renamed without changes.

tests/preprocess/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
file(GLOB_RECURSE test_script_files "*.sqf")
2+
foreach(test_full_path ${test_script_files})
3+
add_sqf_preprocess_test(${test_full_path})
4+
endforeach()

tests/sqf/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
file(GLOB_RECURSE test_script_files "*.sqf")
2+
foreach(test_full_path ${test_script_files})
3+
add_sqf_run_test(${test_full_path})
4+
endforeach()

0 commit comments

Comments
 (0)