Skip to content

Commit f8db66b

Browse files
authored
Merge pull request #135 from raszi/gh-133
fix #133, #134
2 parents 0499864 + bb31918 commit f8db66b

6 files changed

Lines changed: 81 additions & 36 deletions

File tree

lib/tmp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ function isEBADF(error) {
477477
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
478478
*/
479479
function isENOENT(error) {
480-
return isExpectedError(error, -EBADF, 'EBADF');
480+
return isExpectedError(error, -ENOENT, 'ENOENT');
481481
}
482482

483483
/**

test/base.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
var
22
assert = require('assert'),
3+
fs = require('fs'),
34
path = require('path'),
45
spawn = require('child_process').spawn,
6+
existsSync = fs.existsSync || path.existsSync,
57
tmp = require('../lib/tmp');
68

9+
var _cleanup_fn = undefined;
10+
11+
// FIXME:does not seem to work at all
712
// make sure that we do not test spam the global tmp
813
tmp.TMP_DIR = './tmp';
914

@@ -200,6 +205,18 @@ function _testIssue115FileSync(cb) {
200205
_spawnTestWithError('issue115-file-sync.js', [], cb);
201206
}
202207

208+
function _testCleanup(err, name, fd, fn) {
209+
var actual_fn = fn;
210+
if (typeof(fd) == 'function') actual_fn = fd;
211+
if (actual_fn) actual_fn();
212+
assert.ok(!existsSync(name), 'should not exist');
213+
}
214+
215+
function _testCleanupSync(result) {
216+
result.removeCallback();
217+
assert.ok(!existsSync(result.name), 'should not exist');
218+
}
219+
203220
module.exports.testStat = _testStat;
204221
module.exports.testPrefix = _testPrefix;
205222
module.exports.testPrefixSync = _testPrefixSync;
@@ -220,3 +237,5 @@ module.exports.testIssue115File = _testIssue115File;
220237
module.exports.testIssue115FileSync = _testIssue115FileSync;
221238
module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
222239
module.exports.testIssue62Sync = _testIssue62Sync;
240+
module.exports.testCleanup = _testCleanup;
241+
module.exports.testCleanupSync = _testCleanupSync;

test/dir-sync-test.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ vows.describe('Synchronous directory creation').addBatch({
3131

3232
'should return with a name': Test.assertNameSync,
3333
'should be a directory': _testDir(040700),
34-
'should have the default prefix': Test.testPrefixSync('tmp-')
34+
'should have the default prefix': Test.testPrefixSync('tmp-'),
35+
'should have been cleaned up': Test.testCleanupSync
3536
},
3637

3738
'when using with prefix': {
@@ -41,7 +42,8 @@ vows.describe('Synchronous directory creation').addBatch({
4142

4243
'should return with a name': Test.assertNameSync,
4344
'should be a directory': _testDir(040700),
44-
'should have the provided prefix': Test.testPrefixSync('something')
45+
'should have the provided prefix': Test.testPrefixSync('something'),
46+
'should have been cleaned up': Test.testCleanupSync
4547
},
4648

4749
'when using with postfix': {
@@ -51,7 +53,8 @@ vows.describe('Synchronous directory creation').addBatch({
5153

5254
'should return with a name': Test.assertNameSync,
5355
'should be a directory': _testDir(040700),
54-
'should have the provided postfix': Test.testPostfixSync('.txt')
56+
'should have the provided postfix': Test.testPostfixSync('.txt'),
57+
'should have been cleaned up': Test.testCleanupSync
5558
},
5659

5760
'when using template': {
@@ -62,7 +65,8 @@ vows.describe('Synchronous directory creation').addBatch({
6265
'should return with a name': Test.assertNameSync,
6366
'should be a directory': _testDir(040700),
6467
'should have the provided prefix': Test.testPrefixSync('clike-'),
65-
'should have the provided postfix': Test.testPostfixSync('-postfix')
68+
'should have the provided postfix': Test.testPostfixSync('-postfix'),
69+
'should have been cleaned up': Test.testCleanupSync
6670
},
6771

6872
'when using name': {
@@ -74,9 +78,8 @@ vows.describe('Synchronous directory creation').addBatch({
7478
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')),
7579
'should be a directory': function (result) {
7680
_testDir(040700)(result);
77-
result.removeCallback();
78-
assert.ok(!existsSync(result.name), 'Directory should be removed');
79-
}
81+
},
82+
'should have been cleaned up': Test.testCleanupSync
8083
},
8184

8285
'when using multiple options': {
@@ -87,7 +90,8 @@ vows.describe('Synchronous directory creation').addBatch({
8790
'should return with a name': Test.assertNameSync,
8891
'should be a directory': _testDir(040750),
8992
'should have the provided prefix': Test.testPrefixSync('foo'),
90-
'should have the provided postfix': Test.testPostfixSync('bar')
93+
'should have the provided postfix': Test.testPostfixSync('bar'),
94+
'should have been cleaned up': Test.testCleanupSync
9195
},
9296

9397
'when using multiple options and mode': {
@@ -98,7 +102,8 @@ vows.describe('Synchronous directory creation').addBatch({
98102
'should return with a name': Test.assertNameSync,
99103
'should be a directory': _testDir(040755),
100104
'should have the provided prefix': Test.testPrefixSync('complicated'),
101-
'should have the provided postfix': Test.testPostfixSync('options')
105+
'should have the provided postfix': Test.testPostfixSync('options'),
106+
'should have been cleaned up': Test.testCleanupSync
102107
},
103108

104109
'no tries': {

test/dir-test.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var
1111
tmp = require('../lib/tmp.js'),
1212
Test = require('./base.js');
1313

14-
1514
function _testDir(mode) {
1615
return function _testDirGenerated(err, name) {
1716
assert.ok(existsSync(name), 'should exist');
@@ -23,14 +22,16 @@ function _testDir(mode) {
2322
};
2423
}
2524

25+
2626
vows.describe('Directory creation').addBatch({
2727
'when using without parameters': {
2828
topic: function () {
2929
tmp.dir(this.callback);
3030
},
3131

3232
'should be a directory': _testDir(040700),
33-
'should have the default prefix': Test.testPrefix('tmp-')
33+
'should have the default prefix': Test.testPrefix('tmp-'),
34+
'should have been cleaned up': Test.testCleanup
3435
},
3536

3637
'when using with prefix': {
@@ -41,7 +42,8 @@ vows.describe('Directory creation').addBatch({
4142
'should not return with an error': assert.isNull,
4243
'should return with a name': Test.assertName,
4344
'should be a directory': _testDir(040700),
44-
'should have the provided prefix': Test.testPrefix('something')
45+
'should have the provided prefix': Test.testPrefix('something'),
46+
'should have been cleaned up': Test.testCleanup
4547
},
4648

4749
'when using with postfix': {
@@ -52,7 +54,8 @@ vows.describe('Directory creation').addBatch({
5254
'should not return with an error': assert.isNull,
5355
'should return with a name': Test.assertName,
5456
'should be a directory': _testDir(040700),
55-
'should have the provided postfix': Test.testPostfix('.txt')
57+
'should have the provided postfix': Test.testPostfix('.txt'),
58+
'should have been cleaned up': Test.testCleanup
5659
},
5760

5861
'when using template': {
@@ -64,7 +67,8 @@ vows.describe('Directory creation').addBatch({
6467
'should return with a name': Test.assertName,
6568
'should be a directory': _testDir(040700),
6669
'should have the provided prefix': Test.testPrefix('clike-'),
67-
'should have the provided postfix': Test.testPostfix('-postfix')
70+
'should have the provided postfix': Test.testPostfix('-postfix'),
71+
'should have been cleaned up': Test.testCleanup
6872
},
6973

7074
'when using name': {
@@ -75,7 +79,8 @@ vows.describe('Directory creation').addBatch({
7579
'should not return with an error': assert.isNull,
7680
'should return with a name': Test.assertName,
7781
'should be a directory': _testDir(040700),
78-
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name'))
82+
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name')),
83+
'should have been cleaned up': Test.testCleanup
7984
},
8085

8186
'when using multiple options': {
@@ -87,7 +92,8 @@ vows.describe('Directory creation').addBatch({
8792
'should return with a name': Test.assertName,
8893
'should be a directory': _testDir(040750),
8994
'should have the provided prefix': Test.testPrefix('foo'),
90-
'should have the provided postfix': Test.testPostfix('bar')
95+
'should have the provided postfix': Test.testPostfix('bar'),
96+
'should have been cleaned up': Test.testCleanup
9197
},
9298

9399
'when using multiple options and mode': {
@@ -99,7 +105,8 @@ vows.describe('Directory creation').addBatch({
99105
'should return with a name': Test.assertName,
100106
'should be a directory': _testDir(040755),
101107
'should have the provided prefix': Test.testPrefix('complicated'),
102-
'should have the provided postfix': Test.testPostfix('options')
108+
'should have the provided postfix': Test.testPostfix('options'),
109+
'should have been cleaned up': Test.testCleanup
103110
},
104111

105112
'no tries': {

test/file-sync-test.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ vows.describe('Synchronous file creation').addBatch({
4343
'should return with a name': Test.assertNameSync,
4444
'should be a file': _testFile(0100600, true),
4545
'should have the default prefix': Test.testPrefixSync('tmp-'),
46-
'should have the default postfix': Test.testPostfixSync('.tmp')
46+
'should have the default postfix': Test.testPostfixSync('.tmp'),
47+
'should have been cleaned up': Test.testCleanupSync
4748
},
4849

4950
'when using with prefix': {
@@ -53,7 +54,8 @@ vows.describe('Synchronous file creation').addBatch({
5354

5455
'should return with a name': Test.assertNameSync,
5556
'should be a file': _testFile(0100600, true),
56-
'should have the provided prefix': Test.testPrefixSync('something')
57+
'should have the provided prefix': Test.testPrefixSync('something'),
58+
'should have been cleaned up': Test.testCleanupSync
5759
},
5860

5961
'when using with postfix': {
@@ -63,7 +65,8 @@ vows.describe('Synchronous file creation').addBatch({
6365

6466
'should return with a name': Test.assertNameSync,
6567
'should be a file': _testFile(0100600, true),
66-
'should have the provided postfix': Test.testPostfixSync('.txt')
68+
'should have the provided postfix': Test.testPostfixSync('.txt'),
69+
'should have been cleaned up': Test.testCleanupSync
6770
},
6871

6972
'when using template': {
@@ -74,20 +77,21 @@ vows.describe('Synchronous file creation').addBatch({
7477
'should return with a name': Test.assertNameSync,
7578
'should be a file': _testFile(0100600, true),
7679
'should have the provided prefix': Test.testPrefixSync('clike-'),
77-
'should have the provided postfix': Test.testPostfixSync('-postfix')
80+
'should have the provided postfix': Test.testPostfixSync('-postfix'),
81+
'should have been cleaned up': Test.testCleanupSync
7882
},
7983

8084
'when using name': {
8185
topic: function () {
82-
return tmp.fileSync({ name: 'using-name-sync.tmp' });
86+
return tmp.fileSync({ name: 'using-name' });
8387
},
8488

8589
'should return with a name': Test.assertNameSync,
86-
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name-sync.tmp')),
90+
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')),
8791
'should be a file': function (result) {
8892
_testFile(0100600, true);
89-
fs.unlinkSync(result.name);
90-
}
93+
},
94+
'should have been cleaned up': Test.testCleanupSync
9195
},
9296

9397
'when using multiple options': {
@@ -98,7 +102,8 @@ vows.describe('Synchronous file creation').addBatch({
98102
'should return with a name': Test.assertNameSync,
99103
'should be a file': _testFile(0100640, true),
100104
'should have the provided prefix': Test.testPrefixSync('foo'),
101-
'should have the provided postfix': Test.testPostfixSync('bar')
105+
'should have the provided postfix': Test.testPostfixSync('bar'),
106+
'should have been cleaned up': Test.testCleanupSync
102107
},
103108

104109
'when using multiple options and mode': {
@@ -109,7 +114,8 @@ vows.describe('Synchronous file creation').addBatch({
109114
'should return with a name': Test.assertNameSync,
110115
'should be a file': _testFile(0100644, true),
111116
'should have the provided prefix': Test.testPrefixSync('complicated'),
112-
'should have the provided postfix': Test.testPostfixSync('options')
117+
'should have the provided postfix': Test.testPostfixSync('options'),
118+
'should have been cleaned up': Test.testCleanupSync
113119
},
114120

115121
'no tries': {

test/file-test.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ vows.describe('File creation').addBatch({
7373
'should return with a name': Test.assertName,
7474
'should be a file': _testFile(0100600, true),
7575
'should have the default prefix': Test.testPrefix('tmp-'),
76-
'should have the default postfix': Test.testPostfix('.tmp')
76+
'should have the default postfix': Test.testPostfix('.tmp'),
77+
'should have been cleaned up': Test.testCleanup
7778
},
7879

7980
'when using with prefix': {
@@ -84,7 +85,8 @@ vows.describe('File creation').addBatch({
8485
'should not return with an error': assert.isNull,
8586
'should return with a name': Test.assertName,
8687
'should be a file': _testFile(0100600, true),
87-
'should have the provided prefix': Test.testPrefix('something')
88+
'should have the provided prefix': Test.testPrefix('something'),
89+
'should have been cleaned up': Test.testCleanup
8890
},
8991

9092
'when using with postfix': {
@@ -95,7 +97,8 @@ vows.describe('File creation').addBatch({
9597
'should not return with an error': assert.isNull,
9698
'should return with a name': Test.assertName,
9799
'should be a file': _testFile(0100600, true),
98-
'should have the provided postfix': Test.testPostfix('.txt')
100+
'should have the provided postfix': Test.testPostfix('.txt'),
101+
'should have been cleaned up': Test.testCleanup
99102
},
100103

101104
'when using template': {
@@ -107,7 +110,8 @@ vows.describe('File creation').addBatch({
107110
'should return with a name': Test.assertName,
108111
'should be a file': _testFile(0100600, true),
109112
'should have the provided prefix': Test.testPrefix('clike-'),
110-
'should have the provided postfix': Test.testPostfix('-postfix')
113+
'should have the provided postfix': Test.testPostfix('-postfix'),
114+
'should have been cleaned up': Test.testCleanup
111115
},
112116

113117
'when using name': {
@@ -121,7 +125,8 @@ vows.describe('File creation').addBatch({
121125
'should be a file': function (err, name) {
122126
_testFile(0100600, true);
123127
fs.unlinkSync(name);
124-
}
128+
},
129+
'should have been cleaned up': Test.testCleanup
125130
},
126131

127132
'when using discardDescriptor': {
@@ -133,6 +138,7 @@ vows.describe('File creation').addBatch({
133138
'should return with a name': Test.assertName,
134139
'should not return with a descriptor': Test.assertNoDescriptor,
135140
'should be a file': _testFileNoDescriptor(0100600),
141+
'should have been cleaned up': Test.testCleanup
136142
},
137143

138144
'when using detachDescriptor': {
@@ -147,6 +153,7 @@ vows.describe('File creation').addBatch({
147153
'should not return with an error': assert.isNull,
148154
'should return with a name': Test.assertName,
149155
'should have working descriptor after removeCallback': _testFileAfterDetachRemove(0100600),
156+
'should have been cleaned up': Test.testCleanup
150157
},
151158

152159
'when using multiple options': {
@@ -158,7 +165,8 @@ vows.describe('File creation').addBatch({
158165
'should return with a name': Test.assertName,
159166
'should be a file': _testFile(0100640, true),
160167
'should have the provided prefix': Test.testPrefix('foo'),
161-
'should have the provided postfix': Test.testPostfix('bar')
168+
'should have the provided postfix': Test.testPostfix('bar'),
169+
'should have been cleaned up': Test.testCleanup
162170
},
163171

164172
'when using multiple options and mode': {
@@ -170,7 +178,8 @@ vows.describe('File creation').addBatch({
170178
'should return with a name': Test.assertName,
171179
'should be a file': _testFile(0100644, true),
172180
'should have the provided prefix': Test.testPrefix('complicated'),
173-
'should have the provided postfix': Test.testPostfix('options')
181+
'should have the provided postfix': Test.testPostfix('options'),
182+
'should have been cleaned up': Test.testCleanup
174183
},
175184

176185
'no tries': {
@@ -190,7 +199,6 @@ vows.describe('File creation').addBatch({
190199
'should return with a name': Test.assertName,
191200
'should be a file': function (err, name) {
192201
_testFile(0100600, false)(err, name, null);
193-
fs.unlinkSync(name);
194202
}
195203
},
196204

0 commit comments

Comments
 (0)