Fix tsc-instrumented
1. Make recursiveCreateDirectory correctly handle relative paths. 2. Remove dependency on Harness 3. Correctly increment iocapture0, iocapture1, ... iocaptureN. 4. Stop double-nesting baseline files.
This commit is contained in:
parent
89e19fff35
commit
93c2b10f68
2 changed files with 16 additions and 8 deletions
|
@ -570,10 +570,9 @@ namespace ts {
|
|||
realpath
|
||||
};
|
||||
}
|
||||
|
||||
function recursiveCreateDirectory(directoryPath: string, sys: System) {
|
||||
const basePath = getDirectoryPath(directoryPath);
|
||||
const shouldCreateParent = directoryPath !== basePath && !sys.directoryExists(basePath);
|
||||
const shouldCreateParent = basePath !== "" && directoryPath !== basePath && !sys.directoryExists(basePath);
|
||||
if (shouldCreateParent) {
|
||||
recursiveCreateDirectory(basePath, sys);
|
||||
}
|
||||
|
|
|
@ -157,11 +157,20 @@ namespace Playback {
|
|||
return log;
|
||||
}
|
||||
|
||||
const canonicalizeForHarness = ts.createGetCanonicalFileName(/*caseSensitive*/ false); // This is done so tests work on windows _and_ linux
|
||||
function sanitizeTestFilePath(name: string) {
|
||||
const path = ts.toPath(ts.normalizeSlashes(name.replace(/[\^<>:"|?*%]/g, "_")).replace(/\.\.\//g, "__dotdot/"), "", canonicalizeForHarness);
|
||||
if (ts.startsWith(path, "/")) {
|
||||
return path.substring(1);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
export function oldStyleLogIntoNewStyleLog(log: IOLog, writeFile: typeof Harness.IO.writeFile, baseTestName: string) {
|
||||
if (log.filesAppended) {
|
||||
for (const file of log.filesAppended) {
|
||||
if (file.contents !== undefined) {
|
||||
file.contentsPath = ts.combinePaths("appended", Harness.Compiler.sanitizeTestFilePath(file.path));
|
||||
file.contentsPath = ts.combinePaths("appended", sanitizeTestFilePath(file.path));
|
||||
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
|
||||
delete file.contents;
|
||||
}
|
||||
|
@ -170,7 +179,7 @@ namespace Playback {
|
|||
if (log.filesWritten) {
|
||||
for (const file of log.filesWritten) {
|
||||
if (file.contents !== undefined) {
|
||||
file.contentsPath = ts.combinePaths("written", Harness.Compiler.sanitizeTestFilePath(file.path));
|
||||
file.contentsPath = ts.combinePaths("written", sanitizeTestFilePath(file.path));
|
||||
writeFile(ts.combinePaths(baseTestName, file.contentsPath), file.contents);
|
||||
delete file.contents;
|
||||
}
|
||||
|
@ -180,7 +189,7 @@ namespace Playback {
|
|||
for (const file of log.filesRead) {
|
||||
const { contents } = file.result;
|
||||
if (contents !== undefined) {
|
||||
file.result.contentsPath = ts.combinePaths("read", Harness.Compiler.sanitizeTestFilePath(file.path));
|
||||
file.result.contentsPath = ts.combinePaths("read", sanitizeTestFilePath(file.path));
|
||||
writeFile(ts.combinePaths(baseTestName, file.result.contentsPath), contents);
|
||||
const len = contents.length;
|
||||
if (len >= 2 && contents.charCodeAt(0) === 0xfeff) {
|
||||
|
@ -235,8 +244,8 @@ namespace Playback {
|
|||
if (recordLog !== undefined) {
|
||||
let i = 0;
|
||||
const fn = () => recordLogFileNameBase + i;
|
||||
while (underlying.fileExists(fn() + ".json")) i++;
|
||||
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(ts.combinePaths(fn(), path), string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
|
||||
while (underlying.fileExists(ts.combinePaths(fn(), "test.json"))) i++;
|
||||
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
|
||||
recordLog = undefined;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue