mirror of
https://github.com/S2-/gitlit
synced 2025-08-03 21:00:04 +02:00
add node modules to repo
This commit is contained in:
149
node_modules/tmp/test/base.js
generated
vendored
Normal file
149
node_modules/tmp/test/base.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
var
|
||||
assert = require('assert'),
|
||||
path = require('path'),
|
||||
exec = require('child_process').exec,
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
// make sure that we do not test spam the global tmp
|
||||
tmp.TMP_DIR = './tmp';
|
||||
|
||||
|
||||
function _spawnTestWithError(testFile, params, cb) {
|
||||
_spawnTest(true, testFile, params, cb);
|
||||
}
|
||||
|
||||
function _spawnTestWithoutError(testFile, params, cb) {
|
||||
_spawnTest(false, testFile, params, cb);
|
||||
}
|
||||
|
||||
function _spawnTest(passError, testFile, params, cb) {
|
||||
var
|
||||
node_path = process.argv[0],
|
||||
command = [ node_path, path.join(__dirname, testFile) ].concat(params).join(' ');
|
||||
|
||||
exec(command, function _execDone(err, stdout, stderr) {
|
||||
if (passError) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else if (stderr.length > 0) {
|
||||
return cb(stderr.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return cb(null, stdout.toString());
|
||||
});
|
||||
}
|
||||
|
||||
function _testStat(stat, mode) {
|
||||
assert.equal(stat.uid, process.getuid(), 'should have the same UID');
|
||||
assert.equal(stat.gid, process.getgid(), 'should have the same GUID');
|
||||
assert.equal(stat.mode, mode);
|
||||
}
|
||||
|
||||
function _testPrefix(prefix) {
|
||||
return function _testPrefixGenerated(err, name) {
|
||||
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
|
||||
};
|
||||
}
|
||||
|
||||
function _testPrefixSync(prefix) {
|
||||
return function _testPrefixGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testPrefix(prefix)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testPostfix(postfix) {
|
||||
return function _testPostfixGenerated(err, name) {
|
||||
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
|
||||
};
|
||||
}
|
||||
|
||||
function _testPostfixSync(postfix) {
|
||||
return function _testPostfixGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testPostfix(postfix)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testKeep(type, keep, cb) {
|
||||
_spawnTestWithError('keep.js', [ type, keep ], cb);
|
||||
}
|
||||
|
||||
function _testKeepSync(type, keep, cb) {
|
||||
_spawnTestWithError('keep-sync.js', [ type, keep ], cb);
|
||||
}
|
||||
|
||||
function _testGraceful(type, graceful, cb) {
|
||||
_spawnTestWithoutError('graceful.js', [ type, graceful ], cb);
|
||||
}
|
||||
|
||||
function _testGracefulSync(type, graceful, cb) {
|
||||
_spawnTestWithoutError('graceful-sync.js', [ type, graceful ], cb);
|
||||
}
|
||||
|
||||
function _assertName(err, name) {
|
||||
assert.isString(name);
|
||||
assert.isNotZero(name.length, 'an empty string is not a valid name');
|
||||
}
|
||||
|
||||
function _assertNameSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
var name = typeof(result) == 'string' ? result : result.name;
|
||||
_assertName(null, name);
|
||||
}
|
||||
|
||||
function _testName(expected){
|
||||
return function _testNameGenerated(err, name) {
|
||||
assert.equal(expected, name, 'should have the provided name');
|
||||
};
|
||||
}
|
||||
|
||||
function _testNameSync(expected){
|
||||
return function _testNameGeneratedSync(result) {
|
||||
if (result instanceof Error) {
|
||||
throw result;
|
||||
}
|
||||
_testName(expected)(null, result.name, result.fd);
|
||||
};
|
||||
}
|
||||
|
||||
function _testUnsafeCleanup(unsafe, cb) {
|
||||
_spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
|
||||
}
|
||||
|
||||
function _testIssue62(cb) {
|
||||
_spawnTestWithoutError('issue62.js', [], cb);
|
||||
}
|
||||
|
||||
function _testUnsafeCleanupSync(unsafe, cb) {
|
||||
_spawnTestWithoutError('unsafe-sync.js', [ 'dir', unsafe ], cb);
|
||||
}
|
||||
|
||||
function _testIssue62Sync(cb) {
|
||||
_spawnTestWithoutError('issue62-sync.js', [], cb);
|
||||
}
|
||||
|
||||
module.exports.testStat = _testStat;
|
||||
module.exports.testPrefix = _testPrefix;
|
||||
module.exports.testPrefixSync = _testPrefixSync;
|
||||
module.exports.testPostfix = _testPostfix;
|
||||
module.exports.testPostfixSync = _testPostfixSync;
|
||||
module.exports.testKeep = _testKeep;
|
||||
module.exports.testKeepSync = _testKeepSync;
|
||||
module.exports.testGraceful = _testGraceful;
|
||||
module.exports.testGracefulSync = _testGracefulSync;
|
||||
module.exports.assertName = _assertName;
|
||||
module.exports.assertNameSync = _assertNameSync;
|
||||
module.exports.testName = _testName;
|
||||
module.exports.testNameSync = _testNameSync;
|
||||
module.exports.testUnsafeCleanup = _testUnsafeCleanup;
|
||||
module.exports.testIssue62 = _testIssue62;
|
||||
module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
|
||||
module.exports.testIssue62Sync = _testIssue62Sync;
|
230
node_modules/tmp/test/dir-sync-test.js
generated
vendored
Normal file
230
node_modules/tmp/test/dir-sync-test.js
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testDir(mode) {
|
||||
return function _testDirGenerated(result) {
|
||||
assert.ok(existsSync(result.name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(result.name);
|
||||
assert.ok(stat.isDirectory(), 'should be a directory');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Synchronous directory creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
return tmp.dirSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the default prefix': Test.testPrefixSync('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'something' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefixSync('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ postfix: '.txt' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided postfix': Test.testPostfixSync('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefixSync('clike-'),
|
||||
'should have the provided postfix': Test.testPostfixSync('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ name: 'using-name' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')),
|
||||
'should be a directory': function (result) {
|
||||
_testDir(040700)(result);
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'foo', postfix: 'bar', mode: 0750 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040750),
|
||||
'should have the provided prefix': Test.testPrefixSync('foo'),
|
||||
'should have the provided postfix': Test.testPostfixSync('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
return tmp.dirSync({ prefix: 'complicated', postfix: 'options', mode: 0755 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a directory': _testDir(040755),
|
||||
'should have the provided prefix': Test.testPrefixSync('complicated'),
|
||||
'should have the provided postfix': Test.testPostfixSync('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
try {
|
||||
return tmp.dirSync({ tries: -1 });
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
},
|
||||
|
||||
'should return with an error': function (topic) {
|
||||
assert.instanceOf(topic, Error);
|
||||
}
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)({ name: name });
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'non graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)({ name: name });
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanupSync('1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
},
|
||||
'should remove symlinked dir': function(err, name) {
|
||||
assert.ok(
|
||||
!existsSync(name + '/symlinkme-target'),
|
||||
'should remove target'
|
||||
);
|
||||
},
|
||||
'should not remove contents of symlink dir': function(err, name) {
|
||||
assert.ok(
|
||||
existsSync(__dirname + '/symlinkme/file.js'),
|
||||
'should not remove symlinked directory\'s content'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true with issue62 structure': {
|
||||
topic: function () {
|
||||
Test.testIssue62Sync(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === false': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanupSync('0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': function (err, name) {
|
||||
_testDir(040700)({name:name});
|
||||
// make sure that everything gets cleaned up
|
||||
fs.unlinkSync(path.join(name, 'should-be-removed.file'));
|
||||
fs.unlinkSync(path.join(name, 'symlinkme-target'));
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
return tmp.dirSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'removeCallback should remove directory': function (result) {
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'Directory should be removed');
|
||||
}
|
||||
}
|
||||
}).exportTo(module);
|
225
node_modules/tmp/test/dir-test.js
generated
vendored
Normal file
225
node_modules/tmp/test/dir-test.js
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testDir(mode) {
|
||||
return function _testDirGenerated(err, name) {
|
||||
assert.ok(existsSync(name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(name);
|
||||
assert.ok(stat.isDirectory(), 'should be a directory');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Directory creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.dir(this.callback);
|
||||
},
|
||||
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the default prefix': Test.testPrefix('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.dir({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided postfix': Test.testPostfix('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.dir({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
tmp.dir({ name: 'using-name' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040700),
|
||||
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name'))
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'foo', postfix: 'bar', mode: 0750 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040750),
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
tmp.dir({ prefix: 'complicated', postfix: 'options', mode: 0755 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': _testDir(040755),
|
||||
'should have the provided prefix': Test.testPrefix('complicated'),
|
||||
'should have the provided postfix': Test.testPostfix('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.dir({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should return with an error': assert.isObject
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)(err, name);
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'non graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGraceful('dir', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a dir': function (err, name) {
|
||||
_testDir(040700)(err, name);
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGraceful('dir', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanup('1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
},
|
||||
'should remove symlinked dir': function(err, name) {
|
||||
assert.ok(
|
||||
!existsSync(name + '/symlinkme-target'),
|
||||
'should remove target'
|
||||
);
|
||||
},
|
||||
'should not remove contents of symlink dir': function(err, name) {
|
||||
assert.ok(
|
||||
existsSync(__dirname + '/symlinkme/file.js'),
|
||||
'should not remove symlinked directory\'s content'
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === true with issue62 structure': {
|
||||
topic: function () {
|
||||
Test.testIssue62(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'unsafeCleanup === false': {
|
||||
topic: function () {
|
||||
Test.testUnsafeCleanup('0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a directory': function (err, name) {
|
||||
_testDir(040700)(err, name);
|
||||
// make sure that everything gets cleaned up
|
||||
fs.unlinkSync(path.join(name, 'should-be-removed.file'));
|
||||
fs.unlinkSync(path.join(name, 'symlinkme-target'));
|
||||
fs.rmdirSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
tmp.dir(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'removeCallback should remove directory': function (_err, name, removeCallback) {
|
||||
removeCallback();
|
||||
assert.ok(!existsSync(name), 'Directory should be removed');
|
||||
}
|
||||
}
|
||||
}).exportTo(module);
|
190
node_modules/tmp/test/file-sync-test.js
generated
vendored
Normal file
190
node_modules/tmp/test/file-sync-test.js
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testFile(mode, fdTest) {
|
||||
return function _testFileGenerated(result) {
|
||||
assert.ok(existsSync(result.name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(result.name);
|
||||
assert.equal(stat.size, 0, 'should have zero size');
|
||||
assert.ok(stat.isFile(), 'should be a file');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
|
||||
// check with fstat as well (fd checking)
|
||||
if (fdTest) {
|
||||
var fstat = fs.fstatSync(result.fd);
|
||||
assert.deepEqual(fstat, stat, 'fstat results should be the same');
|
||||
|
||||
var data = new Buffer('something');
|
||||
assert.equal(fs.writeSync(result.fd, data, 0, data.length, 0), data.length, 'should be writable');
|
||||
assert.ok(!fs.closeSync(result.fd), 'should not return with error');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('Synchronous file creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
return tmp.fileSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the default prefix': Test.testPrefixSync('tmp-'),
|
||||
'should have the default postfix': Test.testPostfixSync('.tmp')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'something' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ postfix: '.txt' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided postfix': Test.testPostfixSync('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('clike-'),
|
||||
'should have the provided postfix': Test.testPostfixSync('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ name: 'using-name.tmp' });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name.tmp')),
|
||||
'should be a file': function (result) {
|
||||
_testFile(0100600, true);
|
||||
fs.unlinkSync(result.name);
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'foo', postfix: 'bar', mode: 0640 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100640, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('foo'),
|
||||
'should have the provided postfix': Test.testPostfixSync('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
return tmp.fileSync({ prefix: 'complicated', postfix: 'options', mode: 0644 });
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'should be a file': _testFile(0100644, true),
|
||||
'should have the provided prefix': Test.testPrefixSync('complicated'),
|
||||
'should have the provided postfix': Test.testPostfixSync('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
try {
|
||||
return tmp.fileSync({ tries: -1 });
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
},
|
||||
|
||||
'should return with an error': function (topic) {
|
||||
assert.instanceOf(topic, Error);
|
||||
}
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, false)({name:name});
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeepSync('file', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'non graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('file', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, false)({name:name});
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGracefulSync('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
return tmp.fileSync();
|
||||
},
|
||||
|
||||
'should return with a name': Test.assertNameSync,
|
||||
'removeCallback should remove file': function (result) {
|
||||
result.removeCallback();
|
||||
assert.ok(!existsSync(result.name), 'File should be removed');
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
191
node_modules/tmp/test/file-test.js
generated
vendored
Normal file
191
node_modules/tmp/test/file-test.js
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
existsSync = fs.existsSync || path.existsSync,
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
|
||||
function _testFile(mode, fdTest) {
|
||||
return function _testFileGenerated(err, name, fd) {
|
||||
assert.ok(existsSync(name), 'should exist');
|
||||
|
||||
var stat = fs.statSync(name);
|
||||
assert.equal(stat.size, 0, 'should have zero size');
|
||||
assert.ok(stat.isFile(), 'should be a file');
|
||||
|
||||
Test.testStat(stat, mode);
|
||||
|
||||
// check with fstat as well (fd checking)
|
||||
if (fdTest) {
|
||||
var fstat = fs.fstatSync(fd);
|
||||
assert.deepEqual(fstat, stat, 'fstat results should be the same');
|
||||
|
||||
var data = new Buffer('something');
|
||||
assert.equal(fs.writeSync(fd, data, 0, data.length, 0), data.length, 'should be writable');
|
||||
assert.ok(!fs.closeSync(fd), 'should not return with error');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
vows.describe('File creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.file(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the default prefix': Test.testPrefix('tmp-'),
|
||||
'should have the default postfix': Test.testPostfix('.tmp')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.file({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided postfix': Test.testPostfix('.txt')
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.file({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100600, true),
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix')
|
||||
},
|
||||
|
||||
'when using name': {
|
||||
topic: function () {
|
||||
tmp.file({ name: 'using-name.tmp' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name.tmp')),
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, true);
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'foo', postfix: 'bar', mode: 0640 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100640, true),
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'when using multiple options and mode': {
|
||||
topic: function () {
|
||||
tmp.file({ prefix: 'complicated', postfix: 'options', mode: 0644 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': _testFile(0100644, true),
|
||||
'should have the provided prefix': Test.testPrefix('complicated'),
|
||||
'should have the provided postfix': Test.testPostfix('options')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.file({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should not be created': assert.isObject
|
||||
},
|
||||
|
||||
'keep testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, false)(err, name, null);
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'unlink testing': {
|
||||
topic: function () {
|
||||
Test.testKeep('file', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'non graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGraceful('file', '0', this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should be a file': function (err, name) {
|
||||
_testFile(0100600, false)(err, name, null);
|
||||
fs.unlinkSync(name);
|
||||
}
|
||||
},
|
||||
|
||||
'graceful testing': {
|
||||
topic: function () {
|
||||
Test.testGraceful('file', '1', this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'should not exist': function (err, name) {
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
},
|
||||
|
||||
'remove callback': {
|
||||
topic: function () {
|
||||
tmp.file(this.callback);
|
||||
},
|
||||
|
||||
'should not return with an error': assert.isNull,
|
||||
'should return with a name': Test.assertName,
|
||||
'removeCallback should remove file': function (_err, name, _fd, removeCallback) {
|
||||
removeCallback();
|
||||
assert.ok(!existsSync(name), 'File should be removed');
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
20
node_modules/tmp/test/graceful-sync.js
generated
vendored
Normal file
20
node_modules/tmp/test/graceful-sync.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var
|
||||
tmp = require('../lib/tmp'),
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
var graceful = spawn.arg;
|
||||
|
||||
if (graceful) {
|
||||
tmp.setGracefulCleanup();
|
||||
}
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction();
|
||||
spawn.out(result.name, function () {
|
||||
throw new Error('Thrown on purpose');
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(e, spawn.exit);
|
||||
}
|
||||
|
15
node_modules/tmp/test/graceful.js
generated
vendored
Normal file
15
node_modules/tmp/test/graceful.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var
|
||||
tmp = require('../lib/tmp'),
|
||||
spawn = require('./spawn');
|
||||
|
||||
var graceful = spawn.arg;
|
||||
|
||||
if (graceful) {
|
||||
tmp.setGracefulCleanup();
|
||||
}
|
||||
|
||||
spawn.tmpFunction(function (err, name) {
|
||||
spawn.out(name, function () {
|
||||
throw new Error('Thrown on purpose');
|
||||
});
|
||||
});
|
27
node_modules/tmp/test/issue62-sync.js
generated
vendored
Normal file
27
node_modules/tmp/test/issue62-sync.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ unsafeCleanup: true });
|
||||
try {
|
||||
// creates structure from issue 62
|
||||
// https://github.com/raszi/node-tmp/issues/62
|
||||
|
||||
fs.mkdirSync(join(result.name, 'issue62'));
|
||||
|
||||
['foo', 'bar'].forEach(function(subdir) {
|
||||
fs.mkdirSync(join(result.name, 'issue62', subdir));
|
||||
fs.writeFileSync(join(result.name, 'issue62', subdir, 'baz.txt'), '');
|
||||
});
|
||||
|
||||
spawn.out(result.name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(e, spawn.exit);
|
||||
}
|
27
node_modules/tmp/test/issue62.js
generated
vendored
Normal file
27
node_modules/tmp/test/issue62.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn');
|
||||
|
||||
spawn.tmpFunction({ unsafeCleanup: true }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// creates structure from issue 62
|
||||
// https://github.com/raszi/node-tmp/issues/62
|
||||
|
||||
fs.mkdirSync(join(name, 'issue62'));
|
||||
|
||||
['foo', 'bar'].forEach(function(subdir) {
|
||||
fs.mkdirSync(join(name, 'issue62', subdir));
|
||||
fs.writeFileSync(join(name, 'issue62', subdir, 'baz.txt'), '');
|
||||
});
|
||||
|
||||
spawn.out(name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
});
|
12
node_modules/tmp/test/keep-sync.js
generated
vendored
Normal file
12
node_modules/tmp/test/keep-sync.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var spawn = require('./spawn-sync');
|
||||
|
||||
var keep = spawn.arg;
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ keep: keep });
|
||||
spawn.out(result.name, spawn.exit);
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(err, spawn.exit);
|
||||
}
|
||||
|
11
node_modules/tmp/test/keep.js
generated
vendored
Normal file
11
node_modules/tmp/test/keep.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var spawn = require('./spawn');
|
||||
|
||||
var keep = spawn.arg;
|
||||
|
||||
spawn.tmpFunction({ keep: keep }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
} else {
|
||||
spawn.out(name, spawn.exit);
|
||||
}
|
||||
});
|
82
node_modules/tmp/test/name-test.js
generated
vendored
Normal file
82
node_modules/tmp/test/name-test.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
|
||||
path = require('path'),
|
||||
|
||||
tmp = require('../lib/tmp.js'),
|
||||
Test = require('./base.js');
|
||||
|
||||
vows.describe('Name creation').addBatch({
|
||||
'when using without parameters': {
|
||||
topic: function () {
|
||||
tmp.tmpName(this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the default prefix': Test.testPrefix('tmp-')
|
||||
},
|
||||
|
||||
'when using with prefix': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ prefix: 'something' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('something')
|
||||
},
|
||||
|
||||
'when using with postfix': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ postfix: '.txt' }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided postfix': Test.testPostfix('.txt')
|
||||
|
||||
},
|
||||
|
||||
'when using template': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('clike-'),
|
||||
'should have the provided postfix': Test.testPostfix('-postfix'),
|
||||
'should have template filled': function (err, name) {
|
||||
assert.isTrue(/[a-zA-Z0-9]{6}/.test(name));
|
||||
}
|
||||
},
|
||||
|
||||
'when using multiple options': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ prefix: 'foo', postfix: 'bar', tries: 5 }, this.callback);
|
||||
},
|
||||
|
||||
'should not return with error': assert.isNull,
|
||||
'should have the provided prefix': Test.testPrefix('foo'),
|
||||
'should have the provided postfix': Test.testPostfix('bar')
|
||||
},
|
||||
|
||||
'no tries': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ tries: -1 }, this.callback);
|
||||
},
|
||||
|
||||
'should fail': function (err, name) {
|
||||
assert.isObject(err);
|
||||
}
|
||||
},
|
||||
|
||||
'tries not numeric': {
|
||||
topic: function () {
|
||||
tmp.tmpName({ tries: 'hello'}, this.callback);
|
||||
},
|
||||
|
||||
'should fail': function (err, name) {
|
||||
assert.isObject(err);
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
32
node_modules/tmp/test/spawn-sync.js
generated
vendored
Normal file
32
node_modules/tmp/test/spawn-sync.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
function _writeSync(stream, str, cb) {
|
||||
var flushed = stream.write(str);
|
||||
if (flushed) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
stream.once('drain', function _flushed() {
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.out = function (str, cb) {
|
||||
_writeSync(process.stdout, str, cb);
|
||||
};
|
||||
|
||||
module.exports.err = function (str, cb) {
|
||||
_writeSync(process.stderr, str, cb);
|
||||
};
|
||||
|
||||
module.exports.exit = function () {
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
var type = process.argv[2];
|
||||
module.exports.tmpFunction = (type == 'file') ? tmp.fileSync : tmp.dirSync;
|
||||
|
||||
var arg = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
|
||||
module.exports.arg = arg;
|
32
node_modules/tmp/test/spawn.js
generated
vendored
Normal file
32
node_modules/tmp/test/spawn.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
tmp = require('../lib/tmp');
|
||||
|
||||
function _writeSync(stream, str, cb) {
|
||||
var flushed = stream.write(str);
|
||||
if (flushed) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
stream.once('drain', function _flushed() {
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.out = function (str, cb) {
|
||||
_writeSync(process.stdout, str, cb);
|
||||
};
|
||||
|
||||
module.exports.err = function (str, cb) {
|
||||
_writeSync(process.stderr, str, cb);
|
||||
};
|
||||
|
||||
module.exports.exit = function () {
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
var type = process.argv[2];
|
||||
module.exports.tmpFunction = (type == 'file') ? tmp.file : tmp.dir;
|
||||
|
||||
var arg = (process.argv[3] && parseInt(process.argv[3], 10) === 1) ? true : false;
|
||||
module.exports.arg = arg;
|
0
node_modules/tmp/test/symlinkme/file.js
generated
vendored
Normal file
0
node_modules/tmp/test/symlinkme/file.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe-sync.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe-sync.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn-sync');
|
||||
|
||||
var unsafe = spawn.arg;
|
||||
|
||||
try {
|
||||
var result = spawn.tmpFunction({ unsafeCleanup: unsafe });
|
||||
try {
|
||||
// file that should be removed
|
||||
var fd = fs.openSync(join(result.name, 'should-be-removed.file'), 'w');
|
||||
fs.closeSync(fd);
|
||||
|
||||
// in tree source
|
||||
var symlinkSource = join(__dirname, 'symlinkme');
|
||||
// testing target
|
||||
var symlinkTarget = join(result.name, 'symlinkme-target');
|
||||
|
||||
// symlink that should be removed but the contents should be preserved.
|
||||
fs.symlinkSync(symlinkSource, symlinkTarget, 'dir');
|
||||
|
||||
spawn.out(result.name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
spawn.err(err, spawn.exit);
|
||||
}
|
30
node_modules/tmp/test/unsafe.js
generated
vendored
Normal file
30
node_modules/tmp/test/unsafe.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
spawn = require('./spawn');
|
||||
|
||||
var unsafe = spawn.arg;
|
||||
spawn.tmpFunction({ unsafeCleanup: unsafe }, function (err, name) {
|
||||
if (err) {
|
||||
spawn.err(err, spawn.exit);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// file that should be removed
|
||||
var fd = fs.openSync(join(name, 'should-be-removed.file'), 'w');
|
||||
fs.closeSync(fd);
|
||||
|
||||
// in tree source
|
||||
var symlinkSource = join(__dirname, 'symlinkme');
|
||||
// testing target
|
||||
var symlinkTarget = join(name, 'symlinkme-target');
|
||||
|
||||
// symlink that should be removed but the contents should be preserved.
|
||||
fs.symlinkSync(symlinkSource, symlinkTarget, 'dir');
|
||||
|
||||
spawn.out(name, spawn.exit);
|
||||
} catch (e) {
|
||||
spawn.err(e.toString(), spawn.exit);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user