Skip to content

Commit da6d951

Browse files
authored
Remove extraneous arguments from harness's runBaseline (#10419)
* Remove extraneous arguments from runBaseline * Address comments from @yuit
1 parent 0168ab2 commit da6d951

8 files changed

+73
-95
lines changed

src/harness/compilerRunner.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CompilerBaselineRunner extends RunnerBase {
147147
// check errors
148148
it("Correct errors for " + fileName, () => {
149149
if (this.errors) {
150-
Harness.Baseline.runBaseline("Correct errors for " + fileName, justName.replace(/\.tsx?$/, ".errors.txt"), (): string => {
150+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".errors.txt"), (): string => {
151151
if (result.errors.length === 0) return null;
152152
return getErrorBaseline(toBeCompiled, otherFiles, result);
153153
});
@@ -156,7 +156,7 @@ class CompilerBaselineRunner extends RunnerBase {
156156

157157
it (`Correct module resolution tracing for ${fileName}`, () => {
158158
if (options.traceResolution) {
159-
Harness.Baseline.runBaseline("Correct module resolution tracing for " + fileName, justName.replace(/\.tsx?$/, ".trace.json"), () => {
159+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".trace.json"), () => {
160160
return JSON.stringify(result.traceResults || [], undefined, 4);
161161
});
162162
}
@@ -165,7 +165,7 @@ class CompilerBaselineRunner extends RunnerBase {
165165
// Source maps?
166166
it("Correct sourcemap content for " + fileName, () => {
167167
if (options.sourceMap || options.inlineSourceMap) {
168-
Harness.Baseline.runBaseline("Correct sourcemap content for " + fileName, justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => {
168+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => {
169169
const record = result.getSourceMapRecord();
170170
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
171171
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn"t required.
@@ -183,7 +183,7 @@ class CompilerBaselineRunner extends RunnerBase {
183183
}
184184

185185
// check js output
186-
Harness.Baseline.runBaseline("Correct JS output for " + fileName, justName.replace(/\.tsx?/, ".js"), () => {
186+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, ".js"), () => {
187187
let tsCode = "";
188188
const tsSources = otherFiles.concat(toBeCompiled);
189189
if (tsSources.length > 1) {
@@ -242,7 +242,7 @@ class CompilerBaselineRunner extends RunnerBase {
242242
throw new Error("Number of sourcemap files should be same as js files.");
243243
}
244244

245-
Harness.Baseline.runBaseline("Correct Sourcemap output for " + fileName, justName.replace(/\.tsx?/, ".js.map"), () => {
245+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, ".js.map"), () => {
246246
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
247247
// We need to return null here or the runBaseLine will actually create a empty file.
248248
// Baselining isn't required here because there is no output.
@@ -330,11 +330,11 @@ class CompilerBaselineRunner extends RunnerBase {
330330
const pullExtension = isSymbolBaseLine ? ".symbols.pull" : ".types.pull";
331331

332332
if (fullBaseLine !== pullBaseLine) {
333-
Harness.Baseline.runBaseline("Correct full information for " + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
334-
Harness.Baseline.runBaseline("Correct pull information for " + fileName, justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine);
333+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
334+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, pullExtension), () => pullBaseLine);
335335
}
336336
else {
337-
Harness.Baseline.runBaseline("Correct information for " + fileName, justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
337+
Harness.Baseline.runBaseline(justName.replace(/\.tsx?/, fullExtension), () => fullBaseLine);
338338
}
339339
}
340340

src/harness/fourslash.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1132,12 +1132,10 @@ namespace FourSlash {
11321132

11331133
}
11341134
Harness.Baseline.runBaseline(
1135-
"Breakpoint Locations for " + this.activeFile.fileName,
11361135
baselineFile,
11371136
() => {
11381137
return this.baselineCurrentFileLocations(pos => this.getBreakpointStatementLocation(pos));
1139-
},
1140-
true /* run immediately */);
1138+
});
11411139
}
11421140

11431141
public baselineGetEmitOutput() {
@@ -1159,7 +1157,6 @@ namespace FourSlash {
11591157
}
11601158

11611159
Harness.Baseline.runBaseline(
1162-
"Generate getEmitOutput baseline : " + emitFiles.join(" "),
11631160
this.testData.globalOptions[metadataOptionNames.baselineFile],
11641161
() => {
11651162
let resultString = "";
@@ -1185,8 +1182,7 @@ namespace FourSlash {
11851182
});
11861183

11871184
return resultString;
1188-
},
1189-
true /* run immediately */);
1185+
});
11901186
}
11911187

11921188
public printBreakpointLocation(pos: number) {
@@ -1730,13 +1726,11 @@ namespace FourSlash {
17301726

17311727
public baselineCurrentFileNameOrDottedNameSpans() {
17321728
Harness.Baseline.runBaseline(
1733-
"Name OrDottedNameSpans for " + this.activeFile.fileName,
17341729
this.testData.globalOptions[metadataOptionNames.baselineFile],
17351730
() => {
17361731
return this.baselineCurrentFileLocations(pos =>
17371732
this.getNameOrDottedNameSpan(pos));
1738-
},
1739-
true /* run immediately */);
1733+
});
17401734
}
17411735

17421736
public printNameOrDottedNameSpans(pos: number) {

src/harness/harness.ts

+34-50
Original file line numberDiff line numberDiff line change
@@ -1604,31 +1604,7 @@ namespace Harness {
16041604
}
16051605

16061606
const fileCache: { [idx: string]: boolean } = {};
1607-
function generateActual(actualFileName: string, generateContent: () => string): string {
1608-
// For now this is written using TypeScript, because sys is not available when running old test cases.
1609-
// But we need to move to sys once we have
1610-
// Creates the directory including its parent if not already present
1611-
function createDirectoryStructure(dirName: string) {
1612-
if (fileCache[dirName] || IO.directoryExists(dirName)) {
1613-
fileCache[dirName] = true;
1614-
return;
1615-
}
1616-
1617-
const parentDirectory = IO.directoryName(dirName);
1618-
if (parentDirectory != "") {
1619-
createDirectoryStructure(parentDirectory);
1620-
}
1621-
IO.createDirectory(dirName);
1622-
fileCache[dirName] = true;
1623-
}
1624-
1625-
// Create folders if needed
1626-
createDirectoryStructure(Harness.IO.directoryName(actualFileName));
1627-
1628-
// Delete the actual file in case it fails
1629-
if (IO.fileExists(actualFileName)) {
1630-
IO.deleteFile(actualFileName);
1631-
}
1607+
function generateActual(generateContent: () => string): string {
16321608

16331609
const actual = generateContent();
16341610

@@ -1663,43 +1639,51 @@ namespace Harness {
16631639
return { expected, actual };
16641640
}
16651641

1666-
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
1642+
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string) {
1643+
// For now this is written using TypeScript, because sys is not available when running old test cases.
1644+
// But we need to move to sys once we have
1645+
// Creates the directory including its parent if not already present
1646+
function createDirectoryStructure(dirName: string) {
1647+
if (fileCache[dirName] || IO.directoryExists(dirName)) {
1648+
fileCache[dirName] = true;
1649+
return;
1650+
}
1651+
1652+
const parentDirectory = IO.directoryName(dirName);
1653+
if (parentDirectory != "") {
1654+
createDirectoryStructure(parentDirectory);
1655+
}
1656+
IO.createDirectory(dirName);
1657+
fileCache[dirName] = true;
1658+
}
1659+
1660+
// Create folders if needed
1661+
createDirectoryStructure(Harness.IO.directoryName(actualFileName));
1662+
1663+
// Delete the actual file in case it fails
1664+
if (IO.fileExists(actualFileName)) {
1665+
IO.deleteFile(actualFileName);
1666+
}
1667+
16671668
const encoded_actual = Utils.encodeString(actual);
16681669
if (expected !== encoded_actual) {
16691670
if (actual === NoContent) {
1670-
IO.writeFile(localPath(relativeFileName + ".delete"), "");
1671+
IO.writeFile(actualFileName + ".delete", "");
16711672
}
16721673
else {
1673-
IO.writeFile(localPath(relativeFileName), actual);
1674+
IO.writeFile(actualFileName, actual);
16741675
}
1675-
// Overwrite & issue error
1676-
const errMsg = "The baseline file " + relativeFileName + " has changed.";
1677-
throw new Error(errMsg);
1676+
throw new Error(`The baseline file ${relativeFileName} has changed.`);
16781677
}
16791678
}
16801679

1680+
export function runBaseline(relativeFileName: string, generateContent: () => string, opts?: BaselineOptions): void {
16811681

1682-
export function runBaseline(
1683-
descriptionForDescribe: string,
1684-
relativeFileName: string,
1685-
generateContent: () => string,
1686-
runImmediately = false,
1687-
opts?: BaselineOptions): void {
1688-
1689-
let actual = <string>undefined;
16901682
const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
16911683

1692-
if (runImmediately) {
1693-
actual = generateActual(actualFileName, generateContent);
1694-
const comparison = compareToBaseline(actual, relativeFileName, opts);
1695-
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName, descriptionForDescribe);
1696-
}
1697-
else {
1698-
actual = generateActual(actualFileName, generateContent);
1699-
1700-
const comparison = compareToBaseline(actual, relativeFileName, opts);
1701-
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName, descriptionForDescribe);
1702-
}
1684+
const actual = generateActual(generateContent);
1685+
const comparison = compareToBaseline(actual, relativeFileName, opts);
1686+
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName);
17031687
}
17041688
}
17051689

src/harness/projectsRunner.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ class ProjectRunner extends RunnerBase {
459459
});
460460

461461
it("Resolution information of (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => {
462-
Harness.Baseline.runBaseline("Resolution information of (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".json", () => {
462+
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".json", () => {
463463
return JSON.stringify(getCompilerResolutionInfo(), undefined, " ");
464464
});
465465
});
466466

467467

468468
it("Errors for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => {
469469
if (compilerResult.errors.length) {
470-
Harness.Baseline.runBaseline("Errors for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".errors.txt", () => {
470+
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".errors.txt", () => {
471471
return getErrorsBaseline(compilerResult);
472472
});
473473
}
@@ -481,7 +481,7 @@ class ProjectRunner extends RunnerBase {
481481
// There may be multiple files with different baselines. Run all and report at the end, else
482482
// it stops copying the remaining emitted files from 'local/projectOutput' to 'local/project'.
483483
try {
484-
Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
484+
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
485485
try {
486486
return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
487487
}
@@ -503,7 +503,7 @@ class ProjectRunner extends RunnerBase {
503503

504504
it("SourceMapRecord for (" + moduleNameToString(moduleKind) + "): " + testCaseFileName, () => {
505505
if (compilerResult.sourceMapData) {
506-
Harness.Baseline.runBaseline("SourceMapRecord for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => {
506+
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".sourcemap.txt", () => {
507507
return Harness.SourceMapRecorder.getSourceMapRecord(compilerResult.sourceMapData, compilerResult.program,
508508
ts.filter(compilerResult.outputFiles, outputFile => Harness.Compiler.isJS(outputFile.emittedFileName)));
509509
});
@@ -516,7 +516,7 @@ class ProjectRunner extends RunnerBase {
516516
if (!compilerResult.errors.length && testCase.declaration) {
517517
const dTsCompileResult = compileCompileDTsFiles(compilerResult);
518518
if (dTsCompileResult && dTsCompileResult.errors.length) {
519-
Harness.Baseline.runBaseline("Errors in generated Dts files for (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".dts.errors.txt", () => {
519+
Harness.Baseline.runBaseline(getBaselineFolder(compilerResult.moduleKind) + testCaseJustName + ".dts.errors.txt", () => {
520520
return getErrorsBaseline(dTsCompileResult);
521521
});
522522
}

src/harness/rwcRunner.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -158,56 +158,56 @@ namespace RWC {
158158

159159

160160
it("has the expected emitted code", () => {
161-
Harness.Baseline.runBaseline("has the expected emitted code", baseName + ".output.js", () => {
161+
Harness.Baseline.runBaseline(baseName + ".output.js", () => {
162162
return Harness.Compiler.collateOutputs(compilerResult.files);
163-
}, false, baselineOpts);
163+
}, baselineOpts);
164164
});
165165

166166
it("has the expected declaration file content", () => {
167-
Harness.Baseline.runBaseline("has the expected declaration file content", baseName + ".d.ts", () => {
167+
Harness.Baseline.runBaseline(baseName + ".d.ts", () => {
168168
if (!compilerResult.declFilesCode.length) {
169169
return null;
170170
}
171171

172172
return Harness.Compiler.collateOutputs(compilerResult.declFilesCode);
173-
}, false, baselineOpts);
173+
}, baselineOpts);
174174
});
175175

176176
it("has the expected source maps", () => {
177-
Harness.Baseline.runBaseline("has the expected source maps", baseName + ".map", () => {
177+
Harness.Baseline.runBaseline(baseName + ".map", () => {
178178
if (!compilerResult.sourceMaps.length) {
179179
return null;
180180
}
181181

182182
return Harness.Compiler.collateOutputs(compilerResult.sourceMaps);
183-
}, false, baselineOpts);
183+
}, baselineOpts);
184184
});
185185

186186
/*it("has correct source map record", () => {
187187
if (compilerOptions.sourceMap) {
188-
Harness.Baseline.runBaseline("has correct source map record", baseName + ".sourcemap.txt", () => {
188+
Harness.Baseline.runBaseline(baseName + ".sourcemap.txt", () => {
189189
return compilerResult.getSourceMapRecord();
190-
}, false, baselineOpts);
190+
}, baselineOpts);
191191
}
192192
});*/
193193

194194
it("has the expected errors", () => {
195-
Harness.Baseline.runBaseline("has the expected errors", baseName + ".errors.txt", () => {
195+
Harness.Baseline.runBaseline(baseName + ".errors.txt", () => {
196196
if (compilerResult.errors.length === 0) {
197197
return null;
198198
}
199199
// Do not include the library in the baselines to avoid noise
200200
const baselineFiles = inputFiles.concat(otherFiles).filter(f => !Harness.isDefaultLibraryFile(f.unitName));
201201
const errors = compilerResult.errors.filter(e => !Harness.isDefaultLibraryFile(e.file.fileName));
202202
return Harness.Compiler.getErrorBaseline(baselineFiles, errors);
203-
}, false, baselineOpts);
203+
}, baselineOpts);
204204
});
205205

206206
// Ideally, a generated declaration file will have no errors. But we allow generated
207207
// declaration file errors as part of the baseline.
208208
it("has the expected errors in generated declaration files", () => {
209209
if (compilerOptions.declaration && !compilerResult.errors.length) {
210-
Harness.Baseline.runBaseline("has the expected errors in generated declaration files", baseName + ".dts.errors.txt", () => {
210+
Harness.Baseline.runBaseline(baseName + ".dts.errors.txt", () => {
211211
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(
212212
inputFiles, otherFiles, compilerResult, /*harnessSettings*/ undefined, compilerOptions, currentDirectory);
213213

@@ -218,7 +218,7 @@ namespace RWC {
218218
return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) +
219219
Harness.IO.newLine() + Harness.IO.newLine() +
220220
Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors);
221-
}, false, baselineOpts);
221+
}, baselineOpts);
222222
}
223223
});
224224

0 commit comments

Comments
 (0)