Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4097fb9

Browse filesBrowse files
inoway46aduh95
authored andcommitted
test: capture negative utimes mtime at call time
PR-URL: #62490 Refs: #37692 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a86c963 commit 4097fb9
Copy full SHA for 4097fb9

1 file changed

+17-6Lines changed: 17 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-fs-utimes.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-utimes.js
+17-6Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.