Tools: Test for error conditions

This commit is contained in:
Shahram Najm 2023-08-08 10:41:36 +01:00
parent 28ece2bbdb
commit 1a9b2f87e8
2 changed files with 27 additions and 17 deletions

View File

@ -50,10 +50,20 @@ centre=`${tools_dir}/grib_get -p centre:l $outfile`
# Set without -s. Expected to fail
# ----------------------------------------------------
set +e
${tools_dir}/grib_set -p levtype $infile $outfile 2> $REDIRECT > $REDIRECT
${tools_dir}/grib_set -p levtype $infile $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "provide some keys to set" $temp
# Set with empty -s. Expected to fail
# ----------------------------------------------------
set +e
${tools_dir}/grib_set -s '' $infile $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "provide some keys to set" $temp
# Out-of-bounds value. Expected to fail
# ----------------------------------------------------

View File

@ -65,28 +65,28 @@ int grib_tool_before_getopt(grib_runtime_options* options)
int grib_tool_init(grib_runtime_options* options)
{
if (options->set_values_count == 0 && !options->repack && !options->constant) {
printf("ERROR: please provide some keys to set through the -s option or use the -r/-d options\n");
fprintf(stderr, "ERROR: Please provide some keys to set through the -s option or use the -r/-d options\n");
exit(1);
}
if (options->verbose)
options->print_header = 1;
/*if (grib_options_on("n:")) {
noise=atof(grib_options_get_option("n:"));
options->repack=1;
}*/
// if (grib_options_on("n:")) {
// noise=atof(grib_options_get_option("n:"));
// options->repack=1;
// }
if (grib_options_on("n:") && grib_options_on("d:")) {
printf("Error: -n and -d options are incompatible. Choose one of the two please.\n");
exit(1);
}
// if (grib_options_on("n:") && grib_options_on("d:")) {
// fprintf(stderr, "Error: -n and -d options are incompatible. Choose one of the two please.\n");
// exit(1);
// }
// if (options->outfile && options->outfile->name) {
// options->outfile->file = fopen(options->outfile->name,"w");
// if(!options->outfile->file) {
// perror(options->outfile->name);
// exit(1);
// }
// }
// if (options->outfile && options->outfile->name) {
// options->outfile->file = fopen(options->outfile->name,"w");
// if(!options->outfile->file) {
// perror(options->outfile->name);
// exit(1);
// }
// }
return 0;
}