Testing: Error messages should go to stderr

This commit is contained in:
Shahram Najm 2022-12-21 11:23:48 +00:00
parent f6ff36c09a
commit def66fe512
5 changed files with 11 additions and 12 deletions

View File

@ -14,7 +14,7 @@
* Description: How to decode GRIB2 multi-field messages. * Description: How to decode GRIB2 multi-field messages.
* Try to turn the multi support on and off to * Try to turn the multi support on and off to
* see the difference. Default is OFF. * see the difference. Default is OFF.
* For all the tools default is multi support ON. * For all the tools (e.g., grib_ls etc) multi support is ON.
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>

View File

@ -48,7 +48,7 @@ int main(int argc, char* argv[])
for (i = 0; i < nvalues; i++) { for (i = 0; i < nvalues; i++) {
if (values[i].error == err) name = (char*)values[i].name; if (values[i].error == err) name = (char*)values[i].name;
} }
printf("Error: \"%s\" %s\n", name, codes_get_error_message(err)); fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
} }
values[1].name = "levelll"; values[1].name = "levelll";
@ -57,7 +57,7 @@ int main(int argc, char* argv[])
for (i = 0; i < nvalues; i++) { for (i = 0; i < nvalues; i++) {
if (values[i].error == err) name = (char*)values[i].name; if (values[i].error == err) name = (char*)values[i].name;
} }
printf("Error: \"%s\" %s\n", name, codes_get_error_message(err)); fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
} }
codes_handle_delete(h); codes_handle_delete(h);

View File

@ -10,9 +10,8 @@
. ./include.ctest.sh . ./include.ctest.sh
#Define a common label for all the tmp files # Define a common label for all the tmp files
label="grib_values_check_c" label="grib_values_check_c"
tempOut=${label}.tmp.out
tempErr=${label}.tmp.err tempErr=${label}.tmp.err
tempRef=${label}.tmp.ref tempRef=${label}.tmp.ref
@ -22,11 +21,11 @@ Error: "levelll" Key/value not found
EOF EOF
# Input GRIB file path is hard coded in the example # Input GRIB file path is hard coded in the example
${examples_dir}/c_grib_values_check > $tempOut ${examples_dir}/c_grib_values_check 2> $tempErr
# Compare output with the reference # Compare stderr with the reference
cat $tempOut cat $tempErr
diff $tempRef $tempOut diff $tempRef $tempErr
# Clean up # Clean up
rm -f $tempRef $tempErr $tempOut rm -f $tempRef $tempErr

View File

@ -26,7 +26,7 @@ int main()
numbytes = ni * nj * sizeof(double); numbytes = ni * nj * sizeof(double);
values = (double*)malloc(numbytes); values = (double*)malloc(numbytes);
if (!values) { if (!values) {
printf("Malloc failed - requested %lu bytes\n", (unsigned long)numbytes); fprintf(stderr, "Malloc failed - requested %zu bytes\n", numbytes);
return 1; return 1;
} }

View File

@ -10,7 +10,7 @@
! Description: How to decode GRIB messages containing multiple ! Description: How to decode GRIB messages containing multiple
! fields. Try to turn on and off multi support to ! fields. Try to turn on and off multi support to
! see the difference. Default is OFF. ! see the difference. Default is OFF.
! For all the tools default is multi support ON. ! For all the tools (e.g., grib_ls etc) multi support is ON.
! !
! !
program multi program multi