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 (follow-up) #110

Merged
merged 9 commits into from
Mar 9, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Check
run: make check

- name: Distribution check
run: make distcheck

build-cmake:
name: ${{ matrix.toolchain }}
runs-on: ${{ matrix.os }}
Expand Down
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 @@ -185,30 +187,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 @@ -231,10 +216,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 @@ -255,46 +236,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
73 changes: 71 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,73 @@ EXTRA_DIST = makefile.vc CMakeLists.txt autogen.sh \
cmake/project-config-version.cmake.in \
cmake/project-config.cmake.in \
tests/test1.sh tests/test2.sh tests/test3.sh \
tests/stream1.out tests/stream2.out tests/stream3.out \
tests/expect1.out tests/expect2.out tests/expect3.out \
tests/shape_eg_data/3dpoints.dbf \
tests/shape_eg_data/3dpoints.shp \
tests/shape_eg_data/3dpoints.shx \
tests/shape_eg_data/anno.aux \
tests/shape_eg_data/anno.dbf \
tests/shape_eg_data/anno.shp \
tests/shape_eg_data/anno.shx \
tests/shape_eg_data/brklinz.dbf \
tests/shape_eg_data/brklinz.shp \
tests/shape_eg_data/brklinz.shx \
tests/shape_eg_data/mexico/cities.dbf \
tests/shape_eg_data/mexico/cities.sbn \
tests/shape_eg_data/mexico/cities.sbx \
tests/shape_eg_data/mexico/cities.shp \
tests/shape_eg_data/mexico/cities.shx \
tests/shape_eg_data/csah.dbf \
tests/shape_eg_data/csah.shp \
tests/shape_eg_data/csah.shx \
tests/shape_eg_data/mexico/drainage.dbf \
tests/shape_eg_data/mexico/drainage.sbn \
tests/shape_eg_data/mexico/drainage.sbx \
tests/shape_eg_data/mexico/drainage.shp \
tests/shape_eg_data/mexico/drainage.shx \
tests/shape_eg_data/mexico/lakes.dbf \
tests/shape_eg_data/mexico/lakes.sbn \
tests/shape_eg_data/mexico/lakes.sbx \
tests/shape_eg_data/mexico/lakes.shp \
tests/shape_eg_data/mexico/lakes.shx \
tests/shape_eg_data/masspntz.dbf \
tests/shape_eg_data/masspntz.shp \
tests/shape_eg_data/masspntz.shx \
tests/shape_eg_data/mpatch3.dbf \
tests/shape_eg_data/mpatch3.shp \
tests/shape_eg_data/mpatch3.shx \
tests/shape_eg_data/multipatch.dbf \
tests/shape_eg_data/multipatch.shp \
tests/shape_eg_data/multipatch.shx \
tests/shape_eg_data/multipnt.dbf \
tests/shape_eg_data/multipnt.shp \
tests/shape_eg_data/multipnt.shx \
tests/shape_eg_data/pline.dbf \
tests/shape_eg_data/pline.shp \
tests/shape_eg_data/pline.shx \
tests/shape_eg_data/polygon.dbf \
tests/shape_eg_data/polygon.shp \
tests/shape_eg_data/polygon.shx \
tests/shape_eg_data/mexico/rivers.dbf \
tests/shape_eg_data/mexico/rivers.sbn \
tests/shape_eg_data/mexico/rivers.sbx \
tests/shape_eg_data/mexico/rivers.shp \
tests/shape_eg_data/mexico/rivers.shx \
tests/shape_eg_data/mexico/roads.dbf \
tests/shape_eg_data/mexico/roads.sbn \
tests/shape_eg_data/mexico/roads.sbx \
tests/shape_eg_data/mexico/roads.shp \
tests/shape_eg_data/mexico/roads.shx \
tests/shape_eg_data/mexico/roads_rt.dbf \
tests/shape_eg_data/mexico/roads_rt.sbn \
tests/shape_eg_data/mexico/roads_rt.sbx \
tests/shape_eg_data/mexico/roads_rt.shp \
tests/shape_eg_data/mexico/roads_rt.shx \
tests/shape_eg_data/mexico/states.dbf \
tests/shape_eg_data/mexico/states.sbn \
tests/shape_eg_data/mexico/states.sbx \
tests/shape_eg_data/mexico/states.shp \
tests/shape_eg_data/mexico/states.shx \
web/maptools.css \
web/codepage.html \
web/index.html \
Expand Down Expand Up @@ -79,4 +145,7 @@ 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

clean-local:
-rm -f test*.* s*.out
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()
5 changes: 4 additions & 1 deletion contrib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CONTRIB_CFLAGS = -I$(top_srcdir) -DDEBUG -DDEBUG2

# Extra files to distribute in the source tarball
EXTRA_DIST = makefile.vc tests/shpproj.sh doc/Shape_PointInPoly_README.txt doc/shpsort.txt ShapeFileII.pas
EXTRA_DIST = makefile.vc tests/expect.out tests/shpproj.sh doc/Shape_PointInPoly_README.txt doc/shpsort.txt ShapeFileII.pas

# Installed executables
bin_PROGRAMS = csv2shp dbfcat dbfinfo shpcat shpdxf shpfix shpsort Shape_PointInPoly shpcentrd shpdata shpinfo shpwkb
Expand Down Expand Up @@ -57,3 +57,6 @@ shpwkb_LDADD = $(top_builddir)/libshp.la -lm
# Tests
TESTS_ENVIRONMENT = top_builddir=$(abs_top_builddir)
TESTS = tests/shpproj.sh

clean-local:
-rm -f test.*
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