File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ function(check_convert _name _input _output _format)
1414 check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format} " "cat/${_output} " )
1515endfunction ()
1616
17+ function (check_warning _name _input _format _expected_stderr)
18+ set (_cmd "$<TARGET_FILE:osmium> cat --no-progress --generator=test cat/${_input} -f ${_format} -o /tmp/test-warning-output.osm --overwrite" )
19+ add_test (
20+ NAME "cat-${_name} "
21+ COMMAND ${CMAKE_COMMAND}
22+ -D cmd:FILEPATH =${_cmd}
23+ -D dir:PATH =${PROJECT_SOURCE_DIR} /test
24+ -D expected_stderr:STRING =${_expected_stderr}
25+ -P ${CMAKE_SOURCE_DIR} /test /cat/run_test_check_stderr.cmake
26+ )
27+ endfunction ()
28+
1729
1830#-----------------------------------------------------------------------------
1931
@@ -26,5 +38,9 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl)
2638check_convert(pbf input1.osm.pbf output1.osm.opl opl)
2739check_convert(opl output1.osm.opl output1.osm.opl opl)
2840
41+ check_warning(warning-xml input -with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output." )
42+ check_warning(warning-pbf input -with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output." )
43+ check_warning(warning-opl input -with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output." )
44+
2945
3046#-----------------------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ #
2+ # Runs a test command and checks that stderr contains expected warning message.
3+ # Used for testing warning functionality.
4+ #
5+
6+ if (NOT cmd)
7+ message (FATAL_ERROR "Variable 'cmd' not defined" )
8+ endif ()
9+
10+ if (NOT dir)
11+ message (FATAL_ERROR "Variable 'dir' not defined" )
12+ endif ()
13+
14+ if (NOT expected_stderr)
15+ message (FATAL_ERROR "Variable 'expected_stderr' not defined" )
16+ endif ()
17+
18+ message ("Executing: ${cmd} " )
19+ separate_arguments (cmd)
20+
21+ execute_process (
22+ COMMAND ${cmd}
23+ WORKING_DIRECTORY ${dir}
24+ RESULT_VARIABLE _return_code
25+ OUTPUT_VARIABLE _stdout
26+ ERROR_VARIABLE _stderr
27+ )
28+
29+ if (NOT _return_code EQUAL 0)
30+ message (FATAL_ERROR "Command failed with return code ${_return_code} " )
31+ endif ()
32+
33+ string (FIND "${_stderr} " "${expected_stderr} " _found_pos)
34+ if (_found_pos EQUAL -1)
35+ message (FATAL_ERROR "Expected stderr message '${expected_stderr} ' not found in stderr output: '${_stderr} '" )
36+ endif ()
37+
38+ message (STATUS "Test passed: Found expected stderr message" )
You can’t perform that action at this time.
0 commit comments