Skip to content

Commit 346fca4

Browse files
nfischerfreitagbr
authored andcommitted
test: don't count hard-to-test lines for coverage (shelljs#672)
No change in logic. Add `/* istanbul ignore next */` lines for hard-to-test lines so that they don't count against us during code coverage. I've also adjusted comments that I found confusing, and changed some formatting. Partial fix for shelljs#671
1 parent eb5230a commit 346fca4

File tree

9 files changed

+26
-4
lines changed

9 files changed

+26
-4
lines changed

src/common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ exports.platform = platform;
7373
var pipeMethods = [];
7474

7575
function log() {
76+
/* istanbul ignore next */
7677
if (!config.silent) {
7778
console.error.apply(console, arguments);
7879
}
@@ -259,6 +260,7 @@ function unlinkSync(file) {
259260
fs.unlinkSync(file);
260261
} catch (e) {
261262
// Try to override file permission
263+
/* istanbul ignore next */
262264
if (e.code === 'EPERM') {
263265
fs.chmodSync(file, '0666');
264266
fs.unlinkSync(file);
@@ -364,6 +366,7 @@ function wrap(cmd, fn, options) {
364366

365367
retValue = fn.apply(this, args);
366368
} catch (e) {
369+
/* istanbul ignore else */
367370
if (e.msg === 'earlyExit') {
368371
retValue = e.retValue;
369372
} else {
@@ -372,6 +375,7 @@ function wrap(cmd, fn, options) {
372375
}
373376
}
374377
} catch (e) {
378+
/* istanbul ignore next */
375379
if (!state.error) {
376380
// If state.error hasn't been set it's an error thrown by Node, not us - probably a bug...
377381
console.error('ShellJS: internal error');

src/cp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ function copyFileSync(srcFile, destFile, options) {
5454
try {
5555
fdr = fs.openSync(srcFile, 'r');
5656
} catch (e) {
57+
/* istanbul ignore next */
5758
common.error('copyFileSync: could not read src file (' + srcFile + ')');
5859
}
5960

6061
try {
6162
fdw = fs.openSync(destFile, 'w');
6263
} catch (e) {
64+
/* istanbul ignore next */
6365
common.error('copyFileSync: could not write to dest file (code=' + e.code + '):' + destFile);
6466
}
6567

@@ -243,6 +245,7 @@ function _cp(options, sources, dest) {
243245
fs.statSync(path.dirname(dest));
244246
cpdirSyncRecursive(src, newDest, 0, { no_force: options.no_force, followsymlink: options.followsymlink });
245247
} catch (e) {
248+
/* istanbul ignore next */
246249
common.error("cannot create directory '" + dest + "': No such file or directory");
247250
}
248251
}

src/mkdir.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function _mkdir(options, dirs) {
8383
if (e.code === 'EACCES') {
8484
common.error('cannot create directory ' + dir + ': Permission denied');
8585
} else {
86+
/* istanbul ignore next */
8687
throw e;
8788
}
8889
}

src/mv.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function _mv(options, sources, dest) {
3838
} else if (typeof sources === 'string') {
3939
sources = [sources];
4040
} else {
41+
// TODO(nate): figure out if we actually need this line
4142
common.error('invalid arguments');
4243
}
4344

@@ -82,9 +83,12 @@ function _mv(options, sources, dest) {
8283
try {
8384
fs.renameSync(src, thisDest);
8485
} catch (e) {
85-
if (e.code === 'EXDEV') { // external partition
86-
// if either of these fails, the appropriate error message will bubble
87-
// up to the top level automatically
86+
/* istanbul ignore next */
87+
if (e.code === 'EXDEV') {
88+
// If we're trying to `mv` to an external partition, we'll actually need
89+
// to perform a copy and then clean up the original file. If either the
90+
// copy or the rm fails with an exception, we should allow this
91+
// exception to pass up to the top level.
8892
cp('-r', src, thisDest);
8993
rm('-rf', src);
9094
}

src/rm.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function rmdirSyncRecursive(dir, force) {
3434
try {
3535
common.unlinkSync(file);
3636
} catch (e) {
37-
common.error('could not remove file (code ' + e.code + '): ' + file, { continue: true });
37+
/* istanbul ignore next */
38+
common.error('could not remove file (code ' + e.code + '): ' + file, {
39+
continue: true,
40+
});
3841
}
3942
}
4043
}
@@ -55,6 +58,7 @@ function rmdirSyncRecursive(dir, force) {
5558
if (fs.existsSync(dir)) throw { code: 'EAGAIN' };
5659
break;
5760
} catch (er) {
61+
/* istanbul ignore next */
5862
// In addition to error codes, also check if the directory still exists and loop again if true
5963
if (process.platform === 'win32' && (er.code === 'ENOTEMPTY' || er.code === 'EBUSY' || er.code === 'EPERM' || er.code === 'EAGAIN')) {
6064
if (Date.now() - start > 1000) throw er;

src/tempdir.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function writeableDir(dir) {
1919
common.unlinkSync(testFile);
2020
return dir;
2121
} catch (e) {
22+
/* istanbul ignore next */
2223
return false;
2324
}
2425
}

src/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ function _test(options, path) {
7272

7373
if (options.file) return stats.isFile();
7474

75+
/* istanbul ignore next */
7576
if (options.pipe) return stats.isFIFO();
7677

78+
/* istanbul ignore next */
7779
if (options.socket) return stats.isSocket();
7880

81+
/* istanbul ignore next */
7982
return false; // fallback
8083
} // test
8184
module.exports = _test;

src/to.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function _to(options, file) {
3030
fs.writeFileSync(file, this.stdout || this.toString(), 'utf8');
3131
return this;
3232
} catch (e) {
33+
/* istanbul ignore next */
3334
common.error('could not write to file (code ' + e.code + '): ' + file, { continue: true });
3435
}
3536
}

src/toEnd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function _toEnd(options, file) {
2929
fs.appendFileSync(file, this.stdout || this.toString(), 'utf8');
3030
return this;
3131
} catch (e) {
32+
/* istanbul ignore next */
3233
common.error('could not append to file (code ' + e.code + '): ' + file, { continue: true });
3334
}
3435
}

0 commit comments

Comments
 (0)