Skip to content

Commit

Permalink
Testing: Detect empty concept value
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Apr 22, 2024
1 parent dace02c commit 8a9186a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions definitions/check_grib_defs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ sub process {
}
elsif ($this =~ /'(.*)' *= *{/) {
$concept = $1;
die "File: $filename, line: $lineNum: Value is empty." if ($concept eq '');
die "File: $filename, line: $lineNum: Value contains invalid characters." if (non_printable($concept));
if ($filename eq 'cfVarName.def') {
#if ($concept =~ /^[0-9]/) {
Expand Down
6 changes: 6 additions & 0 deletions tests/grib_check_param_concepts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static int scale_factor_missing(const char* value)
static int grib_check_param_concepts(const char* key, const char* filename)
{
int isLocal = 0;
int count = 0;
grib_concept_value* concept_value = grib_parse_concept_file(NULL, filename);
if (!concept_value)
return GRIB_IO_PROBLEM;
Expand All @@ -67,6 +68,11 @@ static int grib_check_param_concepts(const char* key, const char* filename)
isLocal = 1;
}
while (concept_value) {
count++;
if (strlen(concept_value->name) == 0) {
fprintf(stderr, "%s %s: Empty concept value (count=%d)\n", key, concept_value->name, count);
Assert(0);
}
grib_concept_condition* concept_condition = concept_value->conditions;
/* Convention:
* -1 key not present
Expand Down
9 changes: 6 additions & 3 deletions tests/grib_check_param_concepts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ for a_dataset in $datasets; do
$EXEC ${test_dir}/grib_check_param_concepts shortName $ECCODES_DEFINITION_PATH/grib2/localConcepts/$a_dataset/shortName.def
done

# Check WMO name.def etc
$EXEC ${test_dir}/grib_check_param_concepts name $ECCODES_DEFINITION_PATH/grib2/name.def
$EXEC ${test_dir}/grib_check_param_concepts units $ECCODES_DEFINITION_PATH/grib2/units.def
$EXEC ${test_dir}/grib_check_param_concepts units $ECCODES_DEFINITION_PATH/grib2/cfVarName.def


# Check the group: name.def paramId.def shortName.def units.def cfVarName.def
# ----------------------------------------------------------------------------
# Check whether the Test::More Perl module is available
Expand All @@ -56,11 +62,8 @@ defs_dirs="
$ECCODES_DEFINITION_PATH/grib1/localConcepts/ecmf
$ECCODES_DEFINITION_PATH/grib2/localConcepts/ecmf
$ECCODES_DEFINITION_PATH/grib1/localConcepts/ammc
$ECCODES_DEFINITION_PATH/grib1/localConcepts/eidb
$ECCODES_DEFINITION_PATH/grib1/localConcepts/ekmi
$ECCODES_DEFINITION_PATH/grib1/localConcepts/enmi
$ECCODES_DEFINITION_PATH/grib1/localConcepts/eswi
$ECCODES_DEFINITION_PATH/grib1/localConcepts/lfpw
$ECCODES_DEFINITION_PATH/grib1/localConcepts/lowm
$ECCODES_DEFINITION_PATH/grib1/localConcepts/rjtd
Expand Down

0 comments on commit 8a9186a

Please sign in to comment.