Skip to content

Let the RWC harness iterate over files instead of building one big file#18416

Merged
weswigham merged 5 commits into
microsoft:masterfrom
weswigham:RWC-new-output-format
Sep 14, 2017
Merged

Let the RWC harness iterate over files instead of building one big file#18416
weswigham merged 5 commits into
microsoft:masterfrom
weswigham:RWC-new-output-format

Conversation

@weswigham
Copy link
Copy Markdown
Member

@mhegazy mentioned yesterday that he'd like it more if our RWC inputs and outputs were split into more files, such that they were easier to review changes to. This does that. There is a PR on our internal tracker with corresponding baseline updates.

Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not delete the old method in favour of multifile? Is there a reason to keep it around?

Comment thread src/harness/harness.ts
export function getErrorBaseline(inputFiles: ReadonlyArray<TestFile>, diagnostics: ReadonlyArray<ts.Diagnostic>, pretty?: boolean) {
let outputLines = "";
const gen = iterateErrorBaseline(inputFiles, diagnostics, pretty);
for (let {done, value} = gen.next(); !done; { done, value } = gen.next()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we use for-of? Is it that we target es5, or because es6's spec doesn't support it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not compile with --downlevelIteration on (and we do not include a Symbol.iterator polyfill)

Comment thread src/harness/rwcRunner.ts
Harness.Baseline.runBaseline(`${baseName}.output.js`, () => {
return Harness.Compiler.collateOutputs(compilerResult.files);
}, baselineOpts);
Harness.Baseline.runMultifileBaseline(baseName, "", () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically we should clone these tests so runBaseline doesn't break, right? If we intend to stop using runBaseLine, maybe we should just delete it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runBaseline is still used for tons of not-rwc-tests, so it's not like it is going away.

Comment thread src/harness/harness.ts Outdated

// 'merge' the lines of each input file with any errors associated with it
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
const filtered = inputFiles.filter(f => f.content !== undefined);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not inline? 🦑 👽 🦀

Comment thread src/harness/harness.ts Outdated
// 'merge' the lines of each input file with any errors associated with it
inputFiles.filter(f => f.content !== undefined).forEach(inputFile => {
const filtered = inputFiles.filter(f => f.content !== undefined);
const dupeMap = ts.createMap<true>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this dupeCase

Comment thread src/harness/harness.ts
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName);
}

export function runMultifileBaseline(relativeFileBase: string, extension: string, generateContent: () => IterableIterator<[string, string, number]> | IterableIterator<[string, string]>, opts?: BaselineOptions, referencedExtensions?: string[]): void {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like return type of generateContent would be better as IterableIterator<[string, string, number | undefined]>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An IterableIterator<[string, string]> is not assignable to an IterableIterator<[string, string, number | undefined]>, unfortunately. Tuple optionality would be nice.

Comment thread src/harness/harness.ts Outdated
// Collect, test, and sort the fileNames
outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName)));
let dupeCount = 0;
const dupeMap = ts.createMap<true>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same name comment here

Comment thread src/harness/harness.ts Outdated
// Yield them
for (const outputFile of outputFiles) {
let resultName = sanitizeTestFilePath(outputFile.fileName);
if (dupeMap.has(resultName)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it improve readability to extract this code to a function?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw it 3 or 4 times so I think it's a good idea.

Comment thread src/harness/harness.ts
Harness.Baseline.runBaseline(outputFileName, () => fullBaseLine, opts);
baselinePath.replace(/\.tsx?/, "") : baselinePath;

if (!multifile) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need the non-multifile mode? why not get rid of it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the non-multifile mode for the compiler runner, still. Which is probably a good thing, since those tests are small.

Comment thread src/harness/harness.ts
}

function *iterateBaseLine(typeWriterResults: ts.Map<TypeWriterResult[]>, isSymbolBaseline: boolean): IterableIterator<[string, string]> {
let typeLines = "";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you switch to string from string[] because string concatenation is fast enough in JS?

Copy link
Copy Markdown
Member Author

@weswigham weswigham Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fast enough, but faster.

@weswigham
Copy link
Copy Markdown
Member Author

@sandersn I did delete all the baselines for the old method... for our RWC tests. The single-output-file baseline methods are still used for compiler, conformance, test262, and some other tests, however, so the code is going to stick around. (Though all the collation/combining methods now defer to the iteration methods, to reduce duplication!) That's probably a good thing, since I really didn't want four 3-line files for each of the module resolution tests, anyway.

@weswigham weswigham force-pushed the RWC-new-output-format branch from 1d92f9f to e420c9c Compare September 14, 2017 22:44
@weswigham weswigham force-pushed the RWC-new-output-format branch from e420c9c to 7654f47 Compare September 14, 2017 22:45
@weswigham weswigham merged commit fd4a8d1 into microsoft:master Sep 14, 2017
@weswigham weswigham deleted the RWC-new-output-format branch September 14, 2017 23:24
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants