2 assert = require('assert'),
3 path = require('path'),
4 exec = require('child_process').exec,
5 tmp = require('../lib/tmp');
7 // make sure that we do not test spam the global tmp
11 function _spawnTestWithError(testFile, params, cb) {
12 _spawnTest(true, testFile, params, cb);
15 function _spawnTestWithoutError(testFile, params, cb) {
16 _spawnTest(false, testFile, params, cb);
19 function _spawnTest(passError, testFile, params, cb) {
21 node_path = process.argv[0],
22 command = [ node_path, path.join(__dirname, testFile) ].concat(params).join(' ');
24 exec(command, function _execDone(err, stdout, stderr) {
28 } else if (stderr.length > 0) {
29 return cb(stderr.toString());
33 return cb(null, stdout.toString());
37 function _testStat(stat, mode) {
38 assert.equal(stat.uid, process.getuid(), 'should have the same UID');
39 assert.equal(stat.gid, process.getgid(), 'should have the same GUID');
40 assert.equal(stat.mode, mode);
43 function _testPrefix(prefix) {
44 return function _testPrefixGenerated(err, name) {
45 assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
49 function _testPrefixSync(prefix) {
50 return function _testPrefixGeneratedSync(result) {
51 if (result instanceof Error) {
54 _testPrefix(prefix)(null, result.name, result.fd);
58 function _testPostfix(postfix) {
59 return function _testPostfixGenerated(err, name) {
60 assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
64 function _testPostfixSync(postfix) {
65 return function _testPostfixGeneratedSync(result) {
66 if (result instanceof Error) {
69 _testPostfix(postfix)(null, result.name, result.fd);
73 function _testKeep(type, keep, cb) {
74 _spawnTestWithError('keep.js', [ type, keep ], cb);
77 function _testKeepSync(type, keep, cb) {
78 _spawnTestWithError('keep-sync.js', [ type, keep ], cb);
81 function _testGraceful(type, graceful, cb) {
82 _spawnTestWithoutError('graceful.js', [ type, graceful ], cb);
85 function _testGracefulSync(type, graceful, cb) {
86 _spawnTestWithoutError('graceful-sync.js', [ type, graceful ], cb);
89 function _assertName(err, name) {
90 assert.isString(name);
91 assert.isNotZero(name.length, 'an empty string is not a valid name');
94 function _assertNameSync(result) {
95 if (result instanceof Error) {
98 var name = typeof(result) == 'string' ? result : result.name;
99 _assertName(null, name);
102 function _testName(expected){
103 return function _testNameGenerated(err, name) {
104 assert.equal(expected, name, 'should have the provided name');
108 function _testNameSync(expected){
109 return function _testNameGeneratedSync(result) {
110 if (result instanceof Error) {
113 _testName(expected)(null, result.name, result.fd);
117 function _testUnsafeCleanup(unsafe, cb) {
118 _spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
121 function _testIssue62(cb) {
122 _spawnTestWithoutError('issue62.js', [], cb);
125 function _testUnsafeCleanupSync(unsafe, cb) {
126 _spawnTestWithoutError('unsafe-sync.js', [ 'dir', unsafe ], cb);
129 function _testIssue62Sync(cb) {
130 _spawnTestWithoutError('issue62-sync.js', [], cb);
133 module.exports.testStat = _testStat;
134 module.exports.testPrefix = _testPrefix;
135 module.exports.testPrefixSync = _testPrefixSync;
136 module.exports.testPostfix = _testPostfix;
137 module.exports.testPostfixSync = _testPostfixSync;
138 module.exports.testKeep = _testKeep;
139 module.exports.testKeepSync = _testKeepSync;
140 module.exports.testGraceful = _testGraceful;
141 module.exports.testGracefulSync = _testGracefulSync;
142 module.exports.assertName = _assertName;
143 module.exports.assertNameSync = _assertNameSync;
144 module.exports.testName = _testName;
145 module.exports.testNameSync = _testNameSync;
146 module.exports.testUnsafeCleanup = _testUnsafeCleanup;
147 module.exports.testIssue62 = _testIssue62;
148 module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
149 module.exports.testIssue62Sync = _testIssue62Sync;