Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor fs.write() test #16827

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions test/parallel/test-fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There probably needs to be a common.mustCall() for this callback as well.

Copy link
Author

@PatrickHeneise PatrickHeneise Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this:

  const written = common.mustCall(function(err, written) {
    assert.strictEqual(0, written);
  });

  fs.write(fd, '', 0, 'utf8', written);

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either inline or not, doesn't really matter.

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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

assert.strictEqual(0, written);
});

fs.write(fd, expected, 0, 'utf8', done);
}));