Testing: Split bufr_filter tests

This commit is contained in:
Shahram Najm 2023-12-25 14:46:39 +00:00
parent 0e6a0083b2
commit b4186bbb48
3 changed files with 97 additions and 80 deletions

View File

@ -188,6 +188,7 @@ if( HAVE_BUILD_TOOLS )
bufr_get
bufr_operators
bufr_filter_misc
bufr_filter_fail
bufr_filter_extract_subsets
bufr_filter_extract_datetime
bufr_filter_extract_area

94
tests/bufr_filter_fail.sh Executable file
View File

@ -0,0 +1,94 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.ctest.sh
label="bufr_filter_fail_test"
cd ${data_dir}/bufr
fBufrTmp=${label}".bufr.tmp"
fRules=${label}.filter
fLog=${label}".log"
tempErr=temp.$label.err
#-----------------------------------------------------------
# Test: with nonexistent keys.
#-----------------------------------------------------------
cat > $fRules <<EOF
set center="98"; #Here centre is misspelled
EOF
# Invoke without -f i.e. should fail if error encountered
set +e
f="syno_1.bufr"
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if key not found" >&2
exit 1
fi
set -e
# Now repeat with -f option (do not exit on error)
${tools_dir}/codes_bufr_filter -f $fRules $f 2>>$fLog 1>>$fLog
#-----------------------------------------------------------
# Test: with not allowed key values
#-----------------------------------------------------------
cat > $fRules <<EOF
set centre=1024; #1024 is out of range (it is 8-bit only)
EOF
# Invoke without -f i.e. should fail if error encountered
set +e
f="syno_1.bufr"
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if key value is not allowed" >&2
exit 1
fi
set -e
# Now repeat with -f option (do not exit on error)
${tools_dir}/codes_bufr_filter -f $fRules $f 2>>$fLog 1>>$fLog
#-----------------------------------------------------------
# Test: with invalid string key
#-----------------------------------------------------------
cat > $fRules <<EOF
set unexpandedDescriptors={1015};
set stationOrSiteName="Caesar non supra grammaticos"; # Too long
set pack=1;
write;
EOF
set +e
f="$ECCODES_SAMPLES_PATH/BUFR4.tmpl"
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if string key is invalid" >&2
exit 1
fi
set -e
# Bad filter
# -----------
set +e
${tools_dir}/bufr_filter a_non_existent_filter_file $ECCODES_SAMPLES_PATH/BUFR4.tmpl > $tempErr 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Cannot include file" $tempErr
# Clean up
rm -f $fLog $fRules $tempErr

View File

@ -8,16 +8,15 @@
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
set -x
. ./include.ctest.sh
cd ${data_dir}/bufr
# Define a common label for all the tmp files
label="bufr_filter_misc_test"
tempErr=temp.$label.err
cd ${data_dir}/bufr
# Create log file
fLog=${label}".log"
rm -f $fLog
@ -518,75 +517,6 @@ diff ${f}.ref ${f}.log
rm -f ${f}.ref ${f}.log
#-----------------------------------------------------------
# Test: with nonexistent keys.
#-----------------------------------------------------------
cat > $fRules <<EOF
set center="98"; #Here centre is misspelled
EOF
# Invoke without -f i.e. should fail if error encountered
set +e
f="syno_1.bufr"
echo "Test: nonexistent keys" >> $fLog
echo "file: $f" >> $fLog
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if key not found" >&2
exit 1
fi
set -e
# Now repeat with -f option (do not exit on error)
${tools_dir}/codes_bufr_filter -f $fRules $f 2>>$fLog 1>>$fLog
#-----------------------------------------------------------
# Test: with not allowed key values
#-----------------------------------------------------------
cat > $fRules <<EOF
set centre=1024; #1024 is out of range (it is 8-bit only)
EOF
# Invoke without -f i.e. should fail if error encountered
set +e
f="syno_1.bufr"
echo "Test: not allowed key values" >> $fLog
echo "file: $f" >> $fLog
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if key value is not allowed" >&2
exit 1
fi
set -e
# Now repeat with -f option (do not exit on error)
${tools_dir}/codes_bufr_filter -f $fRules $f 2>>$fLog 1>>$fLog
#-----------------------------------------------------------
# Test: with invalid string key
#-----------------------------------------------------------
cat > $fRules <<EOF
set unexpandedDescriptors={1015};
set stationOrSiteName="Caesar non supra grammaticos"; # Too long
set pack=1;
write;
EOF
set +e
f="$ECCODES_SAMPLES_PATH/BUFR4.tmpl"
echo "Test: Invalid string key" >> $fLog
${tools_dir}/codes_bufr_filter $fRules $f 2>> $fLog 1>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_filter should have failed if string key is invalid" >&2
exit 1
fi
set -e
#----------------------------------------------------
# Test: format specifier for integer keys
#----------------------------------------------------
@ -1340,14 +1270,6 @@ diff $fRef $fLog
rm -f $fRef
# Bad filter
set +e
${tools_dir}/bufr_filter a_non_existent_filter_file $ECCODES_SAMPLES_PATH/BUFR4.tmpl > $tempErr 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Cannot include file" $tempErr
# Clean up
rm -f ${f}.log ${f}.log.ref ${f}.out $fLog $fRules