From ba40b77bcc033a8be5c339f503e386b19ca3d032 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 26 Sep 2021 22:08:09 -0700 Subject: [PATCH] mconvert tests pass --- src/language/data-io/mconvert.c | 55 ++++++-- tests/language/data-io/mconvert.at | 220 +++++++++++++++++++++++++++++ 2 files changed, 260 insertions(+), 15 deletions(-) create mode 100644 tests/language/data-io/mconvert.at diff --git a/src/language/data-io/mconvert.c b/src/language/data-io/mconvert.c index f15ad9be77..dd1c0fbf08 100644 --- a/src/language/data-io/mconvert.c +++ b/src/language/data-io/mconvert.c @@ -40,6 +40,8 @@ cmd_mconvert (struct lexer *lexer, struct dataset *ds) struct file_handle *out = NULL; while (lex_token (lexer) != T_ENDCMD) { + lex_match (lexer, T_SLASH); + if (lex_match_id (lexer, "APPEND")) append = true; else if (lex_match_id (lexer, "REPLACE")) @@ -73,8 +75,6 @@ cmd_mconvert (struct lexer *lexer, struct dataset *ds) if (!lex_force_match (lexer, T_RPAREN)) goto error; } - - lex_match (lexer, T_SLASH); } if (!in && !dataset_has_source (ds)) @@ -84,30 +84,46 @@ cmd_mconvert (struct lexer *lexer, struct dataset *ds) goto error; } - assert (in); - assert (out); - struct dictionary *d; - struct casereader *cr = any_reader_open_and_decode (in, NULL, &d, NULL); - if (!cr) - goto error; + struct casereader *cr; + if (in) + { + cr = any_reader_open_and_decode (in, NULL, &d, NULL); + if (!cr) + goto error; + } + else + { + d = dict_clone (dataset_dict (ds)); + cr = proc_open (ds); + } struct matrix_reader *mr = matrix_reader_create (d, cr); if (!mr) { casereader_destroy (cr); dict_unref (d); + if (!in) + proc_commit (ds); goto error; } - struct casewriter *cw = any_writer_open (out, d); - if (!cw) + struct casewriter *cw; + if (out) { - matrix_reader_destroy (mr); - casereader_destroy (cr); - dict_unref (d); - goto error; + cw = any_writer_open (out, d); + if (!cw) + { + matrix_reader_destroy (mr); + casereader_destroy (cr); + dict_unref (d); + if (!in) + proc_commit (ds); + goto error; + } } + else + cw = autopaging_writer_create (dict_get_proto (d)); for (;;) { @@ -196,7 +212,16 @@ cmd_mconvert (struct lexer *lexer, struct dataset *ds) } matrix_reader_destroy (mr); - casewriter_destroy (cw); + if (!in) + proc_commit (ds); + if (out) + casewriter_destroy (cw); + else + { + dataset_set_dict (ds, dict_ref (d)); + dataset_set_source (ds, casewriter_make_reader (cw)); + } + fh_unref (in); fh_unref (out); dict_unref (d); diff --git a/tests/language/data-io/mconvert.at b/tests/language/data-io/mconvert.at new file mode 100644 index 0000000000..a6b9ab6948 --- /dev/null +++ b/tests/language/data-io/mconvert.at @@ -0,0 +1,220 @@ +dnl PSPP - a program for statistical analysis. +dnl Copyright (C) 2021 Free Software Foundation, Inc. +dnl +dnl This program is free software: you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation, either version 3 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program. If not, see . +dnl +AT_BANNER([MCONVERT]) + +AT_SETUP([MCONVERT]) +AT_DATA([mconvert.sps], [dnl +MATRIX DATA VARIABLES=s ROWTYPE_ var01 TO var03/SPLIT s. +BEGIN DATA. +0 COV 1.0 +0 COV 1.0 16.0 +0 COV 8.1 18.0 81.0 +1 CORR 1 +1 CORR .25 1 +1 CORR .9 .5 1 +1 STDDEV 1 4 9 +END DATA. +FORMATS var01 TO var03(F5.2). +SPLIT FILE OFF. +MCONVERT. +LIST. +]) + +AT_CHECK([pspp -O format=csv mconvert.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,CORR,var01,1.00,.25,.90 +0,CORR,var02,.25,1.00,.50 +0,CORR,var03,.90,.50,1.00 +0,STDDEV,,1.00,4.00,9.00 +1,STDDEV,,1.00,4.00,9.00 +1,COV,var01,1.00,1.00,8.10 +1,COV,var02,1.00,16.00,18.00 +1,COV,var03,8.10,18.00,81.00 +]) +AT_CLEANUP + +AT_SETUP([MCONVERT from .sav file]) +AT_DATA([input.sps], [dnl +MATRIX DATA VARIABLES=s ROWTYPE_ var01 TO var03/SPLIT s. +BEGIN DATA. +0 COV 1.0 +0 COV 1.0 16.0 +0 COV 8.1 18.0 81.0 +1 CORR 1 +1 CORR .25 1 +1 CORR .9 .5 1 +1 STDDEV 1 4 9 +END DATA. +FORMATS var01 TO var03(F5.2). +SPLIT FILE OFF. +SAVE OUTFILE='input.sav'. +]) +AT_DATA([mconvert.sps], [dnl +MCONVERT MATRIX=IN('input.sav'). +LIST. +]) + +AT_CHECK([pspp -O format=csv input.sps]) +AT_CHECK([pspp -O format=csv mconvert.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,CORR,var01,1.00,.25,.90 +0,CORR,var02,.25,1.00,.50 +0,CORR,var03,.90,.50,1.00 +0,STDDEV,,1.00,4.00,9.00 +1,STDDEV,,1.00,4.00,9.00 +1,COV,var01,1.00,1.00,8.10 +1,COV,var02,1.00,16.00,18.00 +1,COV,var03,8.10,18.00,81.00 +]) +AT_CLEANUP + +AT_SETUP([MCONVERT to .sav file]) +AT_DATA([mconvert.sps], [dnl +MATRIX DATA VARIABLES=s ROWTYPE_ var01 TO var03/SPLIT s. +BEGIN DATA. +0 COV 1.0 +0 COV 1.0 16.0 +0 COV 8.1 18.0 81.0 +1 CORR 1 +1 CORR .25 1 +1 CORR .9 .5 1 +1 STDDEV 1 4 9 +END DATA. +FORMATS var01 TO var03(F5.2). +SPLIT FILE OFF. +MCONVERT/REPLACE/OUT('output.sav'). +LIST. +]) +AT_DATA([output.sps], [dnl +GET 'output.sav'. +LIST. +]) + +AT_CHECK([pspp -O format=csv mconvert.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,COV,var01,1.00,1.00,8.10 +0,COV,var02,1.00,16.00,18.00 +0,COV,var03,8.10,18.00,81.00 +1,CORR,var01,1.00,.25,.90 +1,CORR,var02,.25,1.00,.50 +1,CORR,var03,.90,.50,1.00 +1,STDDEV,,1.00,4.00,9.00 +]) +AT_CHECK([pspp -O format=csv output.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,CORR,var01,1.00,.25,.90 +0,CORR,var02,.25,1.00,.50 +0,CORR,var03,.90,.50,1.00 +0,STDDEV,,1.00,4.00,9.00 +1,STDDEV,,1.00,4.00,9.00 +1,COV,var01,1.00,1.00,8.10 +1,COV,var02,1.00,16.00,18.00 +1,COV,var03,8.10,18.00,81.00 +]) +AT_CLEANUP + +AT_SETUP([MCONVERT from .sav file to .sav file]) +AT_DATA([input.sps], [dnl +MATRIX DATA VARIABLES=s ROWTYPE_ var01 TO var03/SPLIT s. +BEGIN DATA. +0 COV 1.0 +0 COV 1.0 16.0 +0 COV 8.1 18.0 81.0 +1 CORR 1 +1 CORR .25 1 +1 CORR .9 .5 1 +1 STDDEV 1 4 9 +END DATA. +FORMATS var01 TO var03(F5.2). +SPLIT FILE OFF. +SAVE OUTFILE='input.sav'. +]) +AT_DATA([mconvert.sps], [dnl +MCONVERT MATRIX=IN('input.sav') OUT('output.sav')/REPLACE. +LIST. +]) +AT_DATA([output.sps], [dnl +GET 'output.sav'. +LIST. +]) + +AT_CHECK([pspp -O format=csv input.sps]) +AT_CHECK([pspp -O format=csv mconvert.sps], [1], [dnl +mconvert.sps:2: error: LIST: LIST is allowed only after the active dataset has been defined. +]) +AT_CHECK([pspp -O format=csv output.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,CORR,var01,1.00,.25,.90 +0,CORR,var02,.25,1.00,.50 +0,CORR,var03,.90,.50,1.00 +0,STDDEV,,1.00,4.00,9.00 +1,STDDEV,,1.00,4.00,9.00 +1,COV,var01,1.00,1.00,8.10 +1,COV,var02,1.00,16.00,18.00 +1,COV,var03,8.10,18.00,81.00 +]) +AT_CLEANUP + +AT_SETUP([MCONVERT with APPEND]) +AT_DATA([mconvert.sps], [dnl +MATRIX DATA VARIABLES=s ROWTYPE_ var01 TO var03/SPLIT s. +BEGIN DATA. +0 COV 1.0 +0 COV 1.0 16.0 +0 COV 8.1 18.0 81.0 +1 CORR 1 +1 CORR .25 1 +1 CORR .9 .5 1 +1 STDDEV 1 4 9 +END DATA. +FORMATS var01 TO var03(F5.2). +SPLIT FILE OFF. +MCONVERT/APPEND. +LIST. +]) + +AT_CHECK([pspp -O format=csv mconvert.sps], [0], [dnl +Table: Data List +s,ROWTYPE_,VARNAME_,var01,var02,var03 +0,COV,var01,1.00,1.00,8.10 +0,COV,var02,1.00,16.00,18.00 +0,COV,var03,8.10,18.00,81.00 +0,CORR,var01,1.00,.25,.90 +0,CORR,var02,.25,1.00,.50 +0,CORR,var03,.90,.50,1.00 +0,STDDEV,,1.00,4.00,9.00 +1,CORR,var01,1.00,.25,.90 +1,CORR,var02,.25,1.00,.50 +1,CORR,var03,.90,.50,1.00 +1,STDDEV,,1.00,4.00,9.00 +1,COV,var01,1.00,1.00,8.10 +1,COV,var02,1.00,16.00,18.00 +1,COV,var03,8.10,18.00,81.00 +]) +AT_CLEANUP + +AT_SETUP([MCONVERT negative test]) +AT_DATA([mconvert.sps], [MCONVERT. +]) +AT_CHECK([pspp mconvert.sps], [1], [dnl +]) +AT_CLEANUP \ No newline at end of file -- 2.30.2