@@ -70,6 +70,11 @@ function expect_ok(syscall, resource, err, atime, mtime, statSync) { |
70 | 70 | ); |
71 | 71 | } |
72 | 72 |
|
| 73 | +function getExpectedMtime(mtime) { |
| 74 | + // Negative numeric timestamps are normalized to "now" at call time. |
| 75 | + return fs._toUnixTimestamp(mtime); |
| 76 | +} |
| 77 | + |
73 | 78 | const stats = fs.statSync(tmpdir.path); |
74 | 79 |
|
75 | 80 | const asPath = (path) => path; |
@@ -98,11 +103,13 @@ function runTests(iter) { |
98 | 103 | // |
99 | 104 | // test async code paths |
100 | 105 | // |
| 106 | + const expectedUtimesMtime = getExpectedMtime(mtime); |
101 | 107 | 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); |
103 | 109 |
|
| 110 | + const expectedLutimesMtime = getExpectedMtime(mtime); |
104 | 111 | 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); |
106 | 113 |
|
107 | 114 | fs.utimes(pathType('foobarbaz'), atime, mtime, common.mustCall((err) => { |
108 | 115 | expect_errno('utimes', 'foobarbaz', err, 'ENOENT'); |
@@ -114,8 +121,9 @@ function runTests(iter) { |
114 | 121 | fd = fs.openSync(tmpdir.path, 'r'); |
115 | 122 | } |
116 | 123 |
|
| 124 | + const expectedFutimesMtime = getExpectedMtime(mtime); |
117 | 125 | fs.futimes(fd, atime, mtime, common.mustCall((err) => { |
118 | | - expect_ok('futimes', fd, err, atime, mtime); |
| 126 | + expect_ok('futimes', fd, err, atime, expectedFutimesMtime); |
119 | 127 |
|
120 | 128 | syncTests(); |
121 | 129 |
|
@@ -129,17 +137,20 @@ function runTests(iter) { |
129 | 137 | // test synchronized code paths, these functions throw on failure |
130 | 138 | // |
131 | 139 | function syncTests() { |
| 140 | + const expectedUtimesMtime = getExpectedMtime(mtime); |
132 | 141 | 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); |
134 | 143 |
|
| 144 | + const expectedLutimesMtime = getExpectedMtime(mtime); |
135 | 145 | 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); |
137 | 147 |
|
138 | 148 | // Some systems don't have futimes |
139 | 149 | // if there's an error, it should be ENOSYS |
140 | 150 | try { |
| 151 | + const expectedFutimesMtime = getExpectedMtime(mtime); |
141 | 152 | fs.futimesSync(fd, atime, mtime); |
142 | | - expect_ok('futimesSync', fd, undefined, atime, mtime); |
| 153 | + expect_ok('futimesSync', fd, undefined, atime, expectedFutimesMtime); |
143 | 154 | } catch (ex) { |
144 | 155 | expect_errno('futimesSync', fd, ex, 'ENOSYS'); |
145 | 156 | } |
|