Skip to content

Commit

Permalink
Merge pull request #32 from shime/feature/customizable_filenames
Browse files Browse the repository at this point in the history
add ability to customize file/dir names
  • Loading branch information
raszi committed Nov 2, 2014
2 parents 539c116 + d93f352 commit 55d6467
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ function _getTmpName(options, callback) {

function _getName() {

if (opts.name){
return path.join(opts.dir || _TMP, opts.name);
}

// prefix and postfix
if (!templateDefined) {
var name = [
Expand Down
7 changes: 7 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ function _assertName(err, name) {
assert.isNotZero(name.length);
}

function _testName(expected){
return function _testPostfixGenerated(err, name, fd) {
assert.equal(expected, name, 'should have the provided name');
};
}

function _testUnsafeCleanup(unsafe, cb) {
_spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
}
Expand All @@ -71,4 +77,5 @@ module.exports.testPostfix = _testPostfix;
module.exports.testKeep = _testKeep;
module.exports.testGraceful = _testGraceful;
module.exports.assertName = _assertName;
module.exports.testName = _testName;
module.exports.testUnsafeCleanup = _testUnsafeCleanup;
13 changes: 12 additions & 1 deletion test/dir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ vows.describe('Directory creation').addBatch({

'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should be a file': _testDir(040700),
'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('/tmp/using-name')
},

'when using multiple options': {
topic: function () {
tmp.dir({ prefix: 'foo', postfix: 'bar', mode: 0750 }, this.callback);
Expand Down
11 changes: 11 additions & 0 deletions test/file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ vows.describe('File creation').addBatch({
'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 be a file': _testFile(0100600, true),
'should have the provided name': Test.testName('/tmp/using-name.tmp')
},

'when using multiple options': {
topic: function () {
tmp.file({ prefix: 'foo', postfix: 'bar', mode: 0640 }, this.callback);
Expand Down

0 comments on commit 55d6467

Please sign in to comment.