Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and refactor tests #79

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 22 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ set(shp_LIB_VERSIONINFO "4:0:0")
set(PROJECT_VERSION
"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

set(EG_DATA ${PROJECT_SOURCE_DIR}/tests/shape_eg_data CACHE STRING "")

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# libraries are all shared by default.
Expand Down Expand Up @@ -175,30 +177,13 @@ endif()
if(MSVC)
# TODO(schwehr): How to test on Windows?
set(BUILD_TESTING OFF CACHE BOOL "")
else()
# TODO(schwehr): Temporary work around.
cmake_policy(SET CMP0026 OLD)
endif()

find_program(BASH_EXECUTABLE bash)
find_program(SED_EXECUTABLE sed)
if(BASH_EXECUTABLE AND SED_EXECUTABLE)
if(BASH_EXECUTABLE)
set(BUILD_TESTING ON CACHE BOOL "")
else()
message(STATUS "WARNING: sed or bash not available so disabling testing")
endif()

# For the first series of tests, the user needs to have downloaded
# from http://dl.maptools.org/dl/shapelib/shape_eg_data.zip, unpacked
# that file, and specified the location of that directory with
# the cmake option, -DEG_DATA:PATH=whatever
if(BUILD_TESTING)
if(EG_DATA)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?/u/www/projects/shapelib/eg_data?${EG_DATA}?\n")
else()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sed "")
message(STATUS "WARNING: EG_DATA:PATH not set to point to downloaded eg_data directory so the eg_data part of testing will be ignored.")
endif()
message(STATUS "WARNING: bash not available so disabling testing")
endif()

if(NOT MSVC)
Expand All @@ -221,10 +206,6 @@ foreach(executable ${executables})
set_target_properties(${TOOLS} PROPERTIES
INSTALL_RPATH "@loader_path/${RELATIVE_LIBDIR}")
endif()
if(BUILD_TESTING)
get_target_property(${executable}_LOC ${executable} LOCATION)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?\\./${executable}?${${executable}_LOC}?\n")
endif()
if(NOT MSVC)
target_compile_options(${executable} PRIVATE -Wall -Wextra)
endif()
Expand All @@ -248,46 +229,40 @@ if(BUILD_TESTING)
foreach(executable shptest shputils)
add_executable(${executable} ${executable}.c)
target_link_libraries(${executable} ${PACKAGE})
get_target_property(${executable}_LOC ${executable} LOCATION)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/script.sed "s?\\./${executable}?${${executable}_LOC}?\n")
endforeach(executable shptest shputils)

# Write this as a shell script since execute_process cannot handle
# anything like redirection.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/script.sh "${SED_EXECUTABLE} -f script.sed < $1 >| $2")
execute_process(
COMMAND
${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test1.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test1.sh
)
# Set environment variables defining path to executables being used
function(declare_test_executable TEST TARGETS)
foreach(TARGET ${TARGETS})
string(TOUPPER ${TARGET} NAME)
list(APPEND TEST_ENV ${NAME}=$<TARGET_FILE:${TARGET}>)
endforeach()

execute_process(
COMMAND
${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test2.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test2.sh
)

execute_process(
COMMAND
${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/script.sh ${CMAKE_CURRENT_SOURCE_DIR}/tests/test3.sh ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test3.sh
)
set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${TEST_ENV}")
endfunction()

if(EG_DATA)
# These tests correspond to everything in test1.sh
add_test(
NAME test1
COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test1.sh
COMMAND
${BASH_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tests/test1.sh ${PROJECT_SOURCE_DIR}/tests/expect1.out ${EG_DATA}
)
declare_test_executable(test1 "shpdump;dbfdump")
endif()
# These tests correspond to everything in test2.sh

add_test(
NAME test2
COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test2.sh
COMMAND
${BASH_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tests/test2.sh ${PROJECT_SOURCE_DIR}/tests/expect2.out
)
declare_test_executable(test2 "dbfadd;dbfcreate;dbfdump;shpadd;shpcreate;shpdump;shptest")

# These tests correspond to everything in test3.sh
add_test(
NAME test3
COMMAND ${BASH_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/sed_scripted_test3.sh
COMMAND
${BASH_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tests/test3.sh ${PROJECT_SOURCE_DIR}/tests/expect3.out
)
declare_test_executable(test3 "dbfadd;dbfcreate;dbfdump;shpadd;shpcreate;shpdump")
endif()

include(cmake/contrib.cmake)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ shptest_LDADD = $(top_builddir)/libshp.la
# Tests
TESTS_ENVIRONMENT = top_builddir=$(abs_top_builddir)
# tests/test1.sh requires ftp://gdal.velocet.ca/pub/outgoing/shape_eg_data.zip
TESTS = tests/test2.sh tests/test3.sh
TESTS = tests/test1.sh tests/test2.sh tests/test3.sh
8 changes: 8 additions & 0 deletions cmake/contrib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ if(BUILD_SHAPELIB_CONTRIB)
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if(BUILD_TESTING)
add_test(
NAME contrib
COMMAND
${BASH_EXECUTABLE} ${PROJECT_SOURCE_DIR}/contrib/tests/shpproj.sh ${PROJECT_SOURCE_DIR}/contrib/tests/expect.out
)
declare_test_executable(contrib "dbfadd;dbfcreate;shpadd;shpcreate;shpdump")
endif()
endif()
29 changes: 29 additions & 0 deletions contrib/tests/expect.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Shapefile Type: Point # of Shapes: 5

File Bounds: (-84.15596,34.54927,0,0)
to (-83.521622,34.992767,0,0)

Shape:0 (Point) nVertices=1, nParts=0
Bounds:(-83.5495,34.992401, 0)
to (-83.5495,34.992401, 0)
(-83.5495,34.992401, 0)

Shape:1 (Point) nVertices=1, nParts=0
Bounds:(-83.521622,34.992767, 0)
to (-83.521622,34.992767, 0)
(-83.521622,34.992767, 0)

Shape:2 (Point) nVertices=1, nParts=0
Bounds:(-84.016815,34.67276, 0)
to (-84.016815,34.67276, 0)
(-84.016815,34.67276, 0)

Shape:3 (Point) nVertices=1, nParts=0
Bounds:(-84.15596,34.648624, 0)
to (-84.15596,34.648624, 0)
(-84.15596,34.648624, 0)

Shape:4 (Point) nVertices=1, nParts=0
Bounds:(-83.619515,34.54927, 0)
to (-83.619515,34.54927, 0)
(-83.619515,34.54927, 0)
35 changes: 16 additions & 19 deletions contrib/tests/shpproj.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
#!/bin/bash

testdir="$(dirname "$(readlink -f $0)")"
readonly SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")

rm -f "$testdir/test*"
$top_builddir/shpcreate "$testdir/test" point
"${SHPCREATE:-$top_builddir/shpcreate}" "test" point

$top_builddir/shpadd "$testdir/test" -83.54949956 34.992401
$top_builddir/shpadd "$testdir/test" -83.52162155 34.99276748
$top_builddir/shpadd "$testdir/test" -84.01681518 34.67275985
$top_builddir/shpadd "$testdir/test" -84.15596023 34.64862437
$top_builddir/shpadd "$testdir/test" -83.61951463 34.54927047
"${SHPADD:-$top_builddir/shpadd}" "test" -83.54949956 34.992401
"${SHPADD:-$top_builddir/shpadd}" "test" -83.52162155 34.99276748
"${SHPADD:-$top_builddir/shpadd}" "test" -84.01681518 34.67275985
"${SHPADD:-$top_builddir/shpadd}" "test" -84.15596023 34.64862437
"${SHPADD:-$top_builddir/shpadd}" "test" -83.61951463 34.54927047

$top_builddir/dbfcreate "$testdir/test" -s fd 30
$top_builddir/dbfadd "$testdir/test" "1"
$top_builddir/dbfadd "$testdir/test" "2"
$top_builddir/dbfadd "$testdir/test" "3"
$top_builddir/dbfadd "$testdir/test" "4"
$top_builddir/dbfadd "$testdir/test" "5"
"${DBFCREATE:-$top_builddir/dbfcreate}" "test" -s fd 30
"${DBFADD:-$top_builddir/dbfadd}" "test" "1"
"${DBFADD:-$top_builddir/dbfadd}" "test" "2"
"${DBFADD:-$top_builddir/dbfadd}" "test" "3"
"${DBFADD:-$top_builddir/dbfadd}" "test" "4"
"${DBFADD:-$top_builddir/dbfadd}" "test" "5"

$top_builddir/shpdump -precision 8 "$testdir/test" > "$testdir/test.out"
"${SHPDUMP:-$top_builddir/shpdump}" -precision 8 "test" > "test.out"

result="$(diff "$testdir/test.out")"
if [ "$result" == "" ]; then

if result=$(diff "$SCRIPTDIR/expect.out" "test.out"); then
echo "******* Test Succeeded *********"
rm -f "$testdir/test*"
exit 0
else
echo "******* Test Failed *********"
echo "$result"
rm -f "$testdir/test*"
exit 1
fi
Loading