Skip to content

Commit

Permalink
Merge branch 'gh-133'
Browse files Browse the repository at this point in the history
fix #134
revert changes to tests introduced by #133
  • Loading branch information
silkentrance committed Jul 10, 2017
2 parents f8db66b + 6c2f762 commit 8f73d89
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 80 deletions.
19 changes: 0 additions & 19 deletions test/base.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
var
assert = require('assert'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn,
existsSync = fs.existsSync || path.existsSync,
tmp = require('../lib/tmp');

var _cleanup_fn = undefined;

// FIXME:does not seem to work at all
// make sure that we do not test spam the global tmp
tmp.TMP_DIR = './tmp';

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

function _testCleanup(err, name, fd, fn) {
var actual_fn = fn;
if (typeof(fd) == 'function') actual_fn = fd;
if (actual_fn) actual_fn();
assert.ok(!existsSync(name), 'should not exist');
}

function _testCleanupSync(result) {
result.removeCallback();
assert.ok(!existsSync(result.name), 'should not exist');
}

module.exports.testStat = _testStat;
module.exports.testPrefix = _testPrefix;
module.exports.testPrefixSync = _testPrefixSync;
Expand All @@ -237,5 +220,3 @@ module.exports.testIssue115File = _testIssue115File;
module.exports.testIssue115FileSync = _testIssue115FileSync;
module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
module.exports.testIssue62Sync = _testIssue62Sync;
module.exports.testCleanup = _testCleanup;
module.exports.testCleanupSync = _testCleanupSync;
23 changes: 9 additions & 14 deletions test/dir-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ vows.describe('Synchronous directory creation').addBatch({

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

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

'should return with a name': Test.assertNameSync,
'should be a directory': _testDir(040700),
'should have the provided prefix': Test.testPrefixSync('something'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided prefix': Test.testPrefixSync('something')
},

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

'should return with a name': Test.assertNameSync,
'should be a directory': _testDir(040700),
'should have the provided postfix': Test.testPostfixSync('.txt'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('.txt')
},

'when using template': {
Expand All @@ -65,8 +62,7 @@ vows.describe('Synchronous directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('-postfix')
},

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

'when using multiple options': {
Expand All @@ -90,8 +87,7 @@ vows.describe('Synchronous directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('bar')
},

'when using multiple options and mode': {
Expand All @@ -102,8 +98,7 @@ vows.describe('Synchronous directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('options')
},

'no tries': {
Expand Down
23 changes: 8 additions & 15 deletions test/dir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var
tmp = require('../lib/tmp.js'),
Test = require('./base.js');


function _testDir(mode) {
return function _testDirGenerated(err, name) {
assert.ok(existsSync(name), 'should exist');
Expand All @@ -22,16 +23,14 @@ function _testDir(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-'),
'should have been cleaned up': Test.testCleanup
'should have the default prefix': Test.testPrefix('tmp-')
},

'when using with prefix': {
Expand All @@ -42,8 +41,7 @@ vows.describe('Directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided prefix': Test.testPrefix('something')
},

'when using with postfix': {
Expand All @@ -54,8 +52,7 @@ vows.describe('Directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('.txt')
},

'when using template': {
Expand All @@ -67,8 +64,7 @@ vows.describe('Directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('-postfix')
},

'when using name': {
Expand All @@ -79,8 +75,7 @@ vows.describe('Directory creation').addBatch({
'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')),
'should have been cleaned up': Test.testCleanup
'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name'))
},

'when using multiple options': {
Expand All @@ -92,8 +87,7 @@ vows.describe('Directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('bar')
},

'when using multiple options and mode': {
Expand All @@ -105,8 +99,7 @@ vows.describe('Directory creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('options')
},

'no tries': {
Expand Down
26 changes: 10 additions & 16 deletions test/file-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ vows.describe('Synchronous file creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the default postfix': Test.testPostfixSync('.tmp')
},

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

'should return with a name': Test.assertNameSync,
'should be a file': _testFile(0100600, true),
'should have the provided prefix': Test.testPrefixSync('something'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided prefix': Test.testPrefixSync('something')
},

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

'should return with a name': Test.assertNameSync,
'should be a file': _testFile(0100600, true),
'should have the provided postfix': Test.testPostfixSync('.txt'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('.txt')
},

'when using template': {
Expand All @@ -77,21 +74,20 @@ vows.describe('Synchronous file creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('-postfix')
},

'when using name': {
topic: function () {
return tmp.fileSync({ name: 'using-name' });
return tmp.fileSync({ name: 'using-name-sync.tmp' });
},

'should return with a name': Test.assertNameSync,
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name')),
'should have the provided name': Test.testNameSync(path.join(tmp.tmpdir, 'using-name-sync.tmp')),
'should be a file': function (result) {
_testFile(0100600, true);
},
'should have been cleaned up': Test.testCleanupSync
fs.unlinkSync(result.name);
}
},

'when using multiple options': {
Expand All @@ -102,8 +98,7 @@ vows.describe('Synchronous file creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('bar')
},

'when using multiple options and mode': {
Expand All @@ -114,8 +109,7 @@ vows.describe('Synchronous file creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanupSync
'should have the provided postfix': Test.testPostfixSync('options')
},

'no tries': {
Expand Down
24 changes: 8 additions & 16 deletions test/file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the default postfix': Test.testPostfix('.tmp')
},

'when using with prefix': {
Expand All @@ -85,8 +84,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided prefix': Test.testPrefix('something')
},

'when using with postfix': {
Expand All @@ -97,8 +95,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('.txt')
},

'when using template': {
Expand All @@ -110,8 +107,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('-postfix')
},

'when using name': {
Expand All @@ -125,8 +121,7 @@ vows.describe('File creation').addBatch({
'should be a file': function (err, name) {
_testFile(0100600, true);
fs.unlinkSync(name);
},
'should have been cleaned up': Test.testCleanup
}
},

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

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

'when using multiple options': {
Expand All @@ -165,8 +158,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('bar')
},

'when using multiple options and mode': {
Expand All @@ -178,8 +170,7 @@ vows.describe('File creation').addBatch({
'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'),
'should have been cleaned up': Test.testCleanup
'should have the provided postfix': Test.testPostfix('options')
},

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

Expand Down

0 comments on commit 8f73d89

Please sign in to comment.