Skip to content

See if splitting is causing the mismatch output issues in tests #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DiagnosticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import stripAnsi = require("strip-ansi");
import configuration from "./configuration";
import { SwiftExecution } from "./tasks/SwiftExecution";
import { WorkspaceContext } from "./WorkspaceContext";
import { checkIfBuildComplete } from "./utilities/tasks";
import { checkIfBuildComplete, lineBreakRegex } from "./utilities/tasks";

interface ParsedDiagnostic {
uri: string;
Expand Down Expand Up @@ -278,7 +278,7 @@ export class DiagnosticsManager implements vscode.Disposable {
disposables.push(
swiftExecution.onDidWrite(data => {
const sanitizedData = (remainingData || "") + stripAnsi(data);
const lines = sanitizedData.split(/\r\n|\n|\r/gm);
const lines = sanitizedData.split(lineBreakRegex);
// If ends with \n then will be "" and there's no affect.
// Otherwise want to keep remaining data to pre-pend next write
remainingData = lines.pop();
Expand Down
3 changes: 2 additions & 1 deletion src/SwiftPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { isPathInsidePath } from "./utilities/filesystem";
import { SwiftToolchain } from "./toolchain/toolchain";
import { BuildFlags } from "./toolchain/BuildFlags";
import { SwiftOutputChannel } from "./ui/SwiftOutputChannel";
import { lineBreakRegex } from "./utilities/tasks";

/** Swift Package Manager contents */
interface PackageContents {
Expand Down Expand Up @@ -313,7 +314,7 @@ export class SwiftPackage {
cwd: folder.fsPath,
});
const plugins: PackagePlugin[] = [];
const lines = stdout.split("\n").map(item => item.trim());
const lines = stdout.split(lineBreakRegex).map(item => item.trim());
for (const line of lines) {
// ‘generate-documentation’ (plugin ‘Swift-DocC’ in package ‘SwiftDocCPlugin’)
const pluginMatch = /^‘(.*)’ \(plugin ‘(.*)’ in package ‘(.*)’\)/.exec(line);
Expand Down
3 changes: 2 additions & 1 deletion src/TestExplorer/TestParsers/SwiftTestingOutputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ITestRunState } from "./TestRunState";
import { TestClass } from "../TestDiscovery";
import { sourceLocationToVSCodeLocation } from "../../utilities/utilities";
import { exec } from "child_process";
import { lineBreakRegex } from "../../utilities/tasks";

// All events produced by a swift-testing run will be one of these three types.
// Detailed information about swift-testing's JSON schema is available here:
Expand Down Expand Up @@ -235,7 +236,7 @@ export class SwiftTestingOutputParser {
* @param chunk A chunk of stdout emitted during a test run.
*/
public parseStdout(chunk: string, runState: ITestRunState) {
for (const line of chunk.split("\n")) {
for (const line of chunk.split(lineBreakRegex)) {
if (line.trim().length > 0) {
runState.recordOutput(undefined, `${line}\r\n`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/TestExplorer/TestParsers/XCTestOutputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { sourceLocationToVSCodeLocation } from "../../utilities/utilities";
import { MarkdownString, Location } from "vscode";
// eslint-disable-next-line @typescript-eslint/no-require-imports
import stripAnsi = require("strip-ansi");
import { lineBreakRegex } from "../../utilities/tasks";

/** Regex for parsing XCTest output */
interface TestRegex {
Expand Down Expand Up @@ -190,7 +191,7 @@ export class XCTestOutputParser implements IXCTestOutputParser {
// which we don't care about.
const output = process.platform === "win32" ? stripAnsi(rawOutput) : rawOutput;
const output2 = output.replace(/\r\n/g, "\n");
const lines = output2.split("\n");
const lines = output2.split(lineBreakRegex);
if (runState.excess) {
lines[0] = runState.excess + lines[0];
}
Expand Down
3 changes: 2 additions & 1 deletion src/process-list/BaseProcessList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import * as util from "util";
import * as child_process from "child_process";
import { Process, ProcessList } from ".";
import { lineBreakRegex } from "../utilities/tasks";

const exec = util.promisify(child_process.execFile);

Expand Down Expand Up @@ -46,7 +47,7 @@ export abstract class BaseProcessList implements ProcessList {
maxBuffer: 10 * 1024 * 1024, // Increase the max buffer size to 10Mb
});
const parser = this.createParser();
return (await execCommand).stdout.split("\n").flatMap(line => {
return (await execCommand).stdout.split(lineBreakRegex).flatMap(line => {
const process = parser(line.toString());
if (!process || process.id === execCommand.child.pid) {
return [];
Expand Down
6 changes: 4 additions & 2 deletions src/toolchain/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Version } from "../utilities/version";
import { BuildFlags } from "./BuildFlags";
import { Sanitizer } from "./Sanitizer";
import { SwiftlyConfig } from "./ToolchainVersion";
import { lineBreakRegex } from "../utilities/tasks";

/**
* Contents of **Info.plist** on Windows.
Expand Down Expand Up @@ -235,7 +236,8 @@ export class SwiftToolchain {
execFile("mdfind", [`kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'`]),
this.getXcodeDeveloperDir(),
]);
const spotlightXcodes = mdfindOutput.length > 0 ? mdfindOutput.trimEnd().split("\n") : [];
const spotlightXcodes =
mdfindOutput.length > 0 ? mdfindOutput.trimEnd().split(lineBreakRegex) : [];
const selectedXcode = this.getXcodeDirectory(xcodeDeveloperDir);

// Combine the results from both commands
Expand Down Expand Up @@ -933,7 +935,7 @@ export class SwiftToolchain {
}
const { stdout } = await execSwift(["--version"], { swiftExecutable });
return {
compilerVersion: stdout.split("\n", 1)[0],
compilerVersion: stdout.split(lineBreakRegex, 1)[0],
paths: { runtimeLibraryPaths: [""] },
};
} catch {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/SwiftBuildStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as vscode from "vscode";
import configuration, { ShowBuildStatusOptions } from "../configuration";
import { RunningTask, StatusItem } from "./StatusItem";
import { SwiftExecution } from "../tasks/SwiftExecution";
import { checkIfBuildComplete } from "../utilities/tasks";
import { checkIfBuildComplete, lineBreakRegex } from "../utilities/tasks";

/**
* Progress of `swift` build, parsed from the
Expand Down Expand Up @@ -121,7 +121,7 @@ export class SwiftBuildStatus implements vscode.Disposable {
// We'll process data one line at a time, in reverse order
// since the latest interesting message is all we need to
// be concerned with
const lines = sanitizedData.split(/\r\n|\n|\r/gm).reverse();
const lines = sanitizedData.split(lineBreakRegex).reverse();
for (const line of lines) {
if (checkIfBuildComplete(line)) {
update(name);
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import * as path from "path";
import * as vscode from "vscode";

export const lineBreakRegex = /\r\n|\n|\r/gm;

export function resolveTaskCwd(task: vscode.Task, cwd?: string): string | undefined {
const scopeWorkspaceFolder = getScopeWorkspaceFolder(task);
if (!cwd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { sourceLocationToVSCodeLocation } from "../../../src/utilities/utilities
import { TestXUnitParser } from "../../../src/TestExplorer/TestXUnitParser";
import { activateExtensionForSuite } from "../utilities/testutilities";
import { SwiftOutputChannel } from "../../../src/ui/SwiftOutputChannel";
import { lineBreakRegex } from "../../../src/utilities/tasks";

enum ParserTestKind {
Regular = "Regular Test Run",
Expand All @@ -33,7 +34,7 @@ enum ParserTestKind {
suite("XCTestOutputParser Suite", () => {
function inputToTestOutput(input: string) {
return input
.split("\n")
.split(lineBreakRegex)
.slice(0, -1)
.map(line => `${line}\r\n`);
}
Expand Down