Skip to content
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
Prev Previous commit
test: refactor eqeqeq, var and use common.mustCall() in fs-utimes
  • Loading branch information
jun-oka authored and Trott committed Jan 7, 2017
commit 90b88b9d91f3b96c22225c6936eac586da1616b3
41 changes: 21 additions & 20 deletions test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const assert = require('assert');
const util = require('util');
const fs = require('fs');

var tests_ok = 0;
var tests_run = 0;
let tests_ok = 0;
let tests_run = 0;

function stat_resource(resource) {
if (typeof resource === 'string') {
Expand All @@ -19,8 +19,8 @@ function stat_resource(resource) {

function check_mtime(resource, mtime) {
mtime = fs._toUnixTimestamp(mtime);
var stats = stat_resource(resource);
var real_mtime = fs._toUnixTimestamp(stats.mtime);
const stats = stat_resource(resource);
const real_mtime = fs._toUnixTimestamp(stats.mtime);
// check up to single-second precision
// sub-second precision is OS and fs dependant
return mtime - real_mtime < 2;
Expand All @@ -46,9 +46,9 @@ function expect_ok(syscall, resource, err, atime, mtime) {
// the tests assume that __filename belongs to the user running the tests
// this should be a fairly safe assumption; testing against a temp file
// would be even better though (node doesn't have such functionality yet)
function runTest(atime, mtime, callback) {
function testIt(atime, mtime, callback) {

var fd;
let fd;
//
// test synchronized code paths, these functions throw on failure
//
Expand All @@ -67,8 +67,7 @@ function runTest(atime, mtime, callback) {
expect_errno('futimesSync', fd, ex, 'ENOSYS');
}

var err;
err = undefined;
let err = undefined;
try {
fs.utimesSync('foobarbaz', atime, mtime);
} catch (ex) {
Expand All @@ -90,10 +89,10 @@ function runTest(atime, mtime, callback) {
//
// test async code paths
//
fs.utimes(__filename, atime, mtime, function(err) {
fs.utimes(__filename, atime, mtime, common.mustCall(function(err) {
expect_ok('utimes', __filename, err, atime, mtime);

fs.utimes('foobarbaz', atime, mtime, function(err) {
fs.utimes('foobarbaz', atime, mtime, common.mustCall(function(err) {
expect_errno('utimes', 'foobarbaz', err, 'ENOENT');

// don't close this fd
Expand All @@ -103,34 +102,36 @@ function runTest(atime, mtime, callback) {
fd = fs.openSync(__filename, 'r');
}

fs.futimes(fd, atime, mtime, function(err) {
fs.futimes(fd, atime, mtime, common.mustCall(function(err) {
expect_ok('futimes', fd, err, atime, mtime);

fs.futimes(-1, atime, mtime, function(err) {
fs.futimes(-1, atime, mtime, common.mustCall(function(err) {
expect_errno('futimes', -1, err, 'EBADF');
syncTests();
callback();
});
}));
tests_run++;
});
}));
tests_run++;
});
}));
tests_run++;
});
}));
tests_run++;
}

var stats = fs.statSync(__filename);
const stats = fs.statSync(__filename);

// run tests
const runTest = common.mustCall(testIt, 6);

runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
runTest(new Date(), new Date(), function() {
runTest(123456.789, 123456.789, function() {
runTest(stats.mtime, stats.mtime, function() {
runTest(NaN, Infinity, function() {
runTest('123456', -1, function() {
runTest('123456', -1, common.mustCall(function() {
// done
});
}));
});
});
});
Expand All @@ -140,5 +141,5 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {

process.on('exit', function() {
console.log('Tests run / ok:', tests_run, '/', tests_ok);
assert.equal(tests_ok, tests_run);
assert.strictEqual(tests_ok, tests_run);
});