Skip to content

Commit 00f056b

Browse files
committed
Add integration tests for sort
1 parent 8fe2800 commit 00f056b

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

test/sort/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ function(check_sort1 _name _input _output _format)
1616
check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}")
1717
endfunction()
1818

19+
function(check_sort_warning _name _input _format _expected_stderr)
20+
set(_cmd "$<TARGET_FILE:osmium> sort --no-progress --generator=test sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output.osm --overwrite")
21+
add_test(
22+
NAME "sort-${_name}"
23+
COMMAND ${CMAKE_COMMAND}
24+
-D cmd:FILEPATH=${_cmd}
25+
-D dir:PATH=${PROJECT_SOURCE_DIR}/test
26+
-D expected_stderr:STRING=${_expected_stderr}
27+
-P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake
28+
)
29+
set(_cmd_mp "$<TARGET_FILE:osmium> sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output-mp.osm --overwrite")
30+
add_test(
31+
NAME "sort-${_name}-mp"
32+
COMMAND ${CMAKE_COMMAND}
33+
-D cmd:FILEPATH=${_cmd_mp}
34+
-D dir:PATH=${PROJECT_SOURCE_DIR}/test
35+
-D expected_stderr:STRING=${_expected_stderr}
36+
-P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake
37+
)
38+
endfunction()
39+
1940

2041
#-----------------------------------------------------------------------------
2142

@@ -32,4 +53,8 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os
3253
check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm)
3354
check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm)
3455

56+
check_sort_warning(warning-xml input-with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output.")
57+
check_sort_warning(warning-pbf input-with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output.")
58+
check_sort_warning(warning-opl input-with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output.")
59+
3560
#-----------------------------------------------------------------------------

test/sort/input-with-locations.osm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<osm version="0.6" upload="false" generator="testdata">
3+
<node id="10" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="1" lon="1"/>
4+
<node id="11" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="2" lon="1"/>
5+
<node id="12" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1" lat="3" lon="1"/>
6+
<way id="20" version="1" timestamp="2015-01-01T01:00:00Z" uid="1" user="test" changeset="1">
7+
<nd ref="10" lat="1" lon="1"/>
8+
<nd ref="11" lat="2" lon="1"/>
9+
<nd ref="12" lat="3" lon="1"/>
10+
<tag k="highway" v="primary"/>
11+
</way>
12+
</osm>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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")

0 commit comments

Comments
 (0)