Review fixes

This commit is contained in:
Kieran Sedgwick 2014-10-24 14:19:17 -04:00
parent c4c13c1535
commit 3178ad9a45
13 changed files with 47 additions and 48 deletions

View File

@ -87,6 +87,9 @@ function FileSystem(options, callback) {
fs.stdout = STDOUT; fs.stdout = STDOUT;
fs.stderr = STDERR; fs.stderr = STDERR;
// Expose Shell constructor
this.Shell = Shell.bind(undefined, this);
// Safely expose the list of open files and file // Safely expose the list of open files and file
// descriptor management functions // descriptor management functions
var openFiles = {}; var openFiles = {};
@ -334,8 +337,4 @@ FileSystem.providers = providers;
}; };
}); });
FileSystem.prototype.shell = function(options) {
return new Shell(this, options);
};
module.exports = FileSystem; module.exports = FileSystem;

View File

@ -8,7 +8,7 @@ describe('sh.cd doesn\'t seem to be working from a relative path if I am one or
it('should properly deal with relative paths missing ./ and ../', function(done) { it('should properly deal with relative paths missing ./ and ../', function(done) {
var fs = util.fs(); var fs = util.fs();
var sh = fs.shell(); var sh = new fs.Shell();
sh.mkdirp('/home/scott', function(err) { sh.mkdirp('/home/scott', function(err) {
if(err) throw err; if(err) throw err;

View File

@ -9,7 +9,7 @@ describe('sh.ls and deep directory trees', function() {
it('should not crash when calling sh.ls() on deep directory layouts', function(done) { it('should not crash when calling sh.ls() on deep directory layouts', function(done) {
var fs = util.fs(); var fs = util.fs();
var sh = fs.shell(); var sh = new fs.Shell();
var path = ''; var path = '';
for(var i=0; i<50; i++) { for(var i=0; i<50; i++) {
@ -29,7 +29,7 @@ describe('sh.ls and deep directory trees', function() {
it('should not crash when calling sh.ls() on wide directory layouts', function(done) { it('should not crash when calling sh.ls() on wide directory layouts', function(done) {
var fs = util.fs(); var fs = util.fs();
var sh = fs.shell(); var sh = new fs.Shell();
var dirName = '/dir'; var dirName = '/dir';

View File

@ -85,7 +85,7 @@
} }
function shell(options) { function shell(options) {
return fs().shell(options); return new (fs()).Shell(options);
} }
function cleanup(callback) { function cleanup(callback) {

View File

@ -8,14 +8,14 @@ describe("fs.shell", function() {
it("is a function", function(done) { it("is a function", function(done) {
var fs = util.fs(); var fs = util.fs();
expect(typeof fs.shell).to.equal('function'); expect(typeof fs.Shell).to.equal('function');
done(); done();
}); });
it('should return a FileSystemShell instance', function(done) { it('should return a FileSystemShell instance', function(done) {
var fs = util.fs(); var fs = util.fs();
var sh = fs.shell(); var sh = new fs.Shell();
expect(sh.prototype).to.deep.equal((new Filer.Shell(fs)).prototype); expect(sh.prototype).to.deep.equal((new Filer.Shell(fs)).prototype);
done(); done();
@ -23,7 +23,7 @@ describe("fs.shell", function() {
it('should reflect changes to the prototype', function(done){ it('should reflect changes to the prototype', function(done){
var fs = util.fs(); var fs = util.fs();
var sh = fs.shell(); var sh = new fs.Shell();
Filer.Shell.prototype.test = "foo"; Filer.Shell.prototype.test = "foo";

View File

@ -13,7 +13,7 @@ describe('FileSystemShell.cat', function() {
it('should fail when files argument is absent', function(done) { it('should fail when files argument is absent', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.cat(null, function(error, data) { shell.cat(null, function(error, data) {
expect(error).to.exist; expect(error).to.exist;
@ -25,7 +25,7 @@ describe('FileSystemShell.cat', function() {
it('should return the contents of a single file', function(done) { it('should return the contents of a single file', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "file contents"; var contents = "file contents";
fs.writeFile('/file', contents, function(err) { fs.writeFile('/file', contents, function(err) {
@ -41,7 +41,7 @@ describe('FileSystemShell.cat', function() {
it('should return the contents of multiple files', function(done) { it('should return the contents of multiple files', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "file contents"; var contents = "file contents";
var contents2 = contents + '\n' + contents; var contents2 = contents + '\n' + contents;
@ -62,7 +62,7 @@ describe('FileSystemShell.cat', function() {
it('should fail if any of multiple file paths is invalid', function(done) { it('should fail if any of multiple file paths is invalid', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "file contents"; var contents = "file contents";
var contents2 = contents + '\n' + contents; var contents2 = contents + '\n' + contents;

View File

@ -18,7 +18,7 @@ describe('FileSystemShell.cd', function() {
it('should allow changing the path to a valid dir', function(done) { it('should allow changing the path to a valid dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -34,7 +34,7 @@ describe('FileSystemShell.cd', function() {
it('should fail when changing the path to an invalid dir', function(done) { it('should fail when changing the path to an invalid dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -51,7 +51,7 @@ describe('FileSystemShell.cd', function() {
it('should fail when changing the path to a file', function(done) { it('should fail when changing the path to a file', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.writeFile('/file', 'file', function(err) { fs.writeFile('/file', 'file', function(err) {
if(err) throw err; if(err) throw err;
@ -68,7 +68,7 @@ describe('FileSystemShell.cd', function() {
it('should allow relative paths for a valid dir', function(done) { it('should allow relative paths for a valid dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -84,7 +84,7 @@ describe('FileSystemShell.cd', function() {
it('should allow .. in paths for a valid dir', function(done) { it('should allow .. in paths for a valid dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -111,7 +111,7 @@ describe('FileSystemShell.cd', function() {
fs.symlink('/dir', '/link', function(error) { fs.symlink('/dir', '/link', function(error) {
if(error) throw error; if(error) throw error;
var shell = fs.shell(); var shell = new fs.Shell();
shell.cd('link', function(error) { shell.cd('link', function(error) {
expect(error).not.to.exist; expect(error).not.to.exist;
expect(shell.pwd()).to.equal('/link'); expect(shell.pwd()).to.equal('/link');

View File

@ -34,7 +34,7 @@ describe('FileSystemShell.env', function() {
it('should fail when dirs argument is absent', function(done) { it('should fail when dirs argument is absent', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.cat(null, function(error, list) { shell.cat(null, function(error, list) {
expect(error).to.exist; expect(error).to.exist;
@ -46,7 +46,7 @@ describe('FileSystemShell.env', function() {
it('should give new value for shell.pwd() when cwd changes', function(done) { it('should give new value for shell.pwd() when cwd changes', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -62,7 +62,7 @@ describe('FileSystemShell.env', function() {
it('should create/return the default tmp dir', function(done) { it('should create/return the default tmp dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
expect(shell.env.get('TMP')).to.equal('/tmp'); expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) { shell.tempDir(function(err, tmp) {
@ -77,7 +77,7 @@ describe('FileSystemShell.env', function() {
it('should create/return the tmp dir specified in env.TMP', function(done) { it('should create/return the tmp dir specified in env.TMP', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell({ var shell = new fs.Shell({
env: { env: {
TMP: '/tempdir' TMP: '/tempdir'
} }
@ -96,7 +96,7 @@ describe('FileSystemShell.env', function() {
it('should allow repeated calls to tempDir()', function(done) { it('should allow repeated calls to tempDir()', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
expect(shell.env.get('TMP')).to.equal('/tmp'); expect(shell.env.get('TMP')).to.equal('/tmp');
shell.tempDir(function(err, tmp) { shell.tempDir(function(err, tmp) {

View File

@ -13,7 +13,7 @@ describe('FileSystemShell.exec', function() {
it('should be able to execute a command .js file from the filesystem', function(done) { it('should be able to execute a command .js file from the filesystem', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var cmdString = "fs.writeFile(args[0], args[1], callback);"; var cmdString = "fs.writeFile(args[0], args[1], callback);";
fs.writeFile('/cmd.js', cmdString, function(error) { fs.writeFile('/cmd.js', cmdString, function(error) {

View File

@ -13,7 +13,7 @@ describe('FileSystemShell.ls', function() {
it('should fail when dirs argument is absent', function(done) { it('should fail when dirs argument is absent', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.cat(null, function(error, list) { shell.cat(null, function(error, list) {
expect(error).to.exist; expect(error).to.exist;
@ -25,7 +25,7 @@ describe('FileSystemShell.ls', function() {
it('should return the contents of a simple dir', function(done) { it('should return the contents of a simple dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "a"; var contents = "a";
var contents2 = "bb"; var contents2 = "bb";
@ -63,7 +63,7 @@ describe('FileSystemShell.ls', function() {
it('should return the shallow contents of a dir tree', function(done) { it('should return the shallow contents of a dir tree', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "a"; var contents = "a";
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
@ -119,7 +119,7 @@ describe('FileSystemShell.ls', function() {
it('should return the deep contents of a dir tree', function(done) { it('should return the deep contents of a dir tree', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "a"; var contents = "a";
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {

View File

@ -13,7 +13,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should fail without a path provided', function(done) { it('should fail without a path provided', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.mkdirp(null, function(err) { shell.mkdirp(null, function(err) {
expect(err).to.exist; expect(err).to.exist;
@ -24,7 +24,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should succeed if provided path is root', function(done) { it('should succeed if provided path is root', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.mkdirp('/', function(err) { shell.mkdirp('/', function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
done(); done();
@ -33,7 +33,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should succeed if the directory exists', function(done) { it('should succeed if the directory exists', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/test', function(err){ fs.mkdir('/test', function(err){
expect(err).to.not.exist; expect(err).to.not.exist;
shell.mkdirp('/test',function(err) { shell.mkdirp('/test',function(err) {
@ -45,7 +45,7 @@ describe('FileSystemShell.mkdirp', function() {
it('fail if a file name is provided', function(done) { it('fail if a file name is provided', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){ fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist; expect(err).to.not.exist;
shell.mkdirp('/test.txt', function(err) { shell.mkdirp('/test.txt', function(err) {
@ -58,7 +58,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should succeed on a folder on root (\'/test\')', function(done) { it('should succeed on a folder on root (\'/test\')', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.mkdirp('/test', function(err) { shell.mkdirp('/test', function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
fs.exists('/test', function(dir){ fs.exists('/test', function(dir){
@ -70,7 +70,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) { it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.mkdirp('/test/test', function(err) { shell.mkdirp('/test/test', function(err) {
expect(err).to.not.exist; expect(err).to.not.exist;
fs.exists('/test', function(dir1){ fs.exists('/test', function(dir1){
@ -85,7 +85,7 @@ describe('FileSystemShell.mkdirp', function() {
it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) { it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.writeFile('/test.txt', 'test', function(err){ fs.writeFile('/test.txt', 'test', function(err){
expect(err).to.not.exist; expect(err).to.not.exist;
shell.mkdirp('/test.txt/test', function(err) { shell.mkdirp('/test.txt/test', function(err) {

View File

@ -13,7 +13,7 @@ describe('FileSystemShell.rm', function() {
it('should fail when path argument is absent', function(done) { it('should fail when path argument is absent', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.rm(null, function(error, list) { shell.rm(null, function(error, list) {
expect(error).to.exist; expect(error).to.exist;
@ -25,7 +25,7 @@ describe('FileSystemShell.rm', function() {
it('should remove a single file', function(done) { it('should remove a single file', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "a"; var contents = "a";
fs.writeFile('/file', contents, function(err) { fs.writeFile('/file', contents, function(err) {
@ -45,7 +45,7 @@ describe('FileSystemShell.rm', function() {
it('should remove an empty dir', function(done) { it('should remove an empty dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -64,7 +64,7 @@ describe('FileSystemShell.rm', function() {
it('should fail to remove a non-empty dir', function(done) { it('should fail to remove a non-empty dir', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -83,7 +83,7 @@ describe('FileSystemShell.rm', function() {
it('should remove a non-empty dir with option.recursive set', function(done) { it('should remove a non-empty dir with option.recursive set', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {
if(err) throw err; if(err) throw err;
@ -106,7 +106,7 @@ describe('FileSystemShell.rm', function() {
it('should work on a complex dir structure', function(done) { it('should work on a complex dir structure', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var contents = "a"; var contents = "a";
fs.mkdir('/dir', function(err) { fs.mkdir('/dir', function(err) {

View File

@ -20,7 +20,7 @@ describe('FileSystemShell.touch', function() {
it('should create a new file if path does not exist', function(done) { it('should create a new file if path does not exist', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.touch('/newfile', function(error) { shell.touch('/newfile', function(error) {
if(error) throw error; if(error) throw error;
@ -35,7 +35,7 @@ describe('FileSystemShell.touch', function() {
it('should skip creating a new file if options.updateOnly is true', function(done) { it('should skip creating a new file if options.updateOnly is true', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
shell.touch('/newfile', { updateOnly: true }, function(error) { shell.touch('/newfile', { updateOnly: true }, function(error) {
if(error) throw error; if(error) throw error;
@ -49,7 +49,7 @@ describe('FileSystemShell.touch', function() {
it('should update times if path does exist', function(done) { it('should update times if path does exist', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var atime = Date.parse('1 Oct 2000 15:33:22'); var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54'); var mtime = Date.parse('30 Sep 2000 06:43:54');
@ -80,7 +80,7 @@ describe('FileSystemShell.touch', function() {
it('should update times to specified date if path does exist', function(done) { it('should update times to specified date if path does exist', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = fs.shell(); var shell = new fs.Shell();
var date = Date.parse('1 Oct 2001 15:33:22'); var date = Date.parse('1 Oct 2001 15:33:22');
fs.open('/newfile', 'w', function (error, fd) { fs.open('/newfile', 'w', function (error, fd) {