aboutsummaryrefslogtreecommitdiff
path: root/modules/test/test-shell-stdin.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/test/test-shell-stdin.js')
-rw-r--r--modules/test/test-shell-stdin.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/test/test-shell-stdin.js b/modules/test/test-shell-stdin.js
index 10ba190..1b0fbca 100644
--- a/modules/test/test-shell-stdin.js
+++ b/modules/test/test-shell-stdin.js
@@ -29,6 +29,33 @@ const mk = (files, pipeInput) => {
};
const last = (out) => out.length ? out[out.length - 1] : '<nothing printed>';
+// (g) grep over a pipe must search the piped text, never the working directory.
+// Measured 2026-10-27 on v4.6.115: `cat /gdir/in.txt | grep zzz` answered
+// "other.txt:1: zzz in a cwd file" — a file that was never piped.
+{
+ const decoy = {
+ readFile: () => null,
+ getCurrentDir: () => ({ name: 'gdir', content: {
+ 'other.txt': { type: 'file', content: 'zzz in a cwd file' },
+ 'in.txt': { type: 'file', content: 'aaa\nbbb\nccc' },
+ } }),
+ };
+ const out = [];
+ const term = { fs: decoy, _pipeInput: 'aaa\nbbb\nccc', print: (m) => out.push(String(m)) };
+ const m = new FileSystemModule();
+ m.terminal = term; m.registerCommands();
+ m.commands.grep(['zzz']);
+ ok('G1 grep over a pipe does not search the cwd', !out.join('|').includes('other.txt'), JSON.stringify(out));
+ ok('G2 a non-match over a pipe reports no matches', out.join('|').includes('(no matches)'), JSON.stringify(out));
+
+ out.length = 0;
+ m.commands.grep(['bbb']);
+ ok('G3 a match prints the line number without a filename', out.length === 1 && out[0] === '2: bbb', JSON.stringify(out));
+
+ out.length = 0;
+ m.commands.grep(['-c', 'b']);
+ ok('G4 grep -c over a pipe counts stdin lines', out.length === 1 && out[0] === '1', JSON.stringify(out));
+}
// (a) wc -l over 3 lines of stdin
{
const { m, out } = mk({}, 'alpha\nbeta\ngamma');