set -ea

. ./utils.sh

# Not all Unix shells support this unfortunately
#set -o pipefail

# Unset any environment variable that could interfere with tests
unset ECCODES_EXTRA_DEFINITION_PATH
unset ECCODES_LOG_STREAM
unset ECCODES_FAIL_IF_LOG_MESSAGE
unset ECCODES_DEBUG
unset ECCODES_GRIB_WRITE_ON_FAIL
unset ECCODES_GRIB_DATA_QUALITY_CHECKS
unset ECCODES_GRIB_KEEP_MATRIX
unset ECCODES_GRIB_NO_SPD
unset ECCODES_GRIB_NO_BIG_GROUP_SPLIT
unset ECCODES_GRIB_IEEE_PACKING
unset ECCODES_GRIBEX_MODE_ON
unset ECCODES_BUFRDC_MODE_ON
unset ECCODES_BUFR_SET_TO_MISSING_IF_OUT_OF_RANGE
unset ECCODES_BUFR_MULTI_ELEMENT_CONSTANT_ARRAYS
unset ECCODES_FILE_POOL_MAX_OPENED_FILES
unset ECCODES_IO_BUFFER_SIZE

set -x
echo "Script: $0"

proj_dir=@PROJECT_SOURCE_DIR@
build_dir=@PROJECT_BINARY_DIR@
data_dir=@PROJECT_BINARY_DIR@/data

# use definitions from binary dir to test if installation will be correct
def_dir="@CMAKE_BINARY_DIR@/@ECCODES_DEFINITION_SUFF@"
ECCODES_DEFINITION_PATH="${def_dir}"
export ECCODES_DEFINITION_PATH

# binaries are in the TOP CMAKE_BINARY_DIR
tools_dir=@CMAKE_BINARY_DIR@/bin
bin_dir=@CMAKE_BINARY_DIR@/bin

# If this environment variable is set, then run the
# executables with valgrind. See ECC-746
EXEC=""
if test "x$ECCODES_TEST_WITH_VALGRIND" != "x"; then
  EXEC="valgrind --error-exitcode=1 -q"
  tools_dir="$EXEC @CMAKE_BINARY_DIR@/bin"
fi

# ecCodes tests are in the PROJECT_BINARY_DIR
test_dir=@PROJECT_BINARY_DIR@/tests

# use samples from binary dir to test if installation will be correct
samp_dir="@CMAKE_BINARY_DIR@/@ECCODES_SAMPLES_SUFF@"
ECCODES_SAMPLES_PATH=${samp_dir}
export ECCODES_SAMPLES_PATH

set -u

# Options
HAVE_PRODUCT_BUFR=@HAVE_PRODUCT_BUFR@
HAVE_PRODUCT_GRIB=@HAVE_PRODUCT_GRIB@
HAVE_JPEG=@HAVE_JPEG@
HAVE_LIBJASPER=@HAVE_LIBJASPER@
HAVE_LIBOPENJPEG=@HAVE_LIBOPENJPEG@
HAVE_PNG=@HAVE_PNG@
HAVE_AEC=@HAVE_AEC@
HAVE_GEOGRAPHY=@HAVE_GEOGRAPHY@
HAVE_ECKIT_GEO=@HAVE_ECKIT_GEO@
HAVE_EXTRA_TESTS=@HAVE_EXTRA_TESTS@
HAVE_MEMFS=@HAVE_MEMFS@
ECCODES_ON_WINDOWS=@ECCODES_ON_WINDOWS@

echo "Current directory: `pwd`"
