mirror of
https://github.com/wader/fq.git
synced 2024-12-23 13:22:58 +03:00
interp: Add stderr again for jq compat
Also add tests for print* and stderr
This commit is contained in:
parent
2c3e41111d
commit
a3cfcd0ad2
@ -9,11 +9,17 @@ def println: ., "\n" | print;
|
||||
def printerr: tostring | _stderr;
|
||||
def printerrln: ., "\n" | printerr;
|
||||
|
||||
# jq compat
|
||||
def debug:
|
||||
( ((["DEBUG", .] | tojson) | printerrln)
|
||||
, .
|
||||
);
|
||||
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 _global_var($k): _global_state[$k];
|
||||
def _global_var($k; f): _global_state(_global_state | .[$k] |= f) | .[$k];
|
||||
|
29
pkg/interp/testdata/debug.fqtest
vendored
29
pkg/interp/testdata/debug.fqtest
vendored
@ -13,3 +13,32 @@ null> ^D
|
||||
stderr:
|
||||
["DEBUG",{"a":123,"b":[]}]
|
||||
["DEBUG",{"a":123}]
|
||||
$ fq -n 'null, {a:1}, "abc" | ., "\n" | print'
|
||||
null
|
||||
{"a":1}
|
||||
abc
|
||||
$ fq -n 'null, {a:1}, "abc" | println'
|
||||
null
|
||||
{"a":1}
|
||||
abc
|
||||
$ fq -n 'null, {a:1}, "abc" | ., "\n" | printerr'
|
||||
stderr:
|
||||
null
|
||||
{"a":1}
|
||||
abc
|
||||
$ fq -n 'null, {a:1}, "abc" | printerrln'
|
||||
stderr:
|
||||
null
|
||||
{"a":1}
|
||||
abc
|
||||
$ fq -n 'null, {a:1}, "abc" | ., "\n" | stderr'
|
||||
null
|
||||
"\n"
|
||||
{
|
||||
"a": 1
|
||||
}
|
||||
"\n"
|
||||
"abc"
|
||||
"\n"
|
||||
stderr:
|
||||
null"\n"{"a":1}"\n""abc""\n"
|
Loading…
Reference in New Issue
Block a user