Skip to content

Commit efa05f2

Browse files
authored
test: capture negative utimes mtime at call time
PR-URL: #62490 Refs: #37692 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8a48913 commit efa05f2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test/parallel/test-fs-utimes.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ function expect_ok(syscall, resource, err, atime, mtime, statSync) {
7070
);
7171
}
7272

73+
function getExpectedMtime(mtime) {
74+
// Negative numeric timestamps are normalized to "now" at call time.
75+
return fs._toUnixTimestamp(mtime);
76+
}
77+
7378
const stats = fs.statSync(tmpdir.path);
7479

7580
const asPath = (path) => path;
@@ -98,11 +103,13 @@ function runTests(iter) {
98103
//
99104
// test async code paths
100105
//
106+
const expectedUtimesMtime = getExpectedMtime(mtime);
101107
fs.utimes(pathType(tmpdir.path), atime, mtime, common.mustCall((err) => {
102-
expect_ok('utimes', tmpdir.path, err, atime, mtime);
108+
expect_ok('utimes', tmpdir.path, err, atime, expectedUtimesMtime);
103109

110+
const expectedLutimesMtime = getExpectedMtime(mtime);
104111
fs.lutimes(pathType(lpath), atime, mtime, common.mustCall((err) => {
105-
expect_ok('lutimes', lpath, err, atime, mtime, fs.lstatSync);
112+
expect_ok('lutimes', lpath, err, atime, expectedLutimesMtime, fs.lstatSync);
106113

107114
fs.utimes(pathType('foobarbaz'), atime, mtime, common.mustCall((err) => {
108115
expect_errno('utimes', 'foobarbaz', err, 'ENOENT');
@@ -114,8 +121,9 @@ function runTests(iter) {
114121
fd = fs.openSync(tmpdir.path, 'r');
115122
}
116123

124+
const expectedFutimesMtime = getExpectedMtime(mtime);
117125
fs.futimes(fd, atime, mtime, common.mustCall((err) => {
118-
expect_ok('futimes', fd, err, atime, mtime);
126+
expect_ok('futimes', fd, err, atime, expectedFutimesMtime);
119127

120128
syncTests();
121129

@@ -129,17 +137,20 @@ function runTests(iter) {
129137
// test synchronized code paths, these functions throw on failure
130138
//
131139
function syncTests() {
140+
const expectedUtimesMtime = getExpectedMtime(mtime);
132141
fs.utimesSync(pathType(tmpdir.path), atime, mtime);
133-
expect_ok('utimesSync', tmpdir.path, undefined, atime, mtime);
142+
expect_ok('utimesSync', tmpdir.path, undefined, atime, expectedUtimesMtime);
134143

144+
const expectedLutimesMtime = getExpectedMtime(mtime);
135145
fs.lutimesSync(pathType(lpath), atime, mtime);
136-
expect_ok('lutimesSync', lpath, undefined, atime, mtime, fs.lstatSync);
146+
expect_ok('lutimesSync', lpath, undefined, atime, expectedLutimesMtime, fs.lstatSync);
137147

138148
// Some systems don't have futimes
139149
// if there's an error, it should be ENOSYS
140150
try {
151+
const expectedFutimesMtime = getExpectedMtime(mtime);
141152
fs.futimesSync(fd, atime, mtime);
142-
expect_ok('futimesSync', fd, undefined, atime, mtime);
153+
expect_ok('futimesSync', fd, undefined, atime, expectedFutimesMtime);
143154
} catch (ex) {
144155
expect_errno('futimesSync', fd, ex, 'ENOSYS');
145156
}

0 commit comments

Comments
 (0)