t: add greplint to detect bare grep assertions

Without a lint guard, bare grep assertions will creep back into tests over time, defeating the previous commit's conversion. Add greplint.pl to catch bare 'grep' used as a test assertion (where 'test_grep' should be used) and '! test_grep' (where 'test_grep !' should be used). greplint.pl reuses the shared shell parser from lib-shell-parser.pl to tokenize test bodies. The Lexer collapses heredocs, command substitutions, and quoted strings into single tokens, so 'grep' appearing inside these contexts is not flagged. A flat walk over the token stream tracks command position and pipeline state to distinguish assertion greps from filter greps. For double-quoted test bodies, a source-line walk counts backslash-continuation lines that the Lexer consumes without emitting into the body text, adjusting the reported line number accordingly. Add test fixtures in greplint/ (modeled on chainlint/) covering detection of bare grep assertions, correct skipping of filters, pipelines, redirects, command substitutions, and lint-ok annotations. Wire into the Makefile as: - test-greplint: runs greplint.pl on $(T) $(THELPERS) $(TPERF) - check-greplint: runs greplint.pl on fixtures, diffs against expected - clean-greplint: removes temp dir Add eol=lf entries in t/.gitattributes for greplint fixtures, matching chainlint, so that check-greplint passes on Windows where core.autocrlf would otherwise cause CRLF mismatches between expected and actual output. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Montalbo committed Jul 6, 2026 at 05:01 UTC be7112d1bb97a0f4c4d724484e8940193ab5366d
44 files changed +415 -5
t/.gitattributes
+2
@@ -1,5 +1,7 @@
1 t[0-9][0-9][0-9][0-9]/* -whitespace
2 /chainlint/*.expect eol=lf -whitespace
3 +/greplint/*.expect eol=lf -whitespace
4 +/greplint/*.test eol=lf -whitespace
5 /t0110/url-* binary
6 /t3206/* eol=lf
7 /t3900/*.txt eol=lf
t/Makefile
+24 -5
@@ -27,9 +27,11 @@ TEST_LINT ?= test-lint
27 ifdef TEST_OUTPUT_DIRECTORY
28 TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
29 CHAINLINTTMP = $(TEST_OUTPUT_DIRECTORY)/chainlinttmp
30 +GREPLINTTMP = $(TEST_OUTPUT_DIRECTORY)/greplinttmp
31 else
32 TEST_RESULTS_DIRECTORY = test-results
33 CHAINLINTTMP = chainlinttmp
34 +GREPLINTTMP = greplinttmp
35 endif
36
37 # Shell quote;
@@ -38,6 +40,7 @@ TEST_SHELL_PATH_SQ = $(subst ','\'',$(TEST_SHELL_PATH))
40 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
41 TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
42 CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP))
43 +GREPLINTTMP_SQ = $(subst ','\'',$(GREPLINTTMP))
44
45 T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
46 THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh)))
@@ -45,6 +48,7 @@ TLIBS = $(sort $(wildcard lib-*.sh)) annotate-tests.sh
48 TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh))
49 TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh))
50 CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
51 +GREPLINTTESTS = $(sort $(patsubst greplint/%.test,%,$(wildcard greplint/*.test)))
52 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
53 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
54 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
@@ -63,8 +67,8 @@ test: pre-clean check-meson $(TEST_LINT)
67 $(CHAINLINTSUPPRESS) $(MAKE) aggregate-results-and-cleanup
68
69 ifneq ($(PERL_PATH),)
66 -test: check-chainlint
67 -prove: check-chainlint
70 +test: check-chainlint check-greplint
71 +prove: check-chainlint check-greplint
72 endif
73
74 failed:
@@ -102,7 +106,7 @@ unit-tests-test-tool:
106 pre-clean:
107 $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
108
105 -clean-except-prove-cache: clean-chainlint
109 +clean-except-prove-cache: clean-chainlint clean-greplint
110 $(RM) -r 'trash directory'.*
111 $(RM) -r valgrind/bin
112
@@ -120,6 +124,17 @@ check-chainlint:
124 { $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests >'$(CHAINLINTTMP_SQ)'/actual || true; } && \
125 diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
126
127 +clean-greplint:
128 + $(RM) -r '$(GREPLINTTMP_SQ)'
129 +
130 +check-greplint:
131 + @mkdir -p '$(GREPLINTTMP_SQ)' && \
132 + '$(PERL_PATH_SQ)' greplint-cat.pl '$(GREPLINTTMP_SQ)' $(GREPLINTTESTS) && \
133 + { '$(PERL_PATH_SQ)' greplint.pl \
134 + $(patsubst %,greplint/%.test,$(GREPLINTTESTS)) \
135 + >'$(GREPLINTTMP_SQ)'/actual 2>&1 || true; } && \
136 + diff -u '$(GREPLINTTMP_SQ)'/expect '$(GREPLINTTMP_SQ)'/actual
137 +
138 check-meson:
139 @# awk acts up when trying to match single quotes, so we use \047 instead.
140 @mkdir -p mesontmp && \
@@ -139,7 +154,7 @@ check-meson:
154 test-lint: test-lint-duplicates test-lint-executable \
155 test-lint-filenames
156 ifneq ($(PERL_PATH),)
142 -test-lint: test-lint-shell-syntax
157 +test-lint: test-lint-shell-syntax test-greplint
158 else
159 GIT_TEST_CHAIN_LINT = 0
160 endif
@@ -160,6 +175,9 @@ test-lint-executable:
175 test-lint-shell-syntax:
176 @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) $(TPERF)
177
178 +test-greplint:
179 + @'$(PERL_PATH_SQ)' greplint.pl $(T) $(THELPERS) $(TPERF)
180 +
181 test-lint-filenames:
182 @# We do *not* pass a glob to ls-files but use grep instead, to catch
183 @# non-ASCII characters (which are quoted within double-quotes)
@@ -185,7 +203,8 @@ perf:
203 $(MAKE) -C perf/ all
204
205 .PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
188 - check-chainlint clean-chainlint test-chainlint $(UNIT_TESTS)
206 + check-chainlint clean-chainlint test-chainlint \
207 + check-greplint clean-greplint test-greplint $(UNIT_TESTS)
208
209 .PHONY: libgit-sys-test libgit-rs-test
210 libgit-sys-test:
t/greplint-cat.pl new
+27
@@ -0,0 +1,27 @@
1 +#!/usr/bin/env perl
2 +
3 +use strict;
4 +use warnings;
5 +
6 +# Assemble expected output for check-greplint target.
7 +# Usage: greplint-cat.pl <outdir> <test-name> ...
8 +#
9 +# For each <test-name>, reads greplint/<test-name>.expect and
10 +# prepends "greplint/<test-name>.test:" to every non-empty line,
11 +# matching the output format of greplint.pl. Writes combined
12 +# expected output to <outdir>/expect.
13 +
14 +my $outdir = shift;
15 +open(my $expect, '>', "$outdir/expect")
16 + or die "unable to open $outdir/expect: $!";
17 +
18 +for my $name (@ARGV) {
19 + open(my $fh, '<', "greplint/$name.expect")
20 + or die "unable to open greplint/$name.expect: $!";
21 + while (<$fh>) {
22 + print $expect "greplint/$name.test:$_";
23 + }
24 + close $fh;
25 +}
26 +
27 +close $expect;
t/greplint.pl new
+258
@@ -0,0 +1,258 @@
1 +#!/usr/bin/env perl
2 +
3 +# Detect bare 'grep' used as a test assertion where 'test_grep'
4 +# should be used, and '! test_grep' where 'test_grep !' should
5 +# be used.
6 +#
7 +# The shared shell parser tokenizes test bodies so that 'grep'
8 +# inside heredocs, command substitutions like $(grep ...), and
9 +# quoted strings is collapsed into a single token and never seen
10 +# by our check. A line-oriented approach would need to track
11 +# heredoc delimiters, nested $() depth, and cross-line pipe
12 +# state to avoid false positives on patterns like:
13 +#
14 +# write_script foo.sh <<-\EOF
15 +# grep pattern file # data, not an assertion
16 +# EOF
17 +#
18 +# The Lexer already handles these.
19 +
20 +use warnings;
21 +use strict;
22 +use File::Basename;
23 +do(dirname($0) . "/lib-shell-parser.pl")
24 + or die "$0: failed to load lib-shell-parser.pl: $@$!\n";
25 +
26 +my $exit_code = 0;
27 +
28 +# GrepLintParser inherits ScriptParser's ability to find
29 +# test_expect_success/failure blocks and call check_test()
30 +# on each body. We override check_test() to walk the token
31 +# stream looking for bare grep assertions.
32 +package GrepLintParser;
33 +
34 +our @ISA = ('ScriptParser');
35 +
36 +# After these tokens, the next token is a command word.
37 +# For example, in 'echo foo && grep bar file', the 'grep'
38 +# after '&&' is at command position and should be flagged.
39 +my %cmd_start = map { $_ => 1 } qw(&& || ; ;; do then else elif), "\n", '{', '(';
40 +
41 +# Tokens indicating grep's output is piped or redirected.
42 +my %filter_op = map { $_ => 1 } qw(| > >> <);
43 +
44 +# A token is at "command word" position if the shell would
45 +# interpret it as a program name rather than an argument.
46 +# Only 'grep' at command position is an assertion we should
47 +# flag; 'grep' as an argument ('test_must_fail grep') or
48 +# value ('for cmd in grep sed') is not.
49 +sub is_command_word {
50 + my ($tokens, $pos) = @_;
51 + return 1 if $pos == 0;
52 + for (my $j = $pos - 1; $j >= 0; $j--) {
53 + my $t = $tokens->[$j]->[0];
54 + # After a separator or pipe, a new command starts.
55 + return 1 if $cmd_start{$t} || $t eq '|';
56 + # After '}' or ')', what follows is a separator or
57 + # redirect on the compound command, not a new command.
58 + return 0 if $t eq '}' || $t eq ')';
59 + # '!' is a prefix that does not consume command
60 + # position; keep scanning to find what precedes it.
61 + next if $t eq '!';
62 + # Any other word means we are past the command word.
63 + return 0;
64 + }
65 + return 1;
66 +}
67 +
68 +# lint_ok() reports whether a bare grep carries a trailing
69 +# '# lint-ok' comment telling this linter to skip it.
70 +#
71 +# In practice this is needed for just one case: a grep acting
72 +# as a data filter whose output is consumed by a redirect or
73 +# pipe on an enclosing compound command (such as a subshell or
74 +# brace group) rather than by grep's own pipeline, e.g.
75 +#
76 +# ( grep ... && # lint-ok
77 +# sed ... ) >out
78 +#
79 +# { grep ... || : # lint-ok
80 +# } >out
81 +#
82 +# is_filter() only scans grep's own pipeline: it stops at the
83 +# separator before the compound command closes and never sees
84 +# the outer redirect, so it would flag such a grep as an
85 +# assertion. A grep that really is an assertion is better
86 +# written as test_grep (or a guarded test_grep when the file's
87 +# presence is conditional) than annotated with lint-ok.
88 +sub lint_ok {
89 + my ($raw_lines, $ln) = @_;
90 + if ($ln < 1 || $ln > @$raw_lines) {
91 + warn "lint_ok: line number $ln out of range (1.." .
92 + scalar(@$raw_lines) . ")\n";
93 + return 0;
94 + }
95 + return $raw_lines->[$ln - 1] =~ /lint-ok/;
96 +}
97 +
98 +# Grep is a filter (not an assertion) if it receives piped
99 +# input or sends its output to a pipe or redirect. Check
100 +# both directions from grep's position in the token stream.
101 +sub is_filter {
102 + my ($tokens, $pos) = @_;
103 + # Backward: is grep receiving piped input?
104 + # Newlines don't break pipes ('cmd |\n grep' is one
105 + # pipeline), so skip past them.
106 + for (my $j = $pos - 1; $j >= 0; $j--) {
107 + my $t = $tokens->[$j]->[0];
108 + return 1 if $t eq '|';
109 + next if $t eq "\n";
110 + last if $cmd_start{$t} || $t eq '}' || $t eq ')';
111 + }
112 + # Forward: is grep piping or redirecting output?
113 + # Unlike the backward scan, we do not skip newlines here:
114 + # a bare newline is a command boundary, and redirects or
115 + # pipes must appear on the same line as grep (or after a
116 + # line continuation, which the Lexer consumes).
117 + for (my $j = $pos + 1; $j < @$tokens; $j++) {
118 + my $t = $tokens->[$j]->[0];
119 + return 0 if $cmd_start{$t};
120 + return 1 if $filter_op{$t};
121 + }
122 + return 0;
123 +}
124 +
125 +# Map a body-relative line number to a file line number.
126 +# For double-quoted bodies, backslash-continuation lines
127 +# (\<newline>) are consumed by the Lexer without appearing
128 +# in the body text, so the inner parser sees fewer lines
129 +# than the source file has. We walk the source lines to
130 +# count continuations and adjust accordingly.
131 +sub body_to_file_line {
132 + my ($body_lineno, $body_token, $raw_lines, $body_start) = @_;
133 + my $body_text = $body_token->[0];
134 + my $body_end_line = $body_token->[4];
135 + unless ($body_start && $body_start >= 1) {
136 + warn "body_start is not a positive integer\n";
137 + return $body_lineno;
138 + }
139 + my $file_lineno = $body_lineno + $body_start - 1;
140 + # Only double-quoted bodies have line splices.
141 + return $file_lineno unless $body_text =~ /^"/;
142 + my $adj = 0;
143 + my $lines_seen = 0;
144 + unless ($body_end_line && $body_end_line >= $body_start) {
145 + warn "body_end_line is not set for double-quoted body\n";
146 + return $file_lineno;
147 + }
148 + my $end = $body_end_line;
149 + if ($end > @$raw_lines) {
150 + warn "body_end_line ($end) exceeds file length (" .
151 + scalar(@$raw_lines) . ")\n";
152 + return $file_lineno;
153 + }
154 + my $src_ln = $body_start;
155 + while ($src_ln <= $end && $lines_seen < $body_lineno) {
156 + my $line = $raw_lines->[$src_ln - 1];
157 + # Odd trailing backslashes = continuation (\<nl>).
158 + # Even = escaped backslashes (\\), not a continuation.
159 + if ($line =~ /(\\*)$/ && length($1) % 2 == 1) {
160 + $adj++;
161 + } else {
162 + $lines_seen++;
163 + }
164 + $src_ln++;
165 + }
166 + if ($lines_seen < $body_lineno) {
167 + warn "body_lineno ($body_lineno) not found within body range " .
168 + "($body_start..$end)\n";
169 + }
170 + return $file_lineno + $adj;
171 +}
172 +
173 +# ScriptParser calls this for each test body found in the script.
174 +sub check_test {
175 + my $self = shift @_;
176 + my $title = ScriptParser::unwrap(shift @_);
177 + my $body_token = shift @_;
178 + my $body_start = $body_token->[3];
179 + my $body = ScriptParser::unwrap($body_token);
180 + # Handle heredoc-style test bodies:
181 + # test_expect_success 'title' - <<\EOF
182 + # grep pattern file
183 + # EOF
184 + # The '-' signals that the body follows as a heredoc.
185 + if ($body eq '-') {
186 + my $herebody = shift @_;
187 + if ($herebody) {
188 + $body = $herebody->{content};
189 + $body_start = $herebody->{start_line};
190 + }
191 + }
192 + return unless $body;
193 +
194 + my $raw_lines = $self->{raw_lines};
195 +
196 + # The outer parser gives us the body as an opaque string.
197 + # Parse it to get individual tokens with command boundaries.
198 + my $parser = ShellParser->new(\$body);
199 + my @tokens = $parser->parse();
200 +
201 + my $file = $self->{file};
202 +
203 + for (my $i = 0; $i < @tokens; $i++) {
204 + my $text = $tokens[$i]->[0];
205 + next unless is_command_word(\@tokens, $i);
206 +
207 + my $token_lineno = $tokens[$i]->[3];
208 + unless (defined($token_lineno) && $token_lineno >= 1) {
209 + warn "token has no line number\n";
210 + next;
211 + }
212 + my $file_lineno = body_to_file_line(
213 + $token_lineno,
214 + $body_token, $raw_lines, $body_start);
215 +
216 + # '!' negates the exit code without consuming command
217 + # position. '! test_grep' is an anti-pattern because
218 + # test_grep only prints diagnostics on grep failure,
219 + # and '!' inverts after that decision is already made.
220 + if ($text eq '!') {
221 + if ($i + 1 < @tokens &&
222 + $tokens[$i + 1]->[0] eq 'test_grep' &&
223 + !lint_ok($raw_lines, $file_lineno)) {
224 + print "$file:$file_lineno: error: ",
225 + 'use "test_grep !" instead of ',
226 + '"! test_grep"', "\n";
227 + $exit_code = 1;
228 + }
229 + next;
230 + }
231 +
232 + # Bare grep as a command (not a filter) is a test
233 + # assertion that should use test_grep for better
234 + # failure diagnostics.
235 + if ($text eq 'grep' &&
236 + !is_filter(\@tokens, $i) &&
237 + !lint_ok($raw_lines, $file_lineno)) {
238 + print "$file:$file_lineno: error: ",
239 + "bare grep outside pipeline ",
240 + "(use test_grep)\n";
241 + $exit_code = 1;
242 + }
243 + }
244 +}
245 +
246 +package main;
247 +
248 +for my $file (@ARGV) {
249 + open(my $fh, '<:unix:crlf', $file) or die "$0: $file: $!\n";
250 + my @raw_lines = <$fh>;
251 + close $fh;
252 + my $s = join('', @raw_lines);
253 + my $parser = GrepLintParser->new(\$s);
254 + $parser->{file} = $file;
255 + $parser->{raw_lines} = \@raw_lines;
256 + $parser->parse();
257 +}
258 +exit $exit_code;
t/greplint/bare-grep-after-and.expect new
+1
@@ -0,0 +1 @@
1 +3: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-after-and.test new
+4
@@ -0,0 +1,4 @@
1 +test_expect_success 'grep after && is flagged' '
2 + cmd &&
3 + grep pattern file
4 +'
t/greplint/bare-grep-after-semicolon.expect new
+1
@@ -0,0 +1 @@
1 +3: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-after-semicolon.test new
+4
@@ -0,0 +1,4 @@
1 +test_expect_success 'grep after semicolon is flagged' '
2 + echo hello;
3 + grep pattern file
4 +'
t/greplint/bare-grep-compound-body.expect new
+3
@@ -0,0 +1,3 @@
1 +4: error: bare grep outside pipeline (use test_grep)
2 +8: error: bare grep outside pipeline (use test_grep)
3 +15: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-compound-body.test new
+17
@@ -0,0 +1,17 @@
1 +test_expect_success 'grep after then/do/else is flagged' '
2 + if true
3 + then
4 + grep pattern file
5 + fi &&
6 + while true
7 + do
8 + grep pattern file &&
9 + break
10 + done &&
11 + if true
12 + then
13 + echo yes
14 + else
15 + grep pattern file
16 + fi
17 +'
t/greplint/bare-grep-count-mode.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-count-mode.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep -c is flagged (not special-cased)' '
2 + grep -c pattern file
3 +'
t/greplint/bare-grep-explicit-pattern.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-explicit-pattern.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep -e is flagged' '
2 + grep -e pattern file
3 +'
t/greplint/bare-grep-flags.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-flags.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep -E is flagged' '
2 + grep -E "pat+ern" file
3 +'
t/greplint/bare-grep-lint-ok.expect
t/greplint/bare-grep-lint-ok.test new
+4
@@ -0,0 +1,4 @@
1 +test_expect_success 'grep with lint-ok annotation is not flagged' '
2 + grep pattern file && # lint-ok
3 + echo done
4 +'
t/greplint/bare-grep-negated.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-negated.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'negated grep is flagged' '
2 + ! grep pattern file
3 +'
t/greplint/bare-grep-pattern-file.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-pattern-file.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep -f is flagged' '
2 + grep -f patterns.txt file
3 +'
t/greplint/bare-grep-simple.expect new
+1
@@ -0,0 +1 @@
1 +2: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-simple.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'bare grep is flagged' '
2 + grep pattern file
3 +'
t/greplint/bare-grep-subshell.expect new
+1
@@ -0,0 +1 @@
1 +3: error: bare grep outside pipeline (use test_grep)
t/greplint/bare-grep-subshell.test new
+5
@@ -0,0 +1,5 @@
1 +test_expect_success 'grep in subshell is flagged' '
2 + (
3 + grep pattern file
4 + )
5 +'
t/greplint/dqstring-continuation-offset.expect new
+1
@@ -0,0 +1 @@
1 +10: error: bare grep outside pipeline (use test_grep)
t/greplint/dqstring-continuation-offset.test new
+11
@@ -0,0 +1,11 @@
1 +# Double-quoted test bodies with backslash-continuation lines:
2 +# the splice adjustment in check_test compensates for \<newline>
3 +# lines that the lexer consumes without emitting into the body
4 +# text, so the reported line number matches the source.
5 +test_expect_success 'dqstring continuation offset' "
6 + x=\$(echo \
7 + hello) &&
8 + y=\$(echo \
9 + world) &&
10 + grep pattern file
11 +"
t/greplint/filter-command-substitution.expect
t/greplint/filter-command-substitution.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep in command substitution is not flagged' '
2 + x=$(grep pattern file)
3 +'
t/greplint/filter-pipe-input.expect
t/greplint/filter-pipe-input.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep receiving pipe input is not flagged' '
2 + cmd | grep pattern
3 +'
t/greplint/filter-pipe-output.expect
t/greplint/filter-pipe-output.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep piping to another command is not flagged' '
2 + grep pattern file | wc -l
3 +'
t/greplint/filter-redirect-output.expect
t/greplint/filter-redirect-output.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep with output redirect is not flagged' '
2 + grep pattern file >output
3 +'
t/greplint/filter-stdin-redirect.expect
t/greplint/filter-stdin-redirect.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep reading from stdin redirect is not flagged' '
2 + grep pattern <input
3 +'
t/greplint/grep-as-argument.expect
t/greplint/grep-as-argument.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'grep as argument to another command is not flagged' '
2 + test_must_fail grep pattern file
3 +'
t/greplint/grep-as-value.expect
t/greplint/grep-as-value.test new
+6
@@ -0,0 +1,6 @@
1 +test_expect_success 'grep as value in for-loop is not flagged' '
2 + for cmd in grep sed awk
3 + do
4 + echo $cmd
5 + done
6 +'
t/greplint/wrong-negation.expect new
+1
@@ -0,0 +1 @@
1 +2: error: use "test_grep !" instead of "! test_grep"
t/greplint/wrong-negation.test new
+3
@@ -0,0 +1,3 @@
1 +test_expect_success 'wrong negation of test_grep is flagged' '
2 + ! test_grep pattern file
3 +'