Skip to content

Commit a719df4

Browse files
authored
add filenames to error messages in verify file content functions in fourslash (#60143)
1 parent 44331b9 commit a719df4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/harness/fourslashImpl.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,7 @@ export class TestState {
30693069
private verifyFileContent(fileName: string, text: string) {
30703070
const actual = this.getFileContent(fileName);
30713071
if (actual !== text) {
3072-
throw new Error(`verifyFileContent failed:\n${showTextDiff(text, actual)}`);
3072+
throw new Error(`verifyFileContent in file '${fileName}' failed:\n${showTextDiff(text, actual)}`);
30733073
}
30743074
}
30753075

@@ -3404,10 +3404,11 @@ export class TestState {
34043404
return ts.first(ranges);
34053405
}
34063406

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

@@ -3485,7 +3486,7 @@ export class TestState {
34853486
const newText = ts.textChanges.applyChanges(this.getFileContent(this.activeFile.fileName), change.textChanges);
34863487
const newRange = updateTextRangeForTextChanges(this.getOnlyRange(this.activeFile.fileName), change.textChanges);
34873488
const actualText = newText.slice(newRange.pos, newRange.end);
3488-
this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent);
3489+
this.verifyTextMatches(actualText, /*includeWhitespace*/ true, newRangeContent, change.fileName);
34893490
}
34903491
else {
34913492
if (newFileContent === undefined) throw ts.Debug.fail();
@@ -3497,7 +3498,7 @@ export class TestState {
34973498
}
34983499
const oldText = this.tryGetFileContent(change.fileName);
34993500
const newContent = change.isNewFile ? ts.first(change.textChanges).newText : ts.textChanges.applyChanges(oldText!, change.textChanges);
3500-
this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent);
3501+
this.verifyTextMatches(newContent, /*includeWhitespace*/ true, expectedNewContent, change.fileName);
35013502
}
35023503
for (const newFileName in newFileContent) {
35033504
ts.Debug.assert(changes.some(c => c.fileName === newFileName), "No change in file", () => newFileName);

0 commit comments

Comments
 (0)