From 85d10e97f7c07855c1bbe9bd89e5ebc1aa10352f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 2 Feb 2021 22:11:43 -1000 Subject: lei q: support reading queries from stdin This will be useful on shared machines when a user doesn't want search queries visible to other users looking at the ps(1) output or similar. --- t/lei.t | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 't') diff --git a/t/lei.t b/t/lei.t index 03bbb078..01eed1da 100644 --- a/t/lei.t +++ b/t/lei.t @@ -275,6 +275,25 @@ my $test_external = sub { my $pretty = $json->decode($out); is_deeply($res, $pretty, '--pretty is identical after decode'); + { + open my $fh, '+>', undef or BAIL_OUT $!; + $fh->autoflush(1); + print $fh 's:use' or BAIL_OUT $!; + seek($fh, 0, SEEK_SET) or BAIL_OUT $!; + ok($lei->([qw(q -q --stdin)], undef, { %$opt, 0 => $fh }), + '--stdin on regular file works'); + like($out, qr/use boolean prefix/, '--stdin on regular file'); + } + { + pipe(my ($r, $w)) or BAIL_OUT $!; + print $w 's:use' or BAIL_OUT $!; + close $w or BAIL_OUT $!; + ok($lei->([qw(q -q --stdin)], undef, { %$opt, 0 => $r }), + '--stdin on pipe file works'); + like($out, qr/use boolean prefix/, '--stdin on pipe'); + } + ok(!$lei->(qw(q -q --stdin s:use)), "--stdin and argv don't mix"); + for my $fmt (qw(ldjson ndjson jsonl)) { $lei->('q', '-f', $fmt, 's:use boolean prefix'); is($out, $json->encode($pretty->[0])."\n", "-f $fmt"); -- cgit v1.2.3-24-ge0c7