From fbce17e52ba20200123576272a711f4395bca688 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sat, 21 Oct 2023 13:55:27 +0100 Subject: [PATCH] Testing: Comparing thru indexes --- tests/grib_indexing.sh | 26 +++++++++++++++++++++++++- tools/grib_tools.cc | 20 ++++++++++---------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/tests/grib_indexing.sh b/tests/grib_indexing.sh index 453208f62..ee356393d 100755 --- a/tests/grib_indexing.sh +++ b/tests/grib_indexing.sh @@ -13,6 +13,7 @@ label="grib_indexing_test" temp=temp.$label.index.out infile=${data_dir}/index.grib +sample1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl # Writes to "out.gribidx" $EXEC ${test_dir}/grib_indexing ${infile} > $temp @@ -109,9 +110,32 @@ ${tools_dir}/grib_index_build -N -o $tempIndex2 $tempGribFile2 ${tools_dir}/grib_compare -v $tempIndex1 $tempIndex2 rm -f $tempIndex1 $tempIndex2 $tempGribFile1 $tempGribFile2 +# Indexes containing different keys +${tools_dir}/grib_index_build -k date,time -N -o $tempIndex1 $sample1 +${tools_dir}/grib_index_build -k level -N -o $tempIndex2 $sample1 +set +e +${tools_dir}/grib_compare -v $tempIndex1 $tempIndex2 2>$tempOut +status=$? +set -e +[ $status -ne 0 ] +cat $tempOut +grep -q "Indexes contained in the input files have different keys" $tempOut +rm -f $tempIndex1 $tempIndex2 $tempOut + + +${tools_dir}/grib_index_build -k date,time -N -o $tempIndex1 $sample1 +${tools_dir}/grib_index_build -k date,time,level -N -o $tempIndex2 $sample1 +set +e +${tools_dir}/grib_compare -v $tempIndex2 $tempIndex1 2>$tempOut +status=$? +set -e +[ $status -ne 0 ] +cat $tempOut +grep -q "Indexes contained in the input files have different keys" $tempOut +rm -f $tempIndex1 $tempIndex2 $tempOut + # ECC-1516 # --------- -sample1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl ${tools_dir}/grib_index_build -N -o $tempIndex1 $sample1 > /dev/null ${tools_dir}/grib_dump $tempIndex1 >/dev/null diff --git a/tools/grib_tools.cc b/tools/grib_tools.cc index ce038d07f..72122fbd1 100644 --- a/tools/grib_tools.cc +++ b/tools/grib_tools.cc @@ -511,17 +511,17 @@ static int grib_tool_index(grib_runtime_options* options) k2 = k2->next; } if (!found) { - printf("Indexes contained in the input files have different keys\n"); - printf("keys in file %s:\n", f1); + fprintf(stderr, "Indexes contained in the input files have different keys!\n"); + fprintf(stderr, "keys in file %s:\n", f1); k1 = options->index1->keys; while (k1) { - printf("\t%s\n", k1->name); + fprintf(stderr, "\t%s\n", k1->name); k1 = k1->next; } - printf("keys in file %s:\n", f2); + fprintf(stderr, "keys in file %s:\n", f2); k2 = options->index2->keys; while (k2) { - printf("\t%s\n", k2->name); + fprintf(stderr, "\t%s\n", k2->name); k2 = k2->next; } exit(1); @@ -543,17 +543,17 @@ static int grib_tool_index(grib_runtime_options* options) k1 = k1->next; } if (!found) { - printf("Indexes contained in the input files have different keys\n"); - printf("keys in file %s:\n", f2); + fprintf(stderr,"Indexes contained in the input files have different keys!\n"); + fprintf(stderr, "keys in file %s:\n", f2); k2 = options->index2->keys; while (k2) { - printf("\t%s\n", k2->name); + fprintf(stderr, "\t%s\n", k2->name); k2 = k2->next; } - printf("keys in file %s:\n", f1); + fprintf(stderr, "keys in file %s:\n", f1); k1 = options->index1->keys; while (k1) { - printf("\t%s\n", k1->name); + fprintf(stderr, "\t%s\n", k1->name); k1 = k1->next; }