Skip to content

Commit

Permalink
add filenames to error messages in verify file content functions in f…
Browse files Browse the repository at this point in the history
…ourslash (#60143)
  • Loading branch information
iisaduan authored Oct 7, 2024
1 parent 44331b9 commit a719df4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3069,7 +3069,7 @@ export class TestState {
private verifyFileContent(fileName: string, text: string) {
const actual = this.getFileContent(fileName);
if (actual !== text) {
throw new Error(`verifyFileContent failed:\n${showTextDiff(text, actual)}`);
throw new Error(`verifyFileContent in file '${fileName}' failed:\n${showTextDiff(text, actual)}`);
}
}

Expand Down Expand Up @@ -3404,10 +3404,11 @@ export class TestState {
return ts.first(ranges);
}

private verifyTextMatches(actualText: string, includeWhitespace: boolean, expectedText: string) {
private verifyTextMatches(actualText: string, includeWhitespace: boolean, expectedText: string, fileName?: string) {
const removeWhitespace = (s: string): string => includeWhitespace ? s : this.removeWhitespace(s);
if (removeWhitespace(actualText) !== removeWhitespace(expectedText)) {
this.raiseError(`Actual range text doesn't match expected text.\n${showTextDiff(expectedText, actualText)}`);
const addFileName = fileName ? ` in file '${fileName}'` : "";
this.raiseError(`Actual range text${addFileName} doesn't match expected text.\n${showTextDiff(expectedText, actualText)}`);
}
}

Expand Down Expand Up @@ -3485,7 +3486,7 @@ export class TestState {
const newText = ts.textChanges.applyChanges(this.getFileContent(this.activeFile.fileName), change.textChanges);
const newRange = updateTextRangeForTextChanges(this.getOnlyRange(this.activeFile.fileName), change.textChanges);
const actualText = newText.slice(newRange.pos, newRange.end);
this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent);
this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent, change.fileName);
}
else {
if (newFileContent === undefined) throw ts.Debug.fail();
Expand All @@ -3497,7 +3498,7 @@ export class TestState {
}
const oldText = this.tryGetFileContent(change.fileName);
const newContent = change.isNewFile ? ts.first(change.textChanges).newText : ts.textChanges.applyChanges(oldText!, change.textChanges);
this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent);
this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent, change.fileName);
}
for (const newFileName in newFileContent) {
ts.Debug.assert(changes.some(c => c.fileName === newFileName), "No change in file", () => newFileName);
Expand Down

0 comments on commit a719df4

Please sign in to comment.