From febba4c8ba3cc9775289cc6693d4c5a046529e32 Mon Sep 17 00:00:00 2001 From: Petr Bouianov Date: Thu, 17 Apr 2014 11:53:55 -0400 Subject: [PATCH] Tests that expect errors check error codes. Fixes issue78 --- src/shell/shell.js | 6 +++--- tests/spec/fs.lstat.spec.js | 1 + tests/spec/fs.mkdir.spec.js | 2 ++ tests/spec/fs.open.spec.js | 4 ++++ tests/spec/fs.readdir.spec.js | 1 + tests/spec/fs.readlink.spec.js | 2 ++ tests/spec/fs.rmdir.spec.js | 5 +++++ tests/spec/fs.stat.spec.js | 1 + tests/spec/fs.symlink.spec.js | 2 ++ tests/spec/fs.truncate.spec.js | 2 ++ tests/spec/fs.writeFile-readFile.spec.js | 1 + tests/spec/path-resolution.spec.js | 2 ++ tests/spec/shell/cat.spec.js | 2 ++ tests/spec/shell/env.spec.js | 1 + tests/spec/shell/ls.spec.js | 1 + tests/spec/shell/mkdirp.spec.js | 6 +++--- tests/spec/shell/rm.spec.js | 1 + 17 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/shell/shell.js b/src/shell/shell.js index 0913f2d..d82e074 100644 --- a/src/shell/shell.js +++ b/src/shell/shell.js @@ -154,7 +154,7 @@ define(function(require) { callback = callback || function(){}; if(!files) { - callback(new Error("Missing files argument")); + callback(new Errors.EINVAL("Missing files argument")); return; } @@ -208,7 +208,7 @@ define(function(require) { callback = callback || function(){}; if(!dir) { - callback(new Error("Missing dir argument")); + callback(new Errors.EINVAL("Missing dir argument")); return; } @@ -280,7 +280,7 @@ define(function(require) { callback = callback || function(){}; if(!path) { - callback(new Error("Missing path argument")); + callback(new Errors.EINVAL("Missing path argument")); return; } diff --git a/tests/spec/fs.lstat.spec.js b/tests/spec/fs.lstat.spec.js index b8cb35d..eaf3504 100644 --- a/tests/spec/fs.lstat.spec.js +++ b/tests/spec/fs.lstat.spec.js @@ -15,6 +15,7 @@ define(["Filer", "util"], function(Filer, util) { fs.lstat('/tmp', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(result).not.to.exist; done(); }); diff --git a/tests/spec/fs.mkdir.spec.js b/tests/spec/fs.mkdir.spec.js index b69cd75..40897bc 100644 --- a/tests/spec/fs.mkdir.spec.js +++ b/tests/spec/fs.mkdir.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.mkdir('/tmp/mydir', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); done(); }); }); @@ -23,6 +24,7 @@ define(["Filer", "util"], function(Filer, util) { fs.mkdir('/', function(error) { expect(error).to.exist; + expect(error.code).to.equal("EEXIST"); done(); }); }); diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index 5e05661..6ab8cf4 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.open('/tmp/myfile', 'w+', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(result).not.to.exist; done(); }); @@ -24,6 +25,7 @@ define(["Filer", "util"], function(Filer, util) { fs.open('/myfile', 'r+', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(result).not.to.exist; done(); }); @@ -37,6 +39,7 @@ define(["Filer", "util"], function(Filer, util) { if(error) throw error; fs.open('/tmp', 'w', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("EISDIR"); expect(result).not.to.exist; done(); }); @@ -50,6 +53,7 @@ define(["Filer", "util"], function(Filer, util) { if(error) throw error; fs.open('/tmp', 'a', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("EISDIR"); expect(result).not.to.exist; done(); }); diff --git a/tests/spec/fs.readdir.spec.js b/tests/spec/fs.readdir.spec.js index 40baedd..49ba5a9 100644 --- a/tests/spec/fs.readdir.spec.js +++ b/tests/spec/fs.readdir.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.readdir('/tmp/mydir', function(error, files) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(files).not.to.exist; done(); }); diff --git a/tests/spec/fs.readlink.spec.js b/tests/spec/fs.readlink.spec.js index 548be02..05d4430 100644 --- a/tests/spec/fs.readlink.spec.js +++ b/tests/spec/fs.readlink.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.readlink('/tmp/mydir', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); done(); }); }); @@ -23,6 +24,7 @@ define(["Filer", "util"], function(Filer, util) { fs.readlink('/', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); done(); }); }); diff --git a/tests/spec/fs.rmdir.spec.js b/tests/spec/fs.rmdir.spec.js index aba2c32..9ff5d4d 100644 --- a/tests/spec/fs.rmdir.spec.js +++ b/tests/spec/fs.rmdir.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.rmdir('/tmp/mydir', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); done(); }); }); @@ -23,6 +24,7 @@ define(["Filer", "util"], function(Filer, util) { fs.rmdir('/', function(error) { expect(error).to.exist; + expect(error.code).to.equal("EBUSY"); done(); }); }); @@ -36,6 +38,7 @@ define(["Filer", "util"], function(Filer, util) { if(error) throw error; fs.rmdir('/', function(error) { expect(error).to.exist; + expect(error.code).to.equal("EBUSY"); done(); }); }); @@ -53,6 +56,7 @@ define(["Filer", "util"], function(Filer, util) { if(error) throw error; fs.rmdir('/tmp/myfile', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOTDIR"); done(); }); }); @@ -69,6 +73,7 @@ define(["Filer", "util"], function(Filer, util) { if(error) throw error; fs.rmdir('/tmp/myfile', function (error) { expect(error).to.exist; + expect(error.code).to.equal("ENOTDIR"); done(); }); }); diff --git a/tests/spec/fs.stat.spec.js b/tests/spec/fs.stat.spec.js index b12f1e2..db13141 100644 --- a/tests/spec/fs.stat.spec.js +++ b/tests/spec/fs.stat.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/tmp', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(result).not.to.exist; done(); }); diff --git a/tests/spec/fs.symlink.spec.js b/tests/spec/fs.symlink.spec.js index ff701b7..6ae8ca7 100644 --- a/tests/spec/fs.symlink.spec.js +++ b/tests/spec/fs.symlink.spec.js @@ -14,6 +14,7 @@ define(["Filer", "util"], function(Filer, util) { fs.symlink('/', '/tmp/mydir', function(error) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); done(); }); }); @@ -23,6 +24,7 @@ define(["Filer", "util"], function(Filer, util) { fs.symlink('/tmp', '/', function(error) { expect(error).to.exist; + expect(error.code).to.equal("EEXIST"); done(); }); }); diff --git a/tests/spec/fs.truncate.spec.js b/tests/spec/fs.truncate.spec.js index 32fe256..2de9c37 100644 --- a/tests/spec/fs.truncate.spec.js +++ b/tests/spec/fs.truncate.spec.js @@ -18,6 +18,7 @@ define(["Filer", "util"], function(Filer, util) { fs.truncate('/myfile', -1, function(error) { expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); done(); }); }); @@ -28,6 +29,7 @@ define(["Filer", "util"], function(Filer, util) { fs.truncate('/', 0, function(error) { expect(error).to.exist; + expect(error.code).to.equal("EISDIR"); done(); }); }); diff --git a/tests/spec/fs.writeFile-readFile.spec.js b/tests/spec/fs.writeFile-readFile.spec.js index cf4dd04..670247f 100644 --- a/tests/spec/fs.writeFile-readFile.spec.js +++ b/tests/spec/fs.writeFile-readFile.spec.js @@ -16,6 +16,7 @@ define(["Filer", "util"], function(Filer, util) { fs.readFile('/no-such-file', 'utf8', function(error, data) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(data).not.to.exist; done(); }); diff --git a/tests/spec/path-resolution.spec.js b/tests/spec/path-resolution.spec.js index 6553be8..f96f88e 100644 --- a/tests/spec/path-resolution.spec.js +++ b/tests/spec/path-resolution.spec.js @@ -119,6 +119,7 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/myfilelink1', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOENT"); expect(result).not.to.exist; done(); }); @@ -209,6 +210,7 @@ define(["Filer", "util"], function(Filer, util) { fs.stat('/mynotdirlink/myfile', function(error, result) { expect(error).to.exist; + expect(error.code).to.equal("ENOTDIR"); expect(result).not.to.exist; done(); }); diff --git a/tests/spec/shell/cat.spec.js b/tests/spec/shell/cat.spec.js index 5464e2d..e47b353 100644 --- a/tests/spec/shell/cat.spec.js +++ b/tests/spec/shell/cat.spec.js @@ -15,6 +15,7 @@ define(["Filer", "util"], function(Filer, util) { shell.cat(null, function(error, data) { expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); expect(data).not.to.exist; done(); }); @@ -71,6 +72,7 @@ define(["Filer", "util"], function(Filer, util) { shell.cat(['/file', '/nofile'], function(err, data) { expect(err).to.exist; + expect(err.code).to.equal("ENOENT"); expect(data).not.to.exist; done(); }); diff --git a/tests/spec/shell/env.spec.js b/tests/spec/shell/env.spec.js index 05d8960..cdb2158 100644 --- a/tests/spec/shell/env.spec.js +++ b/tests/spec/shell/env.spec.js @@ -36,6 +36,7 @@ define(["Filer", "util"], function(Filer, util) { shell.cat(null, function(error, list) { expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); expect(list).not.to.exist; done(); }); diff --git a/tests/spec/shell/ls.spec.js b/tests/spec/shell/ls.spec.js index 9c51c30..716dbf7 100644 --- a/tests/spec/shell/ls.spec.js +++ b/tests/spec/shell/ls.spec.js @@ -15,6 +15,7 @@ define(["Filer", "util"], function(Filer, util) { shell.cat(null, function(error, list) { expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); expect(list).not.to.exist; done(); }); diff --git a/tests/spec/shell/mkdirp.spec.js b/tests/spec/shell/mkdirp.spec.js index afca2f7..9c760ba 100644 --- a/tests/spec/shell/mkdirp.spec.js +++ b/tests/spec/shell/mkdirp.spec.js @@ -87,9 +87,9 @@ define(["Filer", "util"], function(Filer, util) { fs.writeFile('/test.txt', 'test', function(err){ expect(err).to.not.exist; shell.mkdirp('/test.txt/test', function(err) { - expect(err).to.exist; - expect(err.code).to.equal('ENOTDIR'); - done(); + expect(err).to.exist; + expect(err.code).to.equal('ENOTDIR'); + done(); }); }); }); diff --git a/tests/spec/shell/rm.spec.js b/tests/spec/shell/rm.spec.js index bae180e..36670cb 100644 --- a/tests/spec/shell/rm.spec.js +++ b/tests/spec/shell/rm.spec.js @@ -15,6 +15,7 @@ define(["Filer", "util"], function(Filer, util) { shell.rm(null, function(error, list) { expect(error).to.exist; + expect(error.code).to.equal("EINVAL"); expect(list).not.to.exist; done(); });