зеркало из https://github.com/microsoft/shelljs.git
Improved tests a little bit.
Added pwd check to all tests, and added a test for invalid use of popd. More tests to come.
This commit is contained in:
Родитель
02efac873c
Коммит
387babda6b
19
test/popd.js
19
test/popd.js
|
@ -7,16 +7,17 @@ var assert = require('assert'),
|
|||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = false;
|
||||
shell.config.silent = true;
|
||||
|
||||
var root = path.resolve(), trail;
|
||||
|
||||
// Pushing to valid directories
|
||||
// Valid
|
||||
shell.pushd('resources/pushd');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 1);
|
||||
assert.equal(trail[0], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
shell.pushd('resources/pushd');
|
||||
shell.pushd('a');
|
||||
|
@ -25,6 +26,7 @@ assert.equal(shell.error(), null);
|
|||
assert.equal(trail.length, 2);
|
||||
assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
shell.pushd('b');
|
||||
trail = shell.popd();
|
||||
|
@ -32,6 +34,7 @@ assert.equal(shell.error(), null);
|
|||
assert.equal(trail.length, 2);
|
||||
assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
shell.pushd('b');
|
||||
shell.pushd('c');
|
||||
|
@ -41,11 +44,23 @@ assert.equal(trail.length, 3);
|
|||
assert.equal(trail[0], path.resolve(root, 'resources/pushd/b'));
|
||||
assert.equal(trail[1], path.resolve(root, 'resources/pushd'));
|
||||
assert.equal(trail[2], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 2);
|
||||
assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 1);
|
||||
assert.equal(trail[0], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
// Invalid
|
||||
trail = shell.popd();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.exit(123);
|
|
@ -7,16 +7,17 @@ var assert = require('assert'),
|
|||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = false;
|
||||
shell.config.silent = true;
|
||||
|
||||
var root = path.resolve(), trail;
|
||||
|
||||
// Pushing to valid directories
|
||||
// Valid
|
||||
trail = shell.pushd('resources/pushd');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 2);
|
||||
assert.equal(path.relative(root, trail[0]), 'resources/pushd');
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.pushd('a');
|
||||
assert.equal(shell.error(), null);
|
||||
|
@ -24,6 +25,7 @@ assert.equal(trail.length, 3);
|
|||
assert.equal(path.relative(root, trail[0]), 'resources/pushd/a');
|
||||
assert.equal(path.relative(root, trail[1]), 'resources/pushd');
|
||||
assert.equal(trail[2], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.pushd('../b');
|
||||
assert.equal(shell.error(), null);
|
||||
|
@ -32,6 +34,7 @@ assert.equal(path.relative(root, trail[0]), 'resources/pushd/b');
|
|||
assert.equal(path.relative(root, trail[1]), 'resources/pushd/a');
|
||||
assert.equal(path.relative(root, trail[2]), 'resources/pushd');
|
||||
assert.equal(trail[3], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.pushd('c');
|
||||
assert.equal(shell.error(), null);
|
||||
|
@ -41,5 +44,6 @@ assert.equal(path.relative(root, trail[1]), 'resources/pushd/b');
|
|||
assert.equal(path.relative(root, trail[2]), 'resources/pushd/a');
|
||||
assert.equal(path.relative(root, trail[3]), 'resources/pushd');
|
||||
assert.equal(trail[4], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
shell.exit(123);
|
Загрузка…
Ссылка в новой задаче