Skip to content

Commit 3217c70

Browse files
domahonytrivikr
authored andcommitted
test: update assert messages to show expected and actual values
uses the same approach as in test-fs-readfile-pipe-large PR-URL: #19420 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c60c93c commit 3217c70

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/fixtures/readfile_pipe_test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
xxxx xxxx xxxx xxxx
2+
xxxx xxxx xxxx xxxx
3+
xxxx xxxx xxxx xxxx
4+
xxxx xxxx xxxx xxxx
5+
xxxx xxxx xxxx xxxx

test/parallel/test-fs-readfile-pipe.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ if (common.isWindows || common.isAIX)
3030
const assert = require('assert');
3131
const fs = require('fs');
3232

33-
const dataExpected = fs.readFileSync(__filename, 'utf8');
34-
3533
if (process.argv[2] === 'child') {
3634
fs.readFile('/dev/stdin', function(er, data) {
3735
assert.ifError(er);
@@ -40,13 +38,24 @@ if (process.argv[2] === 'child') {
4038
return;
4139
}
4240

41+
const fixtures = require('../common/fixtures');
42+
43+
const filename = fixtures.path('readfile_pipe_test.txt');
44+
const dataExpected = fs.readFileSync(filename).toString();
45+
4346
const exec = require('child_process').exec;
4447
const f = JSON.stringify(__filename);
4548
const node = JSON.stringify(process.execPath);
46-
const cmd = `cat ${f} | ${node} ${f} child`;
49+
const cmd = `cat ${filename} | ${node} ${f} child`;
4750
exec(cmd, function(err, stdout, stderr) {
4851
assert.ifError(err);
49-
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
50-
assert.strictEqual(stderr, '', 'it does not write to stderr');
52+
assert.strictEqual(
53+
stdout,
54+
dataExpected,
55+
`expected to read: '${dataExpected}' but got: '${stdout}'`);
56+
assert.strictEqual(
57+
stderr,
58+
'',
59+
`expected not to read anything from stderr but got: '${stderr}'`);
5160
console.log('ok');
5261
});

0 commit comments

Comments
 (0)