From 816f609c8be319747b35f7e5adb91929396f5185 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Fri, 28 Aug 2015 06:47:10 +0530 Subject: [PATCH] test: use tmpDir instead of fixtures in readdir This patch - makes the test use tmp directory instead of the fixtures directory, - simplifies the code - moves the test to `parallel`. PR-URL: https://github.com/nodejs/node/pull/2587 Reviewed-By: Rich Trott --- test/fixtures/readdir/are | 0 test/fixtures/readdir/dir/empty | 0 test/fixtures/readdir/empty | 0 test/fixtures/readdir/files | 0 test/fixtures/readdir/for | 0 test/fixtures/readdir/just | 0 test/fixtures/readdir/testing.js | 0 test/fixtures/readdir/these | 0 test/parallel/test-fs-readdir.js | 36 ++++++++++++++++ test/sequential/test-readdir.js | 71 -------------------------------- 10 files changed, 36 insertions(+), 71 deletions(-) delete mode 100644 test/fixtures/readdir/are delete mode 100644 test/fixtures/readdir/dir/empty delete mode 100644 test/fixtures/readdir/empty delete mode 100644 test/fixtures/readdir/files delete mode 100644 test/fixtures/readdir/for delete mode 100644 test/fixtures/readdir/just delete mode 100644 test/fixtures/readdir/testing.js delete mode 100644 test/fixtures/readdir/these create mode 100644 test/parallel/test-fs-readdir.js delete mode 100644 test/sequential/test-readdir.js diff --git a/test/fixtures/readdir/are b/test/fixtures/readdir/are deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/dir/empty b/test/fixtures/readdir/dir/empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/empty b/test/fixtures/readdir/empty deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/files b/test/fixtures/readdir/files deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/for b/test/fixtures/readdir/for deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/just b/test/fixtures/readdir/just deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/testing.js b/test/fixtures/readdir/testing.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/fixtures/readdir/these b/test/fixtures/readdir/these deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/parallel/test-fs-readdir.js b/test/parallel/test-fs-readdir.js new file mode 100644 index 0000000000..b08f42b5c2 --- /dev/null +++ b/test/parallel/test-fs-readdir.js @@ -0,0 +1,36 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); + +const readdirDir = common.tmpDir; +const files = ['empty', 'files', 'for', 'just', 'testing']; + +// Make sure tmp directory is clean +common.refreshTmpDir(); + +// Create the necessary files +files.forEach(function(currentFile) { + fs.closeSync(fs.openSync(readdirDir + '/' + currentFile, 'w')); +}); + +// Check the readdir Sync version +assert.deepEqual(files, fs.readdirSync(readdirDir).sort()); + +// Check the readdir async version +fs.readdir(readdirDir, common.mustCall(function(err, f) { + assert.ifError(err); + assert.deepEqual(files, f.sort()); +})); + +// readdir() on file should throw ENOTDIR +// https://github.com/joyent/node/issues/1869 +assert.throws(function() { + fs.readdirSync(__filename); +}, /Error: ENOTDIR: not a directory/); + +fs.readdir(__filename, common.mustCall(function(e) { + assert.equal(e.code, 'ENOTDIR'); +})); diff --git a/test/sequential/test-readdir.js b/test/sequential/test-readdir.js deleted file mode 100644 index 4987dc1848..0000000000 --- a/test/sequential/test-readdir.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -var got_error = false, - readdirDir = path.join(common.fixturesDir, 'readdir'); - -var files = ['are', - 'dir', - 'empty', - 'files', - 'for', - 'just', - 'testing.js', - 'these']; - - -console.log('readdirSync ' + readdirDir); -var f = fs.readdirSync(readdirDir); -console.dir(f); -assert.deepEqual(files, f.sort()); - - -console.log('readdir ' + readdirDir); -fs.readdir(readdirDir, function(err, f) { - if (err) { - console.log('error'); - got_error = true; - } else { - console.dir(f); - assert.deepEqual(files, f.sort()); - } -}); - -process.on('exit', function() { - assert.equal(false, got_error); - console.log('exit'); -}); - - -// readdir() on file should throw ENOTDIR -// https://github.com/joyent/node/issues/1869 -(function() { - var has_caught = false; - - try { - fs.readdirSync(__filename); - } - catch (e) { - has_caught = true; - assert.equal(e.code, 'ENOTDIR'); - } - - assert(has_caught); -})(); - - -(function() { - var readdir_cb_called = false; - - fs.readdir(__filename, function(e) { - readdir_cb_called = true; - assert.equal(e.code, 'ENOTDIR'); - }); - - process.on('exit', function() { - assert(readdir_cb_called); - }); -})();