0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-fs-sync-fd-leak.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

49 lines
919 B
JavaScript

var common = require('../common');
var assert = require('assert');
var fs = require('fs');
// ensure that (read|write|append)FileSync() closes the file descriptor
fs.openSync = function() {
return 42;
};
fs.closeSync = function(fd) {
assert.equal(fd, 42);
close_called++;
};
fs.readSync = function() {
throw new Error('BAM');
};
fs.writeSync = function() {
throw new Error('BAM');
};
fs.fstatSync = function() {
throw new Error('BAM');
};
ensureThrows(function() {
fs.readFileSync('dummy');
});
ensureThrows(function() {
fs.writeFileSync('dummy', 'xxx');
});
ensureThrows(function() {
fs.appendFileSync('dummy', 'xxx');
});
var close_called = 0;
function ensureThrows(cb) {
var got_exception = false;
close_called = 0;
try {
cb();
} catch (e) {
assert.equal(e.message, 'BAM');
got_exception = true;
}
assert.equal(close_called, 1);
assert.equal(got_exception, true);
}