From b7c7bae1f570f66507d8dec9d8b2bd4a8bf205b5 Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Mon, 6 Nov 2017 15:52:33 +0000 Subject: [PATCH 1/4] test: refactor fs.write() test --- test/parallel/test-fs-write.js | 55 +++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index fd0e6b768da042..b1c47fb819de99 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -34,10 +34,8 @@ common.refreshTmpDir(); fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { assert.ifError(err); console.log('open done'); - fs.write(fd, '', 0, 'utf8', function(err, written) { - assert.strictEqual(0, written); - }); - fs.write(fd, expected, 0, 'utf8', common.mustCall(function(err, written) { + + const done = common.mustCall(function(err, written) { console.log('write done'); assert.ifError(err); assert.strictEqual(Buffer.byteLength(expected), written); @@ -47,26 +45,35 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { console.log('found: "%s"', found); fs.unlinkSync(fn); assert.strictEqual(expected, found); - })); + }); + + fs.write(fd, '', 0, 'utf8', function(err, written) { + assert.strictEqual(0, written); + }); + + fs.write(fd, expected, 0, 'utf8', done); })); +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.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 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'); - 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 done = 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); + }); + + fs.write(fd, '', 0, 'utf8', (err, written) => { + assert.strictEqual(0, written); + }); + + fs.write(fd, expected, 0, 'utf8', done); +})); From 1b01bfbe36693cc7994c98626feb27f3f68b5029 Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Mon, 6 Nov 2017 16:05:05 +0000 Subject: [PATCH 2/4] add common.mustCall() --- test/parallel/test-fs-write.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index b1c47fb819de99..78dece8a92ef26 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -47,10 +47,11 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { assert.strictEqual(expected, found); }); - fs.write(fd, '', 0, 'utf8', function(err, written) { + const written = common.mustCall(function(err, written) { assert.strictEqual(0, written); }); + fs.write(fd, '', 0, 'utf8', written); fs.write(fd, expected, 0, 'utf8', done); })); @@ -71,9 +72,10 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => { assert.strictEqual(expected, found); }); - fs.write(fd, '', 0, 'utf8', (err, written) => { + const written = common.mustCall(function(err, written) { assert.strictEqual(0, written); }); + fs.write(fd, '', 0, 'utf8', written); fs.write(fd, expected, 0, 'utf8', done); })); From cdaefa6a17b05b92b5845a37f2fa2de6acf8ae88 Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Tue, 7 Nov 2017 09:27:08 +0000 Subject: [PATCH 3/4] remove console.log() --- test/parallel/test-fs-write.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index 78dece8a92ef26..7bf31f7b2d8f2b 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -33,16 +33,12 @@ common.refreshTmpDir(); fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { assert.ifError(err); - console.log('open done'); const done = common.mustCall(function(err, written) { - console.log('write done'); assert.ifError(err); assert.strictEqual(Buffer.byteLength(expected), written); fs.closeSync(fd); const found = fs.readFileSync(fn, 'utf8'); - console.log('expected: "%s"', expected); - console.log('found: "%s"', found); fs.unlinkSync(fn); assert.strictEqual(expected, found); }); @@ -58,16 +54,12 @@ 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'); const done = 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); }); From 99412a4393db3c6d79d6649c068b0ff274fe01ac Mon Sep 17 00:00:00 2001 From: Patrick Heneise Date: Tue, 7 Nov 2017 09:37:07 +0000 Subject: [PATCH 4/4] add assert.ifError() --- test/parallel/test-fs-write.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js index 7bf31f7b2d8f2b..e861b183d966f2 100644 --- a/test/parallel/test-fs-write.js +++ b/test/parallel/test-fs-write.js @@ -44,6 +44,7 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) { }); const written = common.mustCall(function(err, written) { + assert.ifError(err); assert.strictEqual(0, written); }); @@ -65,6 +66,7 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => { }); const written = common.mustCall(function(err, written) { + assert.ifError(err); assert.strictEqual(0, written); });