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 e1fb25a

Browse filesBrowse files
committed
test(touch): add coverage for -d option
No change to production logic. We never had coverage for `touch({'-d': ...})`, so this adds test coverage. This also updates documentation to clarify the parameter should be an instance of the `Date` type. Test: `handles date argument` case
1 parent 355287e commit e1fb25a
Copy full SHA for e1fb25a

File tree

Expand file treeCollapse file tree

3 files changed

+25
-12
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-12
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,20 @@ Available options:
647647
+ `-a`: Change only the access time
648648
+ `-c`: Do not create any files
649649
+ `-m`: Change only the modification time
650-
+ `-d DATE`: Parse `DATE` and use it instead of current time
651-
+ `-r FILE`: Use `FILE`'s times instead of current time
650+
+ `{'-d': date}`: Use `date` (instance of `Date`) instead of current time
651+
+ `{'-r': file}`: Use `file`'s times instead of current time
652652

653653
Examples:
654654

655655
```javascript
656656
touch('source.js');
657-
touch('-c', '/path/to/some/dir/source.js');
658-
touch({ '-r': FILE }, '/path/to/some/dir/source.js');
657+
touch('-c', 'path/to/file.js');
658+
touch({ '-r': 'referenceFile.txt' }, 'path/to/file.js');
659+
touch({ '-d': new Date('December 17, 1995 03:24:00') }, 'path/to/file.js');
659660
```
660661

661-
Update the access and modification times of each `FILE` to the current time.
662-
A `FILE` argument that does not exist is created empty, unless `-c` is supplied.
662+
Update the access and modification times of each file to the current time.
663+
A file argument that does not exist is created empty, unless `-c` is supplied.
663664
This is a partial implementation of [`touch(1)`](http://linux.die.net/man/1/touch).
664665

665666

‎src/touch.js

Copy file name to clipboardExpand all lines: src/touch.js
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ common.register('touch', _touch, {
2020
//@ + `-a`: Change only the access time
2121
//@ + `-c`: Do not create any files
2222
//@ + `-m`: Change only the modification time
23-
//@ + `-d DATE`: Parse `DATE` and use it instead of current time
24-
//@ + `-r FILE`: Use `FILE`'s times instead of current time
23+
//@ + `{'-d': date}`: Use `date` (instance of `Date`) instead of current time
24+
//@ + `{'-r': file}`: Use `file`'s times instead of current time
2525
//@
2626
//@ Examples:
2727
//@
2828
//@ ```javascript
2929
//@ touch('source.js');
30-
//@ touch('-c', '/path/to/some/dir/source.js');
31-
//@ touch({ '-r': FILE }, '/path/to/some/dir/source.js');
30+
//@ touch('-c', 'path/to/file.js');
31+
//@ touch({ '-r': 'referenceFile.txt' }, 'path/to/file.js');
32+
//@ touch({ '-d': new Date('December 17, 1995 03:24:00') }, 'path/to/file.js');
3233
//@ ```
3334
//@
34-
//@ Update the access and modification times of each `FILE` to the current time.
35-
//@ A `FILE` argument that does not exist is created empty, unless `-c` is supplied.
35+
//@ Update the access and modification times of each file to the current time.
36+
//@ A file argument that does not exist is created empty, unless `-c` is supplied.
3637
//@ This is a partial implementation of [`touch(1)`](http://linux.die.net/man/1/touch).
3738
function _touch(opts, files) {
3839
if (!files) {

‎test/touch.js

Copy file name to clipboardExpand all lines: test/touch.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ test('uses a reference file for mtime', t => {
119119
);
120120
});
121121

122+
test('accepts -d flag', t => {
123+
const testFile = tmpFile(t);
124+
const oldStat = resetUtimes(testFile);
125+
const date = new Date('December 17, 1995 03:24:00');
126+
const result = shell.touch({'-d': date}, testFile);
127+
t.is(result.code, 0);
128+
// Compare getTime(), because Date can't be compared with triple-equals.
129+
t.is(common.statFollowLinks(testFile).mtime.getTime(), date.getTime());
130+
t.is(common.statFollowLinks(testFile).atime.getTime(), date.getTime());
131+
});
132+
122133
test('sets mtime and atime by default', t => {
123134
const testFile = tmpFile(t);
124135
const oldStat = resetUtimes(testFile);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.