tests - improve ext path tests

This commit is contained in:
Benjamin Pasero 2021-01-11 15:28:18 +01:00
parent 55bd92dd53
commit 8ec95fa3b7

View file

@ -5,66 +5,55 @@
import * as assert from 'assert';
import * as os from 'os';
import * as path from 'vs/base/common/path';
import * as pfs from 'vs/base/node/pfs';
import { realcaseSync, realpath, realpathSync } from 'vs/base/node/extpath';
import { flakySuite, getRandomTestPath } from 'vs/base/test/node/testUtils';
flakySuite('Extpath', () => {
let testDir: string;
setup(() => {
testDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'extpath');
return pfs.mkdirp(testDir, 493);
});
teardown(() => {
return pfs.rimraf(testDir);
});
test('realcase', async () => {
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'extpath');
const newDir = path.join(parentDir, 'newdir');
await pfs.mkdirp(newDir, 493);
// assume case insensitive file system
if (process.platform === 'win32' || process.platform === 'darwin') {
const upper = newDir.toUpperCase();
const upper = testDir.toUpperCase();
const real = realcaseSync(upper);
if (real) { // can be null in case of permission errors
assert.notEqual(real, upper);
assert.equal(real.toUpperCase(), upper);
assert.equal(real, newDir);
assert.equal(real, testDir);
}
}
// linux, unix, etc. -> assume case sensitive file system
else {
const real = realcaseSync(newDir);
assert.equal(real, newDir);
const real = realcaseSync(testDir);
assert.equal(real, testDir);
}
await pfs.rimraf(parentDir);
});
test('realpath', async () => {
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'extpath');
const newDir = path.join(parentDir, 'newdir');
await pfs.mkdirp(newDir, 493);
const realpathVal = await realpath(newDir);
const realpathVal = await realpath(testDir);
assert.ok(realpathVal);
await pfs.rimraf(parentDir);
});
test('realpathSync', async () => {
const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'extpath');
const newDir = path.join(parentDir, 'newdir');
await pfs.mkdirp(newDir, 493);
let realpath!: string;
try {
realpath = realpathSync(newDir);
const realpath = realpathSync(testDir);
assert.ok(realpath);
} catch (error) {
assert.ok(!error);
assert.fail(error);
}
assert.ok(realpath!);
await pfs.rimraf(parentDir);
});
});