From eacddd57249093bef2defc3bcdca3ad2b2e93b89 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 8 Nov 2021 22:55:13 -0800 Subject: [PATCH] More MATRIX SAVE negative tests. --- src/language/stats/matrix.c | 18 ++++++++++++------ tests/language/stats/matrix.at | 10 ++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/language/stats/matrix.c b/src/language/stats/matrix.c index a145282b12..32a06914d9 100644 --- a/src/language/stats/matrix.c +++ b/src/language/stats/matrix.c @@ -4475,14 +4475,20 @@ save_file_open (struct save_file *sf, gsl_matrix *m) if (!stringi_set_is_empty (&strings)) { + size_t count = stringi_set_count (&strings); const char *example = stringi_set_node_get_string ( stringi_set_first (&strings)); - msg (ME, ngettext ("STRINGS specified a variable %s, but no variable " - "with that name was found on SAVE.", - "STRINGS specified %2$zu variables, including %1$s, " - "whose names were not found on SAVE.", - stringi_set_count (&strings)), - example, stringi_set_count (&strings)); + + if (count == 1) + msg (ME, _("The SAVE command STRINGS subcommand specifies an unknown " + "variable %s."), example); + else + msg (ME, ngettext ("The SAVE command STRINGS subcommand specifies %zu " + "unknown variable: %s.", + "The SAVE command STRINGS subcommand specifies %zu " + "unknown variables, including %s.", + count), + count, example); ok = false; } stringi_set_destroy (&strings); diff --git a/tests/language/stats/matrix.at b/tests/language/stats/matrix.at index d55514c9df..0db26d6eb4 100644 --- a/tests/language/stats/matrix.at +++ b/tests/language/stats/matrix.at @@ -3180,6 +3180,9 @@ SAVE 1. SAVE 1/OUTFILE='matrix.sav'/NAMES={'a'}/VARIABLES=a. SAVE 1/OUTFILE='matrix2.sav'. SAVE {1,2}/OUTFILE='matrix2.sav'. +SAVE {1,2}/OUTFILE='matrix3.sav'/NAMES={'a', 'a'}. +SAVE {1,2}/OUTFILE='matrix4.sav'/STRINGS=a. +SAVE {1,2}/OUTFILE='matrix5.sav'/STRINGS=a, b. END MATRIX. ]) AT_CHECK([pspp matrix.sps], [1], [dnl @@ -3202,5 +3205,12 @@ NAMES. error: The first SAVE to `matrix2.sav' within this matrix program had 1 columns, so a 1×2 matrix cannot be saved to it. + +error: Duplicate variable name a in SAVE statement. + +error: The SAVE command STRINGS subcommand specifies an unknown variable a. + +error: The SAVE command STRINGS subcommand specifies 2 unknown variables, +including a. ]) AT_CLEANUP \ No newline at end of file -- 2.30.2