Skip to content

Commit

Permalink
Adjust raszi#246 regression tests into raszi#268 regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbargiel committed Aug 26, 2022
1 parent fbc65be commit a831713
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
35 changes: 34 additions & 1 deletion test/name-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const
assert = require('assert'),
os = require('os'),
path = require('path'),
inbandStandardTests = require('./name-inband-standard'),
tmp = require('../lib/tmp');

const isWindows = os.platform() === 'win32';

describe('tmp', function () {
describe('#tmpNameSync()', function () {
Expand Down Expand Up @@ -39,7 +41,9 @@ describe('tmp', function () {
describe('on issue #176', function () {
const origfn = os.tmpdir;
it('must fail on invalid os.tmpdir()', function () {
os.tmpdir = function () { return undefined; };
os.tmpdir = function () {
return undefined;
};
try {
tmp.tmpNameSync();
assert.fail('should have failed');
Expand All @@ -50,6 +54,35 @@ describe('tmp', function () {
}
});
});
describe('on issue #268', function () {
const origfn = os.tmpdir;
it(`should not alter ${isWindows ? 'invalid' : 'valid'} path on os.tmpdir() returning path that includes double quotes`, function () {
const tmpdir = isWindows ? '"C:\\Temp With Spaces"' : '"/tmp with spaces"';
os.tmpdir = function () {
return tmpdir;
};
const name = tmp.tmpNameSync();
const index = name.indexOf(path.sep + tmpdir + path.sep);
try {
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
} finally {
os.tmpdir = origfn;
}
});
it('should not alter valid path on os.tmpdir() returning path that includes single quotes', function () {
const tmpdir = isWindows ? '\'C:\\Temp With Spaces\'' : '\'/tmp with spaces\'';
os.tmpdir = function () {
return tmpdir;
};
const name = tmp.tmpNameSync();
const index = name.indexOf(path.sep + tmpdir + path.sep);
try {
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
} finally {
os.tmpdir = origfn;
}
});
});
});

describe('when running standard outband tests', function () {
Expand Down
36 changes: 35 additions & 1 deletion test/name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
const
assert = require('assert'),
os = require('os'),
path = require('path'),
inbandStandardTests = require('./name-inband-standard'),
tmp = require('../lib/tmp');

const isWindows = os.platform() === 'win32';

describe('tmp', function () {
describe('#tmpName()', function () {
Expand Down Expand Up @@ -62,6 +64,39 @@ describe('tmp', function () {
});
});
});
describe('on issue #268', function () {
const origfn = os.tmpdir;
it(`should not alter ${isWindows ? 'invalid' : 'valid'} path on os.tmpdir() returning path that includes double quotes`, function (done) {
const tmpdir = isWindows ? '"C:\\Temp With Spaces"' : '"/tmp with spaces"';
os.tmpdir = function () { return tmpdir; };
tmp.tmpName(function (err, name) {
const index = name.indexOf(path.sep + tmpdir + path.sep);
try {
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
} catch (err) {
return done(err);
} finally {
os.tmpdir = origfn;
}
done();
});
});
it('should not alter valid path on os.tmpdir() returning path that includes single quotes', function (done) {
const tmpdir = isWindows ? '\'C:\\Temp With Spaces\'' : '\'/tmp with spaces\'';
os.tmpdir = function () { return tmpdir; };
tmp.tmpName(function (err, name) {
const index = name.indexOf(path.sep + tmpdir + path.sep);
try {
assert.ok(index > 0, `${tmpdir} should have been a subdirectory name in ${name}`);
} catch (err) {
return done(err);
} finally {
os.tmpdir = origfn;
}
done();
});
});
});
});

describe('when running standard outband tests', function () {
Expand All @@ -71,4 +106,3 @@ describe('tmp', function () {
});
});
});

0 comments on commit a831713

Please sign in to comment.