From 386b4db6a3fb1a613d1e26fba174c1613dedc0b7 Mon Sep 17 00:00:00 2001 From: Dave O'Mahony Date: Sat, 17 Mar 2018 16:16:31 -0230 Subject: [PATCH 1/4] test: update assert messages to show expected and actual values uses the same approach as in test-fs-readfile-pipe-large --- test/parallel/test-fs-readfile-pipe.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index 0c26d7c287e012..f2bf294aa7d0af 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -46,7 +46,7 @@ const node = JSON.stringify(process.execPath); const cmd = `cat ${f} | ${node} ${f} child`; exec(cmd, function(err, stdout, stderr) { assert.ifError(err); - assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it'); - assert.strictEqual(stderr, '', 'it does not write to stderr'); + assert.strictEqual(stdout, dataExpected, `expected to read ${dataExpected} but got: ${stdout}`); + assert.strictEqual(stderr, '', `expected not to read anything from stderr but got: ${stderr}`); console.log('ok'); }); From 9c470d70e8a8c50aec7591525d5845331c81e54c Mon Sep 17 00:00:00 2001 From: Dave O'Mahony Date: Sat, 17 Mar 2018 16:44:09 -0230 Subject: [PATCH 2/4] test: update test to use regularly formatted test data The test originally used the contents of the test file as test data. However, if the assertion fires, the resulting message is difficult to comprehend. The test now uses a short string of regularly formatted x characters that make it easier to spot differences in the expected and actual values. --- test/parallel/test-fs-readfile-pipe.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index f2bf294aa7d0af..30a44ccb2df4d1 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -28,10 +28,9 @@ if (common.isWindows || common.isAIX) common.skip(`No /dev/stdin on ${process.platform}.`); const assert = require('assert'); +const path = require('path'); const fs = require('fs'); -const dataExpected = fs.readFileSync(__filename, 'utf8'); - if (process.argv[2] === 'child') { fs.readFile('/dev/stdin', function(er, data) { assert.ifError(er); @@ -40,13 +39,28 @@ if (process.argv[2] === 'child') { return; } +const tmpdir = require('../common/tmpdir'); + +const filename = path.join(tmpdir.path, '/readfile_pipe_test.txt'); +const dataExpected = `xxxxxxxxxx xxxxxxxxxx +xxxxxxxxxx xxxxxxxxxx +xxxxxxxxxx xxxxxxxxxx +xxxxxxxxxx xxxxxxxxxx +xxxxxxxxxx xxxxxxxxxx` +tmpdir.refresh(); +fs.writeFileSync(filename, dataExpected); + const exec = require('child_process').exec; const f = JSON.stringify(__filename); const node = JSON.stringify(process.execPath); -const cmd = `cat ${f} | ${node} ${f} child`; +const cmd = `cat ${filename} | ${node} ${f} child`; exec(cmd, function(err, stdout, stderr) { assert.ifError(err); - assert.strictEqual(stdout, dataExpected, `expected to read ${dataExpected} but got: ${stdout}`); - assert.strictEqual(stderr, '', `expected not to read anything from stderr but got: ${stderr}`); + assert.strictEqual(stdout, dataExpected, `expected to read: '${dataExpected}' but got: '${stdout}'`); + assert.strictEqual(stderr, '', `expected not to read anything from stderr but got: '${stderr}'`); console.log('ok'); }); + +process.on('exit', function() { + fs.unlinkSync(filename); +}); From 47e641171322cd0e2b2132915dbb1b918e3e5b13 Mon Sep 17 00:00:00 2001 From: Dave O'Mahony Date: Sat, 17 Mar 2018 16:44:09 -0230 Subject: [PATCH 3/4] test: update test to use regularly formatted test data The test originally used the contents of the test file as test data. However, if the assertion fires, the resulting message is difficult to comprehend. The test now uses a short string of regularly formatted x characters that make it easier to spot differences in the expected and actual values. --- test/parallel/test-fs-readfile-pipe.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index 30a44ccb2df4d1..ac724d5ee716d2 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -46,7 +46,7 @@ const dataExpected = `xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx -xxxxxxxxxx xxxxxxxxxx` +xxxxxxxxxx xxxxxxxxxx`; tmpdir.refresh(); fs.writeFileSync(filename, dataExpected); @@ -56,8 +56,14 @@ const node = JSON.stringify(process.execPath); const cmd = `cat ${filename} | ${node} ${f} child`; exec(cmd, function(err, stdout, stderr) { assert.ifError(err); - assert.strictEqual(stdout, dataExpected, `expected to read: '${dataExpected}' but got: '${stdout}'`); - assert.strictEqual(stderr, '', `expected not to read anything from stderr but got: '${stderr}'`); + assert.strictEqual( + stdout, + dataExpected, + `expected to read: '${dataExpected}' but got: '${stdout}'`); + assert.strictEqual( + stderr, + '', + `expected not to read anything from stderr but got: '${stderr}'`); console.log('ok'); }); From cfb0cc39415dfa950f66bfa31d5a4da98949fe6e Mon Sep 17 00:00:00 2001 From: Dave O'Mahony Date: Thu, 22 Mar 2018 19:46:10 -0230 Subject: [PATCH 4/4] test: update test to use a test file from test/fixtures The test has been updated to read a test file from the test/fixtures folder. This makes the source of the test less cluttered. --- test/fixtures/readfile_pipe_test.txt | 5 +++++ test/parallel/test-fs-readfile-pipe.js | 17 +++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/readfile_pipe_test.txt diff --git a/test/fixtures/readfile_pipe_test.txt b/test/fixtures/readfile_pipe_test.txt new file mode 100644 index 00000000000000..65975655dc10fa --- /dev/null +++ b/test/fixtures/readfile_pipe_test.txt @@ -0,0 +1,5 @@ +xxxx xxxx xxxx xxxx +xxxx xxxx xxxx xxxx +xxxx xxxx xxxx xxxx +xxxx xxxx xxxx xxxx +xxxx xxxx xxxx xxxx diff --git a/test/parallel/test-fs-readfile-pipe.js b/test/parallel/test-fs-readfile-pipe.js index ac724d5ee716d2..c9f7144c11a6f6 100644 --- a/test/parallel/test-fs-readfile-pipe.js +++ b/test/parallel/test-fs-readfile-pipe.js @@ -28,7 +28,6 @@ if (common.isWindows || common.isAIX) common.skip(`No /dev/stdin on ${process.platform}.`); const assert = require('assert'); -const path = require('path'); const fs = require('fs'); if (process.argv[2] === 'child') { @@ -39,16 +38,10 @@ if (process.argv[2] === 'child') { return; } -const tmpdir = require('../common/tmpdir'); +const fixtures = require('../common/fixtures'); -const filename = path.join(tmpdir.path, '/readfile_pipe_test.txt'); -const dataExpected = `xxxxxxxxxx xxxxxxxxxx -xxxxxxxxxx xxxxxxxxxx -xxxxxxxxxx xxxxxxxxxx -xxxxxxxxxx xxxxxxxxxx -xxxxxxxxxx xxxxxxxxxx`; -tmpdir.refresh(); -fs.writeFileSync(filename, dataExpected); +const filename = fixtures.path('readfile_pipe_test.txt'); +const dataExpected = fs.readFileSync(filename).toString(); const exec = require('child_process').exec; const f = JSON.stringify(__filename); @@ -66,7 +59,3 @@ exec(cmd, function(err, stdout, stderr) { `expected not to read anything from stderr but got: '${stderr}'`); console.log('ok'); }); - -process.on('exit', function() { - fs.unlinkSync(filename); -});