I'm trying to compare the output of my fizzbuzz.js
program:
for (let i = 1; i <= 100; i++) {
let out = "";
if (i % 3 == 0) out += "Fizz";
if (i % 5 == 0) out += "Buzz";
if (i % 3 && i % 5) out = i;
console.log(out);
}
with the contents of a expected-output.txt
file which contains:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
[...]
I can't get process substitution to work:
diff -u expected-output.txt <(node fizzbuzz.js)
seems to hang indefinitely. What could be causing this?
My environment is macOS Mojave, bash 3.2.57, node v12.5.0.
EDIT: this seems to be a macOS issue. Everything works fine on a Ubuntu 18.04 machine with newer bash 4.4.19
node fizzbuzz.js | diff -u expected-output.txt -
?diff
shouldn't need to seek. And if it did, it would probably give a clear error about it anyway.read
reads from stdin, butdiff
expects a filename. The<(...)
expands to a file name, so can be used as-is withdiff
. On the other hand,< <(...)
redirects to stdin from that "file"