mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
test/pwd
This commit is contained in:
parent
f4a2ae3379
commit
17bda2e0e5
2
shell.js
2
shell.js
@ -148,7 +148,7 @@ function _cd(options, dir) {
|
||||
exports.cd = wrap('cd', _cd);
|
||||
|
||||
//@
|
||||
//@ #### pwd()
|
||||
//@ #### shell.pwd()
|
||||
//@ Returns the current directory.
|
||||
function _pwd(options) {
|
||||
return path.resolve(process.cwd());
|
||||
|
||||
48
test/cd.js
48
test/cd.js
@ -1,4 +1,4 @@
|
||||
require('../maker');
|
||||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
@ -7,55 +7,55 @@ var assert = require('assert'),
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
silent();
|
||||
shell.silent();
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
// save current dir
|
||||
var cur = pwd();
|
||||
var cur = shell.pwd();
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
cd();
|
||||
assert.ok(error());
|
||||
shell.cd();
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
cd('/adsfasdf'); // dir does not exist
|
||||
assert.ok(error());
|
||||
shell.cd('/adsfasdf'); // dir does not exist
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('resources/file1'), true); // sanity check
|
||||
cd('resources/file1'); // file, not dir
|
||||
assert.ok(error());
|
||||
shell.cd('resources/file1'); // file, not dir
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
cd(cur);
|
||||
cd('tmp');
|
||||
assert.equal(error(), null);
|
||||
shell.cd(cur);
|
||||
shell.cd('tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(path.basename(process.cwd()), 'tmp');
|
||||
|
||||
cd(cur);
|
||||
cd('/');
|
||||
assert.equal(error(), null);
|
||||
shell.cd(cur);
|
||||
shell.cd('/');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), path.resolve('/'));
|
||||
|
||||
// cd + other commands
|
||||
|
||||
cd(cur);
|
||||
rm('-f tmp/*');
|
||||
shell.cd(cur);
|
||||
shell.rm('-f', 'tmp/*');
|
||||
assert.equal(fs.existsSync('tmp/file1'), false);
|
||||
cd('resources');
|
||||
assert.equal(error(), null);
|
||||
cp('file1 ../tmp');
|
||||
assert.equal(error(), null);
|
||||
cd('../tmp');
|
||||
assert.equal(error(), null);
|
||||
shell.cd('resources');
|
||||
assert.equal(shell.error(), null);
|
||||
shell.cp('file1', '../tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
shell.cd('../tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), true);
|
||||
|
||||
exit(123);
|
||||
shell.exit(123);
|
||||
|
||||
16
test/pwd.js
16
test/pwd.js
@ -1,9 +1,9 @@
|
||||
require('../maker');
|
||||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path');
|
||||
|
||||
silent();
|
||||
shell.silent();
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
@ -13,13 +13,13 @@ function numLines(str) {
|
||||
// Valids
|
||||
//
|
||||
|
||||
var _pwd = pwd();
|
||||
assert.equal(error(), null);
|
||||
var _pwd = shell.pwd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(_pwd, path.resolve('.'));
|
||||
|
||||
cd('tmp');
|
||||
var _pwd = pwd();
|
||||
assert.equal(error(), null);
|
||||
shell.cd('tmp');
|
||||
var _pwd = shell.pwd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(path.basename(_pwd), 'tmp');
|
||||
|
||||
exit(123);
|
||||
shell.exit(123);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user