fix: Line separators are missing in diff messages (#1444)

Signed-off-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Sheng Chen 2022-06-29 15:29:42 +08:00 коммит произвёл GitHub
Родитель e7793f97ce
Коммит ea7ffb1472
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 56 добавлений и 3 удалений

Просмотреть файл

@ -47,9 +47,6 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
public analyzeData(data: string): void {
const lines: string[] = data.split(/\r?\n/);
for (const line of lines) {
if (!line) {
continue;
}
this.processData(line);
this.testContext.testRun.appendOutput(line + '\r\n');
}

Просмотреть файл

@ -226,4 +226,60 @@ java.lang.RuntimeException
const testMessage = erroredSpy.getCall(0).args[1] as TestMessage;
assert.strictEqual(testMessage.location?.range.start.line, 8);
});
test("test diff with line separators", () => {
const testItem = generateTestItem(testController, 'junit@junit5.TestAnnotation#shouldFail2', TestKind.JUnit5, new Range(8, 0, 10, 0));
const testRunRequest = new TestRunRequest([testItem], []);
const testRun = testController.createTestRun(testRunRequest);
const startedSpy = sinon.spy(testRun, 'started');
const failedSpy = sinon.spy(testRun, 'failed');
const testRunnerOutput = `%TESTC 1 v2
%TSTTREE2,junit5.TestAnnotation,true,1,false,1,TestAnnotation,,[engine:junit-jupiter]/[class:junit5.TestAnnotation]
%TSTTREE3,shouldFail2(junit5.TestAnnotation),false,1,false,2,shouldFail2(),,[engine:junit-jupiter]/[class:junit5.TestAnnotation]/[method:shouldFail2()]
%TESTS 3,shouldFail2(junit5.TestAnnotation)
%FAILED 3,shouldFail2(junit5.TestAnnotation)
%EXPECTS
hello
world
%EXPECTE
%ACTUALS
hello
world
%ACTUALE
%TRACES
org.junit.ComparisonFailure: expected:<hello
[]world> but was:<hello
[
]world>
at org.junit.Assert.assertEquals(Assert.java:117)
at org.junit.Assert.assertEquals(Assert.java:146)
at junit5.TestAnnotation.shouldFail2(TestAnnotation.java:15)
%TRACEE
%TESTE 3,shouldFail2(junit5.TestAnnotation)
%RUNTIME99`;
const runnerContext: IRunTestContext = {
isDebug: false,
kind: TestKind.JUnit5,
projectName: 'junit',
testItems: [testItem],
testRun: testRun,
workspaceFolder: workspace.workspaceFolders?.[0]!,
};
const analyzer = new JUnitRunnerResultAnalyzer(runnerContext);
analyzer.analyzeData(testRunnerOutput);
sinon.assert.calledWith(startedSpy, testItem);
sinon.assert.calledWith(failedSpy, testItem, sinon.match.any);
const testMessage = failedSpy.getCall(0).args[1] as TestMessage;
assert.strictEqual(testMessage.actualOutput, 'hello\n\nworld');
assert.strictEqual(testMessage.expectedOutput, 'hello\nworld');
assert.strictEqual(testMessage.location?.range.start.line, 8);
});
});