From bd65bb67e25a79b019d745b7262b2008ce2adb15 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 16 Nov 2016 01:59:39 +0100 Subject: incrementally verify denoms The denominations are not stored in a separate object store. --- node_modules/tmp/test/base.js | 85 +++++++++++++++++++++++++++++++++++--- node_modules/tmp/test/dir-test.js | 41 +++++++++++++++--- node_modules/tmp/test/file-test.js | 20 +++++++-- node_modules/tmp/test/graceful.js | 2 +- 4 files changed, 133 insertions(+), 15 deletions(-) (limited to 'node_modules/tmp/test') diff --git a/node_modules/tmp/test/base.js b/node_modules/tmp/test/base.js index 498d8fb3b..a77f3a566 100644 --- a/node_modules/tmp/test/base.js +++ b/node_modules/tmp/test/base.js @@ -1,7 +1,12 @@ var assert = require('assert'), path = require('path'), - exec = require('child_process').exec; + 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); @@ -13,7 +18,6 @@ function _spawnTestWithoutError(testFile, params, cb) { function _spawnTest(passError, testFile, params, cb) { var - filename, node_path = process.argv[0], command = [ node_path, path.join(__dirname, testFile) ].concat(params).join(' '); @@ -37,38 +41,109 @@ function _testStat(stat, mode) { } function _testPrefix(prefix) { - return function _testPrefixGenerated(err, name, fd) { + 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, fd) { + 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); + 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; diff --git a/node_modules/tmp/test/dir-test.js b/node_modules/tmp/test/dir-test.js index 2e4e52999..9f2c282b3 100644 --- a/node_modules/tmp/test/dir-test.js +++ b/node_modules/tmp/test/dir-test.js @@ -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(path.join(tmp.tmpdir, 'using-name')) + }, + 'when using multiple options': { topic: function () { tmp.dir({ prefix: 'foo', postfix: 'bar', mode: 0750 }, this.callback); @@ -118,7 +129,7 @@ vows.describe('Directory creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'Directory should be removed'); } }, @@ -143,7 +154,7 @@ vows.describe('Directory creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'Directory should be removed'); } }, @@ -155,7 +166,7 @@ vows.describe('Directory creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'Directory should be removed'); }, 'should remove symlinked dir': function(err, name) { assert.ok( @@ -171,6 +182,18 @@ vows.describe('Directory creation').addBatch({ } }, + '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); @@ -178,7 +201,13 @@ 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 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': { @@ -190,7 +219,7 @@ vows.describe('Directory creation').addBatch({ 'should return with a name': Test.assertName, 'removeCallback should remove directory': function (_err, name, removeCallback) { removeCallback(); - assert.ok(!existsSync(name), "Directory should be removed"); + assert.ok(!existsSync(name), 'Directory should be removed'); } } }).exportTo(module); diff --git a/node_modules/tmp/test/file-test.js b/node_modules/tmp/test/file-test.js index d9605b38a..b710859c0 100644 --- a/node_modules/tmp/test/file-test.js +++ b/node_modules/tmp/test/file-test.js @@ -79,6 +79,20 @@ 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 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); @@ -132,7 +146,7 @@ vows.describe('File creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'File should be removed'); } }, @@ -157,7 +171,7 @@ vows.describe('File creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'File should be removed'); } }, @@ -170,7 +184,7 @@ vows.describe('File creation').addBatch({ '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"); + assert.ok(!existsSync(name), 'File should be removed'); } } diff --git a/node_modules/tmp/test/graceful.js b/node_modules/tmp/test/graceful.js index c898656f3..dbe554e1c 100644 --- a/node_modules/tmp/test/graceful.js +++ b/node_modules/tmp/test/graceful.js @@ -10,6 +10,6 @@ if (graceful) { spawn.tmpFunction(function (err, name) { spawn.out(name, function () { - throw new Error("Thrown on purpose"); + throw new Error('Thrown on purpose'); }); }); -- cgit v1.2.3