Skip to content

Commit ca3bcc1

Browse files
committed
Improve display of lines in test output. (#17373)
* Improve display of lines in test output. * Add news item
1 parent 7c51c8c commit ca3bcc1

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

news/2 Fixes/17111.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure line feeds are changed to CRLF in test messages.

src/client/testing/testController/common/resultsHelper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as fsapi from 'fs-extra';
55
import { Location, TestItem, TestMessage, TestRun } from 'vscode';
66
import { getRunIdFromRawData, getTestCaseNodes } from './testItemUtilities';
77
import { TestData } from './types';
8+
import { fixLogLines } from './utils';
89

910
type TestSuiteResult = {
1011
$: {
@@ -113,7 +114,7 @@ export async function updateResultFromJunitXml(
113114
}
114115

115116
runInstance.errored(node, message);
116-
runInstance.appendOutput(text);
117+
runInstance.appendOutput(fixLogLines(text));
117118
} else if (result.failure) {
118119
failures += 1;
119120
const failure = result.failure[0];
@@ -125,23 +126,23 @@ export async function updateResultFromJunitXml(
125126
}
126127

127128
runInstance.failed(node, message);
128-
runInstance.appendOutput(text);
129+
runInstance.appendOutput(fixLogLines(text));
129130
} else if (result.skipped) {
130131
skipped += 1;
131132
const skip = result.skipped[0];
132133
const text = `${rawTestCaseNode.rawId} Skipped: [${skip.$.type}]${skip.$.message}\r\n`;
133134

134135
runInstance.skipped(node);
135-
runInstance.appendOutput(text);
136+
runInstance.appendOutput(fixLogLines(text));
136137
} else {
137138
passed += 1;
138139
const text = `${rawTestCaseNode.rawId} Passed\r\n`;
139140
runInstance.passed(node);
140-
runInstance.appendOutput(text);
141+
runInstance.appendOutput(fixLogLines(text));
141142
}
142143
} else {
143144
const text = `Test result not found for: ${rawTestCaseNode.rawId}\r\n`;
144-
runInstance.appendOutput(text);
145+
runInstance.appendOutput(fixLogLines(text));
145146
const message = new TestMessage(text);
146147

147148
if (node.uri && node.range) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
export function fixLogLines(content: string): string {
5+
const lines = content.split(/\r?\n/g);
6+
return `${lines.join('\r\n')}\r\n`;
7+
}

src/client/testing/testController/unittest/runner.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ITestRunner, ITestDebugLauncher, IUnitTestSocketServer, LaunchOptions,
1212
import { TEST_OUTPUT_CHANNEL } from '../../constants';
1313
import { getTestCaseNodes } from '../common/testItemUtilities';
1414
import { ITestRun, ITestsRunner, TestData, TestRunInstanceOptions, TestRunOptions } from '../common/types';
15+
import { fixLogLines } from '../common/utils';
1516
import { getTestRunArgs } from './arguments';
1617

1718
interface ITestData {
@@ -102,7 +103,7 @@ export class UnittestRunner implements ITestsRunner {
102103
if (data.outcome === 'passed' || data.outcome === 'failed-expected') {
103104
const text = `${rawTestCase.rawId} Passed\r\n`;
104105
runInstance.passed(testCase);
105-
runInstance.appendOutput(text);
106+
runInstance.appendOutput(fixLogLines(text));
106107
counts.passed += 1;
107108
} else if (data.outcome === 'failed' || data.outcome === 'passed-unexpected') {
108109
const traceback = data.traceback
@@ -116,7 +117,7 @@ export class UnittestRunner implements ITestsRunner {
116117
}
117118

118119
runInstance.failed(testCase, message);
119-
runInstance.appendOutput(text);
120+
runInstance.appendOutput(fixLogLines(text));
120121
counts.failed += 1;
121122
if (failFast) {
122123
stopTesting = true;
@@ -133,7 +134,7 @@ export class UnittestRunner implements ITestsRunner {
133134
}
134135

135136
runInstance.errored(testCase, message);
136-
runInstance.appendOutput(text);
137+
runInstance.appendOutput(fixLogLines(text));
137138
counts.errored += 1;
138139
if (failFast) {
139140
stopTesting = true;
@@ -144,11 +145,11 @@ export class UnittestRunner implements ITestsRunner {
144145
: '';
145146
const text = `${rawTestCase.rawId} Skipped: ${data.message}\r\n${traceback}\r\n`;
146147
runInstance.skipped(testCase);
147-
runInstance.appendOutput(text);
148+
runInstance.appendOutput(fixLogLines(text));
148149
counts.skipped += 1;
149150
} else {
150151
const text = `Unknown outcome type for test ${rawTestCase.rawId}: ${data.outcome}`;
151-
runInstance.appendOutput(text);
152+
runInstance.appendOutput(fixLogLines(text));
152153
const message = new TestMessage(text);
153154
if (testCase.uri && testCase.range) {
154155
message.location = new Location(testCase.uri, testCase.range);

0 commit comments

Comments
 (0)