From e6b631f73a911ce72573bc4cbc196f25a07b0614 Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Thu, 5 Jul 2018 18:08:42 -0700 Subject: [PATCH 1/2] chore: rename some tests No change to logic. This renames some tests to be a bit more readable. --- test/cp.js | 53 ++++++++++++++++++++++------------------------------ test/echo.js | 6 +++--- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/test/cp.js b/test/cp.js index 8ada327ad..862a2846b 100644 --- a/test/cp.js +++ b/test/cp.js @@ -54,7 +54,7 @@ test('invalid option', t => { t.is(result.stderr, 'cp: option not recognized: @'); }); -test('invalid option', t => { +test('invalid option #2', t => { const result = shell.cp('-Z', 'asdfasdf', `${t.context.tmp}/file2`); t.truthy(shell.error()); t.is(result.code, 1); @@ -265,9 +265,8 @@ test('recursive, nothing exists', t => { t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString()); }); -test( - 'recursive, nothing exists, source ends in \'/\' (see Github issue #15)', - t => { +test('recursive, nothing exists, source ends in "/"', t => { + // Github issue #15 const result = shell.cp('-R', 'test/resources/cp/', `${t.context.tmp}/`); t.falsy(shell.error()); t.falsy(result.stderr); @@ -276,9 +275,8 @@ test( } ); -test( - 'recursive, globbing regular files with extension (see Github issue #376)', - t => { +test('recursive, globbing regular files with extension', t => { + // Github issue #376 const result = shell.cp('-R', 'test/resources/file*.txt', t.context.tmp); t.falsy(shell.error()); t.falsy(result.stderr); @@ -288,9 +286,8 @@ test( } ); -test( - 'recursive, copying one regular file (also related to Github issue #376)', - t => { +test('recursive, copying one regular file', t => { + // Github issue #376 const result = shell.cp('-R', 'test/resources/file1.txt', t.context.tmp); t.falsy(shell.error()); t.falsy(result.stderr); @@ -365,9 +362,8 @@ test('recursive, everything exists, with force flag', t => { t.is(shell.cat('test/resources/cp/dir_a/z').toString(), shell.cat(`${t.context.tmp}/cp/dir_a/z`).toString()); // after cp }); -test( - 'recursive, creates dest dir since it\'s only one level deep (see Github issue #44)', - t => { +test("recursive, creates dest dir since it's only one level deep", t => { + // Github issue #44 const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2`); t.falsy(shell.error()); t.falsy(result.stderr); @@ -380,9 +376,8 @@ test( } ); -test( - 'recursive, does *not* create dest dir since it\'s too deep (see Github issue #44)', - t => { +test("recursive, does *not* create dest dir since it's too deep", t => { + // Github issue #44 const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2/dir3`); t.truthy(shell.error()); t.is( @@ -409,21 +404,17 @@ test('recursive, with trailing slash, does the exact same', t => { t.truthy(fs.existsSync(`${t.context.tmp}/dest/z`)); }); -test( - 'On Windows, permission bits are quite different so skip those tests for now', - t => { - utils.skipOnWin(t, () => { - // preserve mode bits - const execBit = parseInt('001', 8); - t.is(common.statFollowLinks('test/resources/cp-mode-bits/executable').mode & execBit, execBit); - shell.cp('test/resources/cp-mode-bits/executable', `${t.context.tmp}/executable`); - t.is( - common.statFollowLinks('test/resources/cp-mode-bits/executable').mode, - common.statFollowLinks(`${t.context.tmp}/executable`).mode - ); - }); - } -); +test('preserve mode bits by default for file', t => { + utils.skipOnWin(t, () => { + const execBit = parseInt('001', 8); + t.is(common.statFollowLinks('test/resources/cp-mode-bits/executable').mode & execBit, execBit); + shell.cp('test/resources/cp-mode-bits/executable', `${t.context.tmp}/executable`); + t.is( + common.statFollowLinks('test/resources/cp-mode-bits/executable').mode, + common.statFollowLinks(`${t.context.tmp}/executable`).mode + ); + }); +}); test('Make sure hidden files are copied recursively', t => { shell.rm('-rf', t.context.tmp); diff --git a/test/echo.js b/test/echo.js index f8afbee26..1d571e49b 100644 --- a/test/echo.js +++ b/test/echo.js @@ -31,7 +31,7 @@ test('simple test with defaults', t => { }); test('allow arguments to begin with a hyphen', t => { - // see issue #20 + // Github issue #20 const result = shell.echo('-asdf', '111'); const stdout = mocks.stdout(); const stderr = mocks.stderr(); @@ -62,7 +62,7 @@ test('-e option', t => { }); test('piping to a file', t => { - // see issue #476 + // Github issue #476 shell.mkdir(t.context.tmp); const tmp = `${t.context.tmp}/echo.txt`; const resultA = shell.echo('A').toEnd(tmp); @@ -121,7 +121,7 @@ test('-en option with escaped characters', t => { }); test('piping to a file with -n', t => { - // see issue #476 + // Github issue #476 shell.mkdir(t.context.tmp); const tmp = `${t.context.tmp}/echo.txt`; const resultA = shell.echo('-n', 'A').toEnd(tmp); From 1f15fbb118ebeff72c960144f7e761dc47bb8e59 Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Mon, 9 Jul 2018 21:48:38 -0700 Subject: [PATCH 2/2] fix indentation for lint --- test/cp.js | 86 ++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/test/cp.js b/test/cp.js index 862a2846b..c059e8b53 100644 --- a/test/cp.js +++ b/test/cp.js @@ -266,35 +266,33 @@ test('recursive, nothing exists', t => { }); test('recursive, nothing exists, source ends in "/"', t => { - // Github issue #15 - const result = shell.cp('-R', 'test/resources/cp/', `${t.context.tmp}/`); - t.falsy(shell.error()); - t.falsy(result.stderr); - t.is(result.code, 0); - t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString()); - } -); + // Github issue #15 + const result = shell.cp('-R', 'test/resources/cp/', `${t.context.tmp}/`); + t.falsy(shell.error()); + t.falsy(result.stderr); + t.is(result.code, 0); + t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString()); +}); test('recursive, globbing regular files with extension', t => { - // Github issue #376 - const result = shell.cp('-R', 'test/resources/file*.txt', t.context.tmp); - t.falsy(shell.error()); - t.falsy(result.stderr); - t.is(result.code, 0); - t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`)); - t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`)); - } -); + // Github issue #376 + const result = shell.cp('-R', 'test/resources/file*.txt', t.context.tmp); + t.falsy(shell.error()); + t.falsy(result.stderr); + t.is(result.code, 0); + t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`)); + t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`)); +}); test('recursive, copying one regular file', t => { - // Github issue #376 - const result = shell.cp('-R', 'test/resources/file1.txt', t.context.tmp); - t.falsy(shell.error()); - t.falsy(result.stderr); - t.is(result.code, 0); - t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`)); - t.falsy(common.statFollowLinks(`${t.context.tmp}/file1.txt`).isDirectory()); // don't let it be a dir - } + // Github issue #376 + const result = shell.cp('-R', 'test/resources/file1.txt', t.context.tmp); + t.falsy(shell.error()); + t.falsy(result.stderr); + t.is(result.code, 0); + t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`)); + t.falsy(common.statFollowLinks(`${t.context.tmp}/file1.txt`).isDirectory()); // don't let it be a dir +} ); test('recursive, everything exists, no force flag', t => { @@ -363,31 +361,29 @@ test('recursive, everything exists, with force flag', t => { }); test("recursive, creates dest dir since it's only one level deep", t => { - // Github issue #44 - const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2`); - t.falsy(shell.error()); - t.falsy(result.stderr); - t.is(result.code, 0); - t.is(shell.ls('-R', 'test/resources/issue44').toString(), shell.ls('-R', `${t.context.tmp}/dir2`).toString()); - t.is( + // Github issue #44 + const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2`); + t.falsy(shell.error()); + t.falsy(result.stderr); + t.is(result.code, 0); + t.is(shell.ls('-R', 'test/resources/issue44').toString(), shell.ls('-R', `${t.context.tmp}/dir2`).toString()); + t.is( shell.cat('test/resources/issue44/main.js').toString(), shell.cat(`${t.context.tmp}/dir2/main.js`).toString() ); - } -); +}); test("recursive, does *not* create dest dir since it's too deep", t => { - // Github issue #44 - const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2/dir3`); - t.truthy(shell.error()); - t.is( - result.stderr, - `cp: cannot create directory '${t.context.tmp}/dir2/dir3': No such file or directory` - ); - t.is(result.code, 1); - t.falsy(fs.existsSync(`${t.context.tmp}/dir2`)); - } -); + // Github issue #44 + const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2/dir3`); + t.truthy(shell.error()); + t.is( + result.stderr, + `cp: cannot create directory '${t.context.tmp}/dir2/dir3': No such file or directory` + ); + t.is(result.code, 1); + t.falsy(fs.existsSync(`${t.context.tmp}/dir2`)); +}); test('recursive, copies entire directory', t => { const result = shell.cp('-r', 'test/resources/cp/dir_a', `${t.context.tmp}/dest`);