From 7e3635f8adfcce8dde4c39f4d640708dd2a96c7b Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Wed, 15 Nov 2017 16:23:32 +0100 Subject: [PATCH 1/3] test: fs.write() if 3rd argument is a callback, not offset; easier way to resolve conflicts from #16822 and #16827 --- test/parallel/test-fs-write.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index e861b183d966f2..aa82479a5964d8 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -55,21 +55,29 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC; fs.open(fn2, args, 0o644, common.mustCall((err, fd) => { assert.ifError(err); - - const done = common.mustCall((err, written) => { + console.log('open done'); + fs.write(fd, '', 0, 'utf8', (err, written) => { + assert.strictEqual(0, written); + }); + fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => { + console.log('write done'); assert.ifError(err); assert.strictEqual(Buffer.byteLength(expected), written); fs.closeSync(fd); const found = fs.readFileSync(fn2, 'utf8'); + console.log('expected: "%s"', expected); + console.log('found: "%s"', found); fs.unlinkSync(fn2); assert.strictEqual(expected, found); - }); + })); +})); - const written = common.mustCall(function(err, written) { +fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { + assert.ifError(err); + const done = common.mustCall(function(err, written) { assert.ifError(err); - assert.strictEqual(0, written); + assert.strictEqual(Buffer.byteLength(expected), written); + fs.closeSync(fd); }); - - fs.write(fd, '', 0, 'utf8', written); - fs.write(fd, expected, 0, 'utf8', done); + fs.write(fd, expected, done); })); From a11d130789447e0118e9c904db7b289728ec9d08 Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Wed, 15 Nov 2017 16:33:58 +0100 Subject: [PATCH 2/3] fix: done, written, and console.logs removed --- test/parallel/test-fs-write.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index aa82479a5964d8..bafb62c1faa25e 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -55,21 +55,23 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC; fs.open(fn2, args, 0o644, common.mustCall((err, fd) => { assert.ifError(err); - console.log('open done'); - fs.write(fd, '', 0, 'utf8', (err, written) => { - assert.strictEqual(0, written); - }); - fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => { - console.log('write done'); + + const done = common.mustCall((err, written) => { assert.ifError(err); assert.strictEqual(Buffer.byteLength(expected), written); fs.closeSync(fd); const found = fs.readFileSync(fn2, 'utf8'); - console.log('expected: "%s"', expected); - console.log('found: "%s"', found); fs.unlinkSync(fn2); assert.strictEqual(expected, found); - })); + }); + + const written = common.mustCall(function(err, written) { + assert.ifError(err); + assert.strictEqual(0, written); + }); + + fs.write(fd, '', 0, 'utf8', written); + fs.write(fd, expected, 0, 'utf8', done); })); fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { From 5e789afd20f4c0c3a10223d0bf7bcddebd63149f Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Fri, 17 Nov 2017 12:34:02 +0100 Subject: [PATCH 3/3] rename fn to fn3 to avoid conflicts with other tests --- test/parallel/test-fs-write.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index bafb62c1faa25e..ccf2d9b40f7934 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -26,6 +26,7 @@ const path = require('path'); const fs = require('fs'); const fn = path.join(common.tmpDir, 'write.txt'); const fn2 = path.join(common.tmpDir, 'write2.txt'); +const fn3 = path.join(common.tmpDir, 'write3.txt'); const expected = 'ümlaut.'; const constants = fs.constants; @@ -74,12 +75,14 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => { fs.write(fd, expected, 0, 'utf8', done); })); -fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { +fs.open(fn3, 'w', 0o644, common.mustCall(function(err, fd) { assert.ifError(err); + const done = common.mustCall(function(err, written) { assert.ifError(err); assert.strictEqual(Buffer.byteLength(expected), written); fs.closeSync(fd); }); + fs.write(fd, expected, done); }));