node/test/sequential/test-readdir.js

71 lines
1.3 KiB
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
2009-09-04 03:29:20 +08:00
2010-02-26 08:32:30 +08:00
var got_error = false,
2010-12-05 06:45:52 +08:00
readdirDir = path.join(common.fixturesDir, 'readdir');
2009-09-04 03:29:20 +08:00
2010-12-05 06:45:52 +08:00
var files = ['are',
'dir',
'empty',
'files',
'for',
'just',
'testing.js',
'these'];
2010-02-22 15:02:36 +08:00
console.log('readdirSync ' + readdirDir);
2010-02-26 08:32:30 +08:00
var f = fs.readdirSync(readdirDir);
2010-10-12 07:09:02 +08:00
console.dir(f);
2010-02-22 15:02:36 +08:00
assert.deepEqual(files, f.sort());
2010-12-05 06:45:52 +08:00
console.log('readdir ' + readdirDir);
fs.readdir(readdirDir, function(err, f) {
2010-02-20 08:02:30 +08:00
if (err) {
2010-12-05 06:45:52 +08:00
console.log('error');
2010-02-20 08:02:30 +08:00
got_error = true;
} else {
2010-10-12 07:09:02 +08:00
console.dir(f);
2010-02-22 15:02:36 +08:00
assert.deepEqual(files, f.sort());
2010-02-20 08:02:30 +08:00
}
2009-09-04 03:29:20 +08:00
});
process.on('exit', function() {
assert.equal(false, got_error);
2010-12-05 06:45:52 +08:00
console.log('exit');
2009-09-04 03:29:20 +08:00
});
// readdir() on file should throw ENOTDIR
// https://github.com/joyent/node/issues/1869
(function() {
var has_caught = false;
try {
2012-01-18 02:43:34 +08:00
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);
});
2011-11-03 07:26:43 +08:00
})();