Added pwd check to all tests, and added a test for invalid use of
popd. More tests to come.
This commit is contained in:
Marcus Stade 2012-12-27 18:06:52 +01:00
Родитель 02efac873c
Коммит 387babda6b
2 изменённых файлов: 23 добавлений и 4 удалений

Просмотреть файл

@ -7,16 +7,17 @@ var assert = require('assert'),
// Node shims for < v0.7 // Node shims for < v0.7
fs.existsSync = fs.existsSync || path.existsSync; fs.existsSync = fs.existsSync || path.existsSync;
shell.config.silent = false; shell.config.silent = true;
var root = path.resolve(), trail; var root = path.resolve(), trail;
// Pushing to valid directories // Valid
shell.pushd('resources/pushd'); shell.pushd('resources/pushd');
trail = shell.popd(); trail = shell.popd();
assert.equal(shell.error(), null); assert.equal(shell.error(), null);
assert.equal(trail.length, 1); assert.equal(trail.length, 1);
assert.equal(trail[0], root); assert.equal(trail[0], root);
assert.equal(process.cwd(), trail[0]);
shell.pushd('resources/pushd'); shell.pushd('resources/pushd');
shell.pushd('a'); shell.pushd('a');
@ -25,6 +26,7 @@ assert.equal(shell.error(), null);
assert.equal(trail.length, 2); assert.equal(trail.length, 2);
assert.equal(trail[0], path.resolve(root, 'resources/pushd')); assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
assert.equal(trail[1], root); assert.equal(trail[1], root);
assert.equal(process.cwd(), trail[0]);
shell.pushd('b'); shell.pushd('b');
trail = shell.popd(); trail = shell.popd();
@ -32,6 +34,7 @@ assert.equal(shell.error(), null);
assert.equal(trail.length, 2); assert.equal(trail.length, 2);
assert.equal(trail[0], path.resolve(root, 'resources/pushd')); assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
assert.equal(trail[1], root); assert.equal(trail[1], root);
assert.equal(process.cwd(), trail[0]);
shell.pushd('b'); shell.pushd('b');
shell.pushd('c'); 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[0], path.resolve(root, 'resources/pushd/b'));
assert.equal(trail[1], path.resolve(root, 'resources/pushd')); assert.equal(trail[1], path.resolve(root, 'resources/pushd'));
assert.equal(trail[2], root); assert.equal(trail[2], root);
assert.equal(process.cwd(), trail[0]);
trail = shell.popd(); trail = shell.popd();
assert.equal(shell.error(), null); assert.equal(shell.error(), null);
assert.equal(trail.length, 2); assert.equal(trail.length, 2);
assert.equal(trail[0], path.resolve(root, 'resources/pushd')); assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
assert.equal(trail[1], root); 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); shell.exit(123);

Просмотреть файл

@ -7,16 +7,17 @@ var assert = require('assert'),
// Node shims for < v0.7 // Node shims for < v0.7
fs.existsSync = fs.existsSync || path.existsSync; fs.existsSync = fs.existsSync || path.existsSync;
shell.config.silent = false; shell.config.silent = true;
var root = path.resolve(), trail; var root = path.resolve(), trail;
// Pushing to valid directories // Valid
trail = shell.pushd('resources/pushd'); trail = shell.pushd('resources/pushd');
assert.equal(shell.error(), null); assert.equal(shell.error(), null);
assert.equal(trail.length, 2); assert.equal(trail.length, 2);
assert.equal(path.relative(root, trail[0]), 'resources/pushd'); assert.equal(path.relative(root, trail[0]), 'resources/pushd');
assert.equal(trail[1], root); assert.equal(trail[1], root);
assert.equal(process.cwd(), trail[0]);
trail = shell.pushd('a'); trail = shell.pushd('a');
assert.equal(shell.error(), null); 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[0]), 'resources/pushd/a');
assert.equal(path.relative(root, trail[1]), 'resources/pushd'); assert.equal(path.relative(root, trail[1]), 'resources/pushd');
assert.equal(trail[2], root); assert.equal(trail[2], root);
assert.equal(process.cwd(), trail[0]);
trail = shell.pushd('../b'); trail = shell.pushd('../b');
assert.equal(shell.error(), null); 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[1]), 'resources/pushd/a');
assert.equal(path.relative(root, trail[2]), 'resources/pushd'); assert.equal(path.relative(root, trail[2]), 'resources/pushd');
assert.equal(trail[3], root); assert.equal(trail[3], root);
assert.equal(process.cwd(), trail[0]);
trail = shell.pushd('c'); trail = shell.pushd('c');
assert.equal(shell.error(), null); 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[2]), 'resources/pushd/a');
assert.equal(path.relative(root, trail[3]), 'resources/pushd'); assert.equal(path.relative(root, trail[3]), 'resources/pushd');
assert.equal(trail[4], root); assert.equal(trail[4], root);
assert.equal(process.cwd(), trail[0]);
shell.exit(123); shell.exit(123);