diff --git a/news/2 Fixes/17111.md b/news/2 Fixes/17111.md new file mode 100644 index 000000000000..2e735435b2dc --- /dev/null +++ b/news/2 Fixes/17111.md @@ -0,0 +1 @@ +Ensure line feeds are changed to CRLF in test messages. diff --git a/src/client/testing/testController/common/resultsHelper.ts b/src/client/testing/testController/common/resultsHelper.ts index 7eaceeb398d0..823a87c79df2 100644 --- a/src/client/testing/testController/common/resultsHelper.ts +++ b/src/client/testing/testController/common/resultsHelper.ts @@ -5,6 +5,7 @@ import * as fsapi from 'fs-extra'; import { Location, TestItem, TestMessage, TestRun } from 'vscode'; import { getRunIdFromRawData, getTestCaseNodes } from './testItemUtilities'; import { TestData } from './types'; +import { fixLogLines } from './utils'; type TestSuiteResult = { $: { @@ -113,7 +114,7 @@ export async function updateResultFromJunitXml( } runInstance.errored(node, message); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); } else if (result.failure) { failures += 1; const failure = result.failure[0]; @@ -125,23 +126,23 @@ export async function updateResultFromJunitXml( } runInstance.failed(node, message); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); } else if (result.skipped) { skipped += 1; const skip = result.skipped[0]; const text = `${rawTestCaseNode.rawId} Skipped: [${skip.$.type}]${skip.$.message}\r\n`; runInstance.skipped(node); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); } else { passed += 1; const text = `${rawTestCaseNode.rawId} Passed\r\n`; runInstance.passed(node); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); } } else { const text = `Test result not found for: ${rawTestCaseNode.rawId}\r\n`; - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); const message = new TestMessage(text); if (node.uri && node.range) { diff --git a/src/client/testing/testController/common/utils.ts b/src/client/testing/testController/common/utils.ts new file mode 100644 index 000000000000..13fc76a37199 --- /dev/null +++ b/src/client/testing/testController/common/utils.ts @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +export function fixLogLines(content: string): string { + const lines = content.split(/\r?\n/g); + return `${lines.join('\r\n')}\r\n`; +} diff --git a/src/client/testing/testController/unittest/runner.ts b/src/client/testing/testController/unittest/runner.ts index 9e053893740a..71f6dd3f57b7 100644 --- a/src/client/testing/testController/unittest/runner.ts +++ b/src/client/testing/testController/unittest/runner.ts @@ -12,6 +12,7 @@ import { ITestRunner, ITestDebugLauncher, IUnitTestSocketServer, LaunchOptions, import { TEST_OUTPUT_CHANNEL } from '../../constants'; import { getTestCaseNodes } from '../common/testItemUtilities'; import { ITestRun, ITestsRunner, TestData, TestRunInstanceOptions, TestRunOptions } from '../common/types'; +import { fixLogLines } from '../common/utils'; import { getTestRunArgs } from './arguments'; interface ITestData { @@ -102,7 +103,7 @@ export class UnittestRunner implements ITestsRunner { if (data.outcome === 'passed' || data.outcome === 'failed-expected') { const text = `${rawTestCase.rawId} Passed\r\n`; runInstance.passed(testCase); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); counts.passed += 1; } else if (data.outcome === 'failed' || data.outcome === 'passed-unexpected') { const traceback = data.traceback @@ -116,7 +117,7 @@ export class UnittestRunner implements ITestsRunner { } runInstance.failed(testCase, message); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); counts.failed += 1; if (failFast) { stopTesting = true; @@ -133,7 +134,7 @@ export class UnittestRunner implements ITestsRunner { } runInstance.errored(testCase, message); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); counts.errored += 1; if (failFast) { stopTesting = true; @@ -144,11 +145,11 @@ export class UnittestRunner implements ITestsRunner { : ''; const text = `${rawTestCase.rawId} Skipped: ${data.message}\r\n${traceback}\r\n`; runInstance.skipped(testCase); - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); counts.skipped += 1; } else { const text = `Unknown outcome type for test ${rawTestCase.rawId}: ${data.outcome}`; - runInstance.appendOutput(text); + runInstance.appendOutput(fixLogLines(text)); const message = new TestMessage(text); if (testCase.uri && testCase.range) { message.location = new Location(testCase.uri, testCase.range);