diff --git a/src/action_class_print.cc b/src/action_class_print.cc index c96e6e22c..366710458 100644 --- a/src/action_class_print.cc +++ b/src/action_class_print.cc @@ -18,6 +18,7 @@ START_CLASS_DEF CLASS = action IMPLEMENTS = destroy;execute + IMPLEMENTS = create_accessor MEMBERS = char *name MEMBERS = char *outname END_CLASS_DEF @@ -36,6 +37,7 @@ or edit "action.class" and rerun ./make_class.pl static void init_class (grib_action_class*); static void destroy (grib_context*,grib_action*); +static int create_accessor(grib_section*,grib_action*,grib_loader*); static int execute(grib_action* a,grib_handle* h); @@ -57,7 +59,7 @@ static grib_action_class _grib_action_class_print = { &destroy, /* destroy */ 0, /* dump */ 0, /* xref */ - 0, /* create_accessor */ + &create_accessor, /* create_accessor */ 0, /* notify_change */ 0, /* reparse */ &execute, /* execute */ @@ -141,3 +143,21 @@ static void destroy(grib_context* context, grib_action* act) grib_context_free_persistent(context, act->name); grib_context_free_persistent(context, act->op); } + +static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) +{ + // ECC-1929: A print statement within the definitions does not + // actually create an accessor. So we just run it + grib_action_print* self = (grib_action_print*)act; + + const int err = execute(act, p->h); + if (err) + grib_context_log(act->context, GRIB_LOG_ERROR, "Print: '%s' (%s)", self->name, grib_get_error_message(err)); + return err; + + // We may want to be forgiving and ignore the error + // if (act->context->debug) { + // return err; + // } + // return GRIB_SUCCESS; +} diff --git a/src/action_class_set_missing.cc b/src/action_class_set_missing.cc index 0907c3760..413551547 100644 --- a/src/action_class_set_missing.cc +++ b/src/action_class_set_missing.cc @@ -14,7 +14,6 @@ START_CLASS_DEF CLASS = action - IMPLEMENTS = dump IMPLEMENTS = destroy;execute MEMBERS = char *name END_CLASS_DEF @@ -32,7 +31,6 @@ or edit "action.class" and rerun ./make_class.pl */ static void init_class (grib_action_class*); -static void dump (grib_action* d, FILE*,int); static void destroy (grib_context*,grib_action*); static int execute(grib_action* a,grib_handle* h); @@ -52,7 +50,7 @@ static grib_action_class _grib_action_class_set_missing = { &init_class, /* init_class */ 0, /* init */ &destroy, /* destroy */ - &dump, /* dump */ + 0, /* dump */ 0, /* xref */ 0, /* create_accessor */ 0, /* notify_change */ @@ -95,17 +93,6 @@ static int execute(grib_action* a, grib_handle* h) return grib_set_missing(h, self->name); } -static void dump(grib_action* act, FILE* f, int lvl) -{ - grib_context_log(act->context, GRIB_LOG_ERROR, "%s %s(): Not implemented", __FILE__, __func__); - // int i = 0; - // const grib_action_set_missing* self = (grib_action_set_missing*)act; - // for (i = 0; i < lvl; i++) - // grib_context_print(act->context, f, " "); - // grib_context_print(act->context, f, self->name); - // printf("\n"); -} - static void destroy(grib_context* context, grib_action* act) { grib_action_set_missing* a = (grib_action_set_missing*)act; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cba77adcd..1bca272ab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -282,7 +282,9 @@ if( HAVE_BUILD_TOOLS ) grib_set_bytes grib_set_force bufr_ecc-556 + codes_assert codes_ecc-1698 + codes_ecc-1929 codes_get_string codes_codetable gts_get diff --git a/tests/codes_assert.sh b/tests/codes_assert.sh new file mode 100755 index 000000000..1bd5c878d --- /dev/null +++ b/tests/codes_assert.sh @@ -0,0 +1,39 @@ +#!/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="codes_assert_test" + +tempOut=temp.$label.txt +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +tempDir=${label}.temp.dir +rm -rf $tempDir +mkdir -p $tempDir/definitions/grib2 +bootfile=$tempDir/definitions/grib2/boot.def +cat $def_dir/grib2/boot.def > $bootfile +echo 'assert( year == 1990 );' >> $bootfile +echo >> $bootfile + +export ECCODES_DEFINITION_PATH=$PWD/$tempDir/definitions +# This will activate the print statement above +${tools_dir}/grib_set -s year=1990 $sample_grib2 /dev/null + +set +e +${tools_dir}/grib_set -s year=1991 $sample_grib2 /dev/null > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "year.*Assertion failure" $tempOut + +# Clean up +rm -rf $tempDir +rm -f $tempOut diff --git a/tests/codes_ecc-1929.sh b/tests/codes_ecc-1929.sh new file mode 100755 index 000000000..c7ed04d3e --- /dev/null +++ b/tests/codes_ecc-1929.sh @@ -0,0 +1,33 @@ +#!/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="codes_ecc-1929_test" + +tempOut=temp.$label.txt +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +tempDir=${label}.temp.dir +rm -rf $tempDir +mkdir -p $tempDir/definitions/grib2 +bootfile=$tempDir/definitions/grib2/boot.def +cat $def_dir/grib2/boot.def > $bootfile +echo 'print "DEBUG: [gridType=] [typeOfLevel=]";' >> $bootfile +echo >> $bootfile + +export ECCODES_DEFINITION_PATH=$PWD/$tempDir/definitions +# This will activate the print statement above +${tools_dir}/grib_get -p edition $sample_grib2 > $tempOut +grep -q "DEBUG: gridType=regular_ll typeOfLevel=surface" $tempOut + +# Clean up +rm -rf $tempDir +rm -f $tempOut diff --git a/tests/grib_filter_fail.sh b/tests/grib_filter_fail.sh index 3f77cf436..dd5aec1f6 100755 --- a/tests/grib_filter_fail.sh +++ b/tests/grib_filter_fail.sh @@ -85,6 +85,17 @@ set -e [ $status -ne 0 ] grep -q "Unable to open file" $tempOut + +# Bad print +# ---------- +set +e +echo 'print ("/") "should fail";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "IO ERROR" $tempOut + + # Signed bits # ----------- cat >$tempFilt <