diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index 57cc63f2..7f06cad0 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -84,3 +84,4 @@ jobs: cd b cmake .. make VERBOSE=1 + make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea4139c..c9dee2be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,3 +179,9 @@ if(BUILD_LIB) DESTINATION ${CONFIG_INSTALL_DESTINATION}) endif() +# Turn on unit testing. +include(CTest) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..be430b7e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +# This is the CMake file for the test directory in the wgrib2 +# project. +# +# Ed Hartnett 3/27/24 + +# Run each shell test. +function(shell_test name) + # Copy the test scripts. + file(COPY "${CMAKE_SOURCE_DIR}/tests/${name}.sh" + DESTINATION ${CMAKE_BINARY_DIR}/tests + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + # Add the shell script as a test. + add_test(NAME ${name}.sh COMMAND bash ${name}.sh) +endfunction() + +# Run these shell tests. +shell_test(run_wgrib2_tests) diff --git a/tests/run_wgrib2_tests.sh b/tests/run_wgrib2_tests.sh new file mode 100644 index 00000000..31e08835 --- /dev/null +++ b/tests/run_wgrib2_tests.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# This is a test script for the wgrib2 project. +# +# Ed Hartnett, 3/27/24 + +set -e +echo "" +echo "*** Running wgrib2 test" + +# Just run executable. For some reason it returns 8. +ls -l ../wgrib2 +../wgrib2/wgrib2 > out.txt && exit 1 +[ $? -ne 8 ] && exit 2 + +echo "*** SUCCESS!" +exit 0