From: Ben Pfaff Date: Mon, 25 Jan 2021 00:59:29 +0000 (-0800) Subject: DEBUG EVALUATE: Use output_log() instead of printf(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a490bdb254cf8d37eb4ac4edf91c7ef933c92dd;hp=30426c360cc5dc55732bdd7c21a07cd46176bac5;p=pspp DEBUG EVALUATE: Use output_log() instead of printf(). I found that with upcoming changes to the output engine, the relative ordering of output from printf() and from the output engine changed. This commit makes it all go through the output engine, which keeps it consistent as the output engine changes. --- diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c index aa85f2c354..7543aed55e 100644 --- a/src/language/expressions/evaluate.c +++ b/src/language/expressions/evaluate.c @@ -26,6 +26,7 @@ #include "language/expressions/private.h" #include "language/lexer/value-parser.h" #include "libpspp/pool.h" +#include "output/driver.h" #include "xalloc.h" @@ -190,7 +191,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED) { if (expr != NULL) expr_free (expr); - printf ("error\n"); + output_log ("error"); goto done; } @@ -203,28 +204,25 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED) { double d = expr_evaluate_num (expr, c, 0); if (d == SYSMIS) - printf ("sysmis\n"); + output_log ("sysmis"); else - printf ("%.2f\n", d); + output_log ("%.2f", d); } break; case OP_boolean: { double b = expr_evaluate_num (expr, c, 0); - printf ("%s\n", - b == SYSMIS ? "sysmis" : b == 0.0 ? "false" : "true"); + output_log ("%s", + b == SYSMIS ? "sysmis" : b == 0.0 ? "false" : "true"); } break; case OP_string: { - struct substring s; - expr_evaluate (expr, c, 0, &s); - - putchar ('"'); - fwrite (s.string, s.length, 1, stdout); - puts ("\""); + struct substring out; + expr_evaluate (expr, c, 0, &out); + output_log ("\"%.*s\"", (int) out.length, out.string); break; } @@ -248,57 +246,58 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED) void expr_debug_print_postfix (const struct expression *e) { - size_t i; + struct string s = DS_EMPTY_INITIALIZER; - for (i = 0; i < e->op_cnt; i++) + for (size_t i = 0; i < e->op_cnt; i++) { union operation_data *op = &e->ops[i]; if (i > 0) - putc (' ', stderr); + ds_put_byte (&s, ' '); switch (e->op_types[i]) { case OP_operation: if (op->operation == OP_return_number) - printf ("return_number"); + ds_put_cstr (&s, "return_number"); else if (op->operation == OP_return_string) - printf ("return_string"); + ds_put_cstr (&s, "return_string"); else if (is_function (op->operation)) - printf ("%s", operations[op->operation].prototype); + ds_put_format (&s, "%s", operations[op->operation].prototype); else if (is_composite (op->operation)) - printf ("%s", operations[op->operation].name); + ds_put_format (&s, "%s", operations[op->operation].name); else - printf ("%s:", operations[op->operation].name); + ds_put_format (&s, "%s:", operations[op->operation].name); break; case OP_number: if (op->number != SYSMIS) - printf ("n<%g>", op->number); + ds_put_format (&s, "n<%g>", op->number); else - printf ("n"); + ds_put_cstr (&s, "n"); break; case OP_string: - printf ("s<%.*s>", - (int) op->string.length, - op->string.string != NULL ? op->string.string : ""); + ds_put_cstr (&s, "s<"); + ds_put_substring (&s, op->string); + ds_put_byte (&s, '>'); break; case OP_format: { char str[FMT_STRING_LEN_MAX + 1]; fmt_to_string (op->format, str); - printf ("f<%s>", str); + ds_put_format (&s, "f<%s>", str); } break; case OP_variable: - printf ("v<%s>", var_get_name (op->variable)); + ds_put_format (&s, "v<%s>", var_get_name (op->variable)); break; case OP_vector: - printf ("vec<%s>", vector_get_name (op->vector)); + ds_put_format (&s, "vec<%s>", vector_get_name (op->vector)); break; case OP_integer: - printf ("i<%d>", op->integer); + ds_put_format (&s, "i<%d>", op->integer); break; default: NOT_REACHED (); } } - printf ("\n"); + output_log ("%s", ds_cstr (&s)); + ds_destroy (&s); } diff --git a/tests/data/calendar.at b/tests/data/calendar.at index 339098892e..605346ee1d 100644 --- a/tests/data/calendar.at +++ b/tests/data/calendar.at @@ -102,8 +102,20 @@ DEBUG EVALUATE/DATE.DMY(1,1,99) = DATE.DMY(1,1,2099). DEBUG EVALUATE/DATE.DMY(1,1,100). ]) -AT_CHECK([pspp --testing-mode --error-file=- --no-output epoch.sps], [1], - [true +AT_CHECK([pspp --testing-mode epoch.sps -o pspp.csv], [1], [dnl +epoch.sps:11: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:18: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:27: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:34: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:43: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:50: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:59: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:66: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:75: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +epoch.sps:82: error: DEBUG EVALUATE: Date 0100-1-1 is before the earliest acceptable date of 1582-10-15. +]) +AT_CHECK([sed '/^$/d' < pspp.csv], [0], [dnl +true true true true diff --git a/tests/language/expressions/evaluate.at b/tests/language/expressions/evaluate.at index ac4d93e704..cd574eb10f 100644 --- a/tests/language/expressions/evaluate.at +++ b/tests/language/expressions/evaluate.at @@ -26,14 +26,10 @@ DEBUG EVALUATE m4_argn(4, check)/[]m4_car(check). ])]) AT_CAPTURE_FILE([evaluate.sps]) m4_pushdef([i], [3]) - AT_CHECK([pspp --testing-mode --error-file=- --no-output evaluate.sps], + AT_CHECK([pspp --testing-mode -O format=csv evaluate.sps], [m4_if(m4_bregexp([m4_foreach([check], [m4_shift($@)], [m4_argn(3, check)])], [error:]), [-1], [0], [1])], [stdout]) - # Use sed to transform "file:line.column:" into plain "file:line:", - # because column numbers change between opt and noopt versions. - AT_CHECK([[sed 's/\(evaluate.sps:[0-9]\{1,\}\)\.[0-9]\{1,\}:/\1:/' stdout]], - [0], - [m4_foreach([check], [m4_shift($@)], + AT_DATA([expout], [m4_foreach([check], [m4_shift($@)], [m4_define([i], m4_incr(i))dnl m4_if(m4_argn(3, check), [], [], [evaluate.sps:[]i[]: m4_argn(3, check) ])dnl @@ -42,7 +38,21 @@ m4_define([i], m4_incr(i))dnl m4_if(m4_argn(3, check), [], [], [evaluate.sps:[]i[]: m4_argn(3, check) ])dnl m4_argn(2, check) -])], []) +])]) + AT_CHECK([[sed ' +# Transform "file:line.column:" into plain "file:line:", +# because column numbers change between opt and noopt versions. +s/\(evaluate.sps:[0-9]\{1,\}\)\.[0-9]\{1,\}:/\1:/ + +# Remove leading or trailing quotes and un-double CSV quotes. +s/^"// +s/"$// +s/""/"/g +# " + +# Delete blank lines +/^$/d' stdout]], + [0], [expout], []) m4_popdef([i]) AT_CLEANUP]) diff --git a/tests/language/expressions/parse.at b/tests/language/expressions/parse.at index e40a4fe873..8e4166c599 100644 --- a/tests/language/expressions/parse.at +++ b/tests/language/expressions/parse.at @@ -88,6 +88,7 @@ DEBUG EVALUATE/ACOS(0)*0. ]) AT_CHECK([pspp --testing-mode --syntax=compatible -O format=csv parse.sps], [0], [dnl parse.sps:1: warning: DEBUG EVALUATE: ACOS(number) is a PSPP extension. + 0.00 ]) AT_CLEANUP