|
@ -4,11 +4,11 @@ const assert = require('assert'); |
|
|
const util = require('util'); |
|
|
const util = require('util'); |
|
|
const fs = require('fs'); |
|
|
const fs = require('fs'); |
|
|
|
|
|
|
|
|
var tests_ok = 0; |
|
|
let tests_ok = 0; |
|
|
var tests_run = 0; |
|
|
let tests_run = 0; |
|
|
|
|
|
|
|
|
function stat_resource(resource) { |
|
|
function stat_resource(resource) { |
|
|
if (typeof resource == 'string') { |
|
|
if (typeof resource === 'string') { |
|
|
return fs.statSync(resource); |
|
|
return fs.statSync(resource); |
|
|
} else { |
|
|
} else { |
|
|
// ensure mtime has been written to disk
|
|
|
// ensure mtime has been written to disk
|
|
@ -19,8 +19,8 @@ function stat_resource(resource) { |
|
|
|
|
|
|
|
|
function check_mtime(resource, mtime) { |
|
|
function check_mtime(resource, mtime) { |
|
|
mtime = fs._toUnixTimestamp(mtime); |
|
|
mtime = fs._toUnixTimestamp(mtime); |
|
|
var stats = stat_resource(resource); |
|
|
const stats = stat_resource(resource); |
|
|
var real_mtime = fs._toUnixTimestamp(stats.mtime); |
|
|
const real_mtime = fs._toUnixTimestamp(stats.mtime); |
|
|
// check up to single-second precision
|
|
|
// check up to single-second precision
|
|
|
// sub-second precision is OS and fs dependant
|
|
|
// sub-second precision is OS and fs dependant
|
|
|
return mtime - real_mtime < 2; |
|
|
return mtime - real_mtime < 2; |
|
@ -46,9 +46,9 @@ function expect_ok(syscall, resource, err, atime, mtime) { |
|
|
// the tests assume that __filename belongs to the user running the tests
|
|
|
// the tests assume that __filename belongs to the user running the tests
|
|
|
// this should be a fairly safe assumption; testing against a temp file
|
|
|
// this should be a fairly safe assumption; testing against a temp file
|
|
|
// would be even better though (node doesn't have such functionality yet)
|
|
|
// 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
|
|
|
// test synchronized code paths, these functions throw on failure
|
|
|
//
|
|
|
//
|
|
@ -67,8 +67,7 @@ function runTest(atime, mtime, callback) { |
|
|
expect_errno('futimesSync', fd, ex, 'ENOSYS'); |
|
|
expect_errno('futimesSync', fd, ex, 'ENOSYS'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var err; |
|
|
let err = undefined; |
|
|
err = undefined; |
|
|
|
|
|
try { |
|
|
try { |
|
|
fs.utimesSync('foobarbaz', atime, mtime); |
|
|
fs.utimesSync('foobarbaz', atime, mtime); |
|
|
} catch (ex) { |
|
|
} catch (ex) { |
|
@ -90,10 +89,10 @@ function runTest(atime, mtime, callback) { |
|
|
//
|
|
|
//
|
|
|
// test async code paths
|
|
|
// 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); |
|
|
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'); |
|
|
expect_errno('utimes', 'foobarbaz', err, 'ENOENT'); |
|
|
|
|
|
|
|
|
// don't close this fd
|
|
|
// don't close this fd
|
|
@ -103,34 +102,36 @@ function runTest(atime, mtime, callback) { |
|
|
fd = fs.openSync(__filename, 'r'); |
|
|
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); |
|
|
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'); |
|
|
expect_errno('futimes', -1, err, 'EBADF'); |
|
|
syncTests(); |
|
|
syncTests(); |
|
|
callback(); |
|
|
callback(); |
|
|
}); |
|
|
})); |
|
|
tests_run++; |
|
|
tests_run++; |
|
|
}); |
|
|
})); |
|
|
tests_run++; |
|
|
tests_run++; |
|
|
}); |
|
|
})); |
|
|
tests_run++; |
|
|
tests_run++; |
|
|
}); |
|
|
})); |
|
|
tests_run++; |
|
|
tests_run++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var stats = fs.statSync(__filename); |
|
|
const stats = fs.statSync(__filename); |
|
|
|
|
|
|
|
|
// run tests
|
|
|
// 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('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { |
|
|
runTest(new Date(), new Date(), function() { |
|
|
runTest(new Date(), new Date(), function() { |
|
|
runTest(123456.789, 123456.789, function() { |
|
|
runTest(123456.789, 123456.789, function() { |
|
|
runTest(stats.mtime, stats.mtime, function() { |
|
|
runTest(stats.mtime, stats.mtime, function() { |
|
|
runTest(NaN, Infinity, function() { |
|
|
runTest(NaN, Infinity, function() { |
|
|
runTest('123456', -1, function() { |
|
|
runTest('123456', -1, common.mustCall(function() { |
|
|
// done
|
|
|
// done
|
|
|
}); |
|
|
})); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
@ -140,5 +141,5 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { |
|
|
|
|
|
|
|
|
process.on('exit', function() { |
|
|
process.on('exit', function() { |
|
|
console.log('Tests run / ok:', tests_run, '/', tests_ok); |
|
|
console.log('Tests run / ok:', tests_run, '/', tests_ok); |
|
|
assert.equal(tests_ok, tests_run); |
|
|
assert.strictEqual(tests_ok, tests_run); |
|
|
}); |
|
|
}); |
|
|