Skip to content

Commit 86c39d0

Browse files
committed
Add no-warning tests
1 parent ea40f08 commit 86c39d0

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

test/cat/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ function(check_warning _name _input _format _expected_stderr)
2626
)
2727
endfunction()
2828

29+
function(check_no_warning _name _input _format)
30+
set(_cmd "$<TARGET_FILE:osmium> cat --no-progress --generator=test cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/no-warning-${_name}.osm --overwrite")
31+
add_test(
32+
NAME "cat-${_name}"
33+
COMMAND ${CMAKE_COMMAND}
34+
-D cmd:FILEPATH=${_cmd}
35+
-D dir:PATH=${PROJECT_SOURCE_DIR}/test
36+
-P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_no_stderr.cmake
37+
)
38+
endfunction()
39+
2940

3041
#-----------------------------------------------------------------------------
3142

@@ -41,5 +52,8 @@ check_convert(opl output1.osm.opl output1.osm.opl opl)
4152
check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.")
4253
check_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.")
4354

55+
check_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml)
56+
check_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl)
57+
4458

4559
#-----------------------------------------------------------------------------
164 Bytes
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Runs a test command and checks that stderr is empty (no warning message).
3+
# Used for testing that no false positive warnings appear.
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+
message("Executing: ${cmd}")
15+
separate_arguments(cmd)
16+
17+
execute_process(
18+
COMMAND ${cmd}
19+
WORKING_DIRECTORY ${dir}
20+
RESULT_VARIABLE _return_code
21+
OUTPUT_VARIABLE _stdout
22+
ERROR_VARIABLE _stderr
23+
)
24+
25+
if(NOT _return_code EQUAL 0)
26+
message(FATAL_ERROR "Command failed with return code ${_return_code}")
27+
endif()
28+
29+
string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos)
30+
if(NOT _found_pos EQUAL -1)
31+
message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'")
32+
endif()
33+
34+
message(STATUS "Test passed: No warning message found")

test/sort/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ function(check_sort_warning _name _input _format _expected_stderr)
3737
)
3838
endfunction()
3939

40+
function(check_sort_no_warning _name _input _format)
41+
set(_cmd "$<TARGET_FILE:osmium> sort --no-progress --generator=test sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}.osm --overwrite")
42+
add_test(
43+
NAME "sort-${_name}"
44+
COMMAND ${CMAKE_COMMAND}
45+
-D cmd:FILEPATH=${_cmd}
46+
-D dir:PATH=${PROJECT_SOURCE_DIR}/test
47+
-P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake
48+
)
49+
set(_cmd_mp "$<TARGET_FILE:osmium> sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}-mp.osm --overwrite")
50+
add_test(
51+
NAME "sort-${_name}-mp"
52+
COMMAND ${CMAKE_COMMAND}
53+
-D cmd:FILEPATH=${_cmd_mp}
54+
-D dir:PATH=${PROJECT_SOURCE_DIR}/test
55+
-P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake
56+
)
57+
endfunction()
58+
4059

4160
#-----------------------------------------------------------------------------
4261

@@ -56,4 +75,7 @@ check_sort1(history-only-version input-history-only-version.osm output-history-o
5675
check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.")
5776
check_sort_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.")
5877

78+
check_sort_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml)
79+
check_sort_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl)
80+
5981
#-----------------------------------------------------------------------------
401 Bytes
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Runs a test command and checks that stderr is empty (no warning message).
3+
# Used for testing that no false positive warnings appear.
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+
message("Executing: ${cmd}")
15+
separate_arguments(cmd)
16+
17+
execute_process(
18+
COMMAND ${cmd}
19+
WORKING_DIRECTORY ${dir}
20+
RESULT_VARIABLE _return_code
21+
OUTPUT_VARIABLE _stdout
22+
ERROR_VARIABLE _stderr
23+
)
24+
25+
if(NOT _return_code EQUAL 0)
26+
message(FATAL_ERROR "Command failed with return code ${_return_code}")
27+
endif()
28+
29+
string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos)
30+
if(NOT _found_pos EQUAL -1)
31+
message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'")
32+
endif()
33+
34+
message(STATUS "Test passed: No warning message found")

0 commit comments

Comments
 (0)