node/test/simple/test-readdir.js

61 lines
1.9 KiB
JavaScript
Raw Normal View History

2011-03-10 16:54:52 +08:00
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
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
});
2010-12-05 06:45:52 +08:00
process.addListener('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
});