From f8bb502e2cbb4e123a87d719eb8ef973be0ed478 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 24 Sep 2024 12:17:30 +0200 Subject: [PATCH] interp: Output raw strings for stderr/0 Same as jq Also some cleanup and simplifications --- pkg/interp/internal.jq | 17 ++++------------- pkg/interp/testdata/debug.fqtest | 4 +++- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pkg/interp/internal.jq b/pkg/interp/internal.jq index 48435959..a929ed41 100644 --- a/pkg/interp/internal.jq +++ b/pkg/interp/internal.jq @@ -25,20 +25,11 @@ def println: ., "\n" | print; def printerr: tostring | _stderr; def printerrln: ., "\n" | printerr; -def _debug($name): - ( (([$name, .] | tojson) | printerrln) - , . - ); - # jq compat -def debug: _debug("DEBUG"); -def debug(f): . as $c | f | debug | $c; - -# jq compat, output to compact json to stderr and let input thru -def stderr: - ( (tojson | printerr) - , . - ); +def debug: (["DEBUG", .] | tojson | printerrln), .; +def debug(f): (f | debug | empty), .; +# output raw string or compact json to stderr and let input thru +def stderr: printerr, .; def _fatal_error($code): "error: \(.)\n" | halt_error($code); diff --git a/pkg/interp/testdata/debug.fqtest b/pkg/interp/testdata/debug.fqtest index e0766092..d7e26aed 100644 --- a/pkg/interp/testdata/debug.fqtest +++ b/pkg/interp/testdata/debug.fqtest @@ -41,4 +41,6 @@ null "abc" "\n" stderr: -null"\n"{"a":1}"\n""abc""\n" \ No newline at end of file +null +{"a":1} +abc