From 33f2a20744e97951032b729b3d98b611b071371f Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 10 Nov 2022 21:50:26 -0800 Subject: [PATCH] SORT VARIABLES: Improve error messages. --- src/language/dictionary/sort-variables.c | 9 ++++++- tests/language/dictionary/sort-variables.at | 27 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/language/dictionary/sort-variables.c b/src/language/dictionary/sort-variables.c index aee341bda6..d30629feb0 100644 --- a/src/language/dictionary/sort-variables.c +++ b/src/language/dictionary/sort-variables.c @@ -240,6 +240,13 @@ cmd_sort_variables (struct lexer *lexer, struct dataset *ds) c.attr_name = xstrdup (lex_tokcstr (lexer)); lex_get (lexer); } + else + { + lex_error_expecting (lexer, "NAME", "TYPE", "FORMAT", "LABEL", + "VALUES", "MISSING", "MEASURE", "ROLE", + "COLUMNS", "ALIGNMENT", "ATTRIBUTE"); + return CMD_FAILURE; + } /* Parse sort direction. */ if (lex_match (lexer, T_LPAREN)) @@ -250,7 +257,7 @@ cmd_sort_variables (struct lexer *lexer, struct dataset *ds) c.descending = true; else { - lex_error (lexer, NULL); + lex_error_expecting (lexer, "A", "D"); goto exit; } if (!lex_force_match (lexer, T_RPAREN)) diff --git a/tests/language/dictionary/sort-variables.at b/tests/language/dictionary/sort-variables.at index 896833d23e..8d012576bf 100644 --- a/tests/language/dictionary/sort-variables.at +++ b/tests/language/dictionary/sort-variables.at @@ -76,3 +76,30 @@ test_sort 'az ax ay ab' \ VARIABLE ATTRIBUTE VARIABLES=ab ATTRIBUTE=key("b").' \ 'ATTRIBUTE key' 'ab ax ay az' AT_CLEANUP + +AT_SETUP([SORT VARIABLES syntax errors]) +AT_DATA([sort-variables.sps], [dnl +DATA LIST LIST NOTABLE /x y z. +SORT VARIABLES BY **. +SORT VARIABLES BY ATTRIBUTE **. +SORT VARIABLES BY NAME (**). +SORT VARIABLES BY NAME (A **). +]) +AT_CHECK([pspp -O format=csv sort-variables.sps], [1], [dnl +"sort-variables.sps:2.19-2.20: error: SORT VARIABLES: Syntax error expecting one of the following: NAME, TYPE, FORMAT, LABEL, VALUES, MISSING, MEASURE, ROLE, COLUMNS, ALIGNMENT, ATTRIBUTE. + 2 | SORT VARIABLES BY **. + | ^~" + +"sort-variables.sps:3.29-3.30: error: SORT VARIABLES: Syntax error expecting identifier. + 3 | SORT VARIABLES BY ATTRIBUTE **. + | ^~" + +"sort-variables.sps:4.25-4.26: error: SORT VARIABLES: Syntax error expecting A or D. + 4 | SORT VARIABLES BY NAME (**). + | ^~" + +"sort-variables.sps:5.27-5.28: error: SORT VARIABLES: Syntax error expecting `)'. + 5 | SORT VARIABLES BY NAME (A **). + | ^~" +]) +AT_CLEANUP -- 2.30.2