Skip to content

Commit

Permalink
More debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
plemarquand committed Feb 11, 2025
1 parent 83901a4 commit 397da73
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
52 changes: 50 additions & 2 deletions src/TestExplorer/TestParsers/XCTestOutputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { MarkdownString, Location } from "vscode";
// eslint-disable-next-line @typescript-eslint/no-require-imports
import stripAnsi = require("strip-ansi");

/* eslint-disable no-console */

/** Regex for parsing XCTest output */
interface TestRegex {
started: RegExp;
Expand Down Expand Up @@ -151,25 +153,38 @@ export class XCTestOutputParser implements IXCTestOutputParser {
* @param output Output from `swift test`
*/
public parseResult(rawOutput: string, runState: ITestRunState) {
console.log("RAW XCTEST OUTPUT:", rawOutput.split("\n").join("\n>>>> "));
console.log(
">>>>>>>>>>>>>>>> RAW XCTEST OUTPUT >>>>>>>>>>>>>>>>>>> :\n" +
rawOutput.split("\n").join("\n")
);
console.log(">>>>>>>>>>>>>>>> RAW XCTEST OUTPUT COMPLETE >>>>>>>>>>>>>>>>>>>");
const annotated = rawOutput.replaceAll("\n", "❌\n").replaceAll("\r", "🐀\r");
console.log(">>>>>>>>>>>>>>>> ANNOTATED XCTEST OUTPUT >>>>>>>>>>>>>>>>>>> :\n" + annotated);
console.log(">>>>>>>>>>>>>>>> ANNOTATED XCTEST OUTPUT COMPLETE >>>>>>>>>>>>>>>>>>>");

// Windows is inserting ANSI codes into the output to do things like clear the cursor,
// 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");
console.log(">>> Run State Excess |" + runState.excess + "|");
if (runState.excess) {
console.log(">>> !Had Excess from previous output |" + runState.excess + "|");
lines[0] = runState.excess + lines[0];
console.log(">>> !New line[0] is now |" + lines[0] + "|");
}
// pop empty string off the end of the lines array
if (lines.length > 0 && lines[lines.length - 1] === "") {
console.log(">>> Trimming last line");
lines.pop();
}
// if submitted text does not end with a newline then pop that off and store in excess
// for next call of parseResult
if (output2[output2.length - 1] !== "\n") {
runState.excess = lines.pop();
console.log(">>> Saving Excess |" + runState.excess + "|");
} else {
console.log(">>> Unsetting Excess");
runState.excess = undefined;
}

Expand All @@ -181,6 +196,7 @@ export class XCTestOutputParser implements IXCTestOutputParser {
// occur in another target, so we revert to just searching for class and function name if
// the above method is unsuccessful.
for (const line of lines) {
console.log(">>> Process Line: |" + line + "|");
// Regex "Test Case '-[<test target> <class.function>]' started"
const startedMatch = this.regex.started.exec(line);
if (startedMatch) {
Expand All @@ -203,6 +219,16 @@ export class XCTestOutputParser implements IXCTestOutputParser {
const testIndex = runState.getTestItemIndex(testName, undefined);
const state = finishedMatch[3] as TestCompletionState;
const duration = +finishedMatch[4];
console.log(
"!!! >>>>> !!!! FINISHED MATCH ON LINE:",
line,
"...STATE IS",
state,
"... TEST INDEX IS",
testIndex,
"... FAILED TEST IS",
runState.failedTest
);
switch (state) {
case TestCompletionState.failed:
this.failTest(testIndex, { duration }, runState);
Expand All @@ -223,6 +249,12 @@ export class XCTestOutputParser implements IXCTestOutputParser {
if (errorMatch) {
const testName = `${errorMatch[3]}/${errorMatch[4]}`;
const failedTestIndex = runState.getTestItemIndex(testName, errorMatch[1]);
console.log(
">>> ERROR MATCH ON LINE:",
line,
"...FAILED TEST INDEX IS",
failedTestIndex
);
this.startErrorMessage(
failedTestIndex,
errorMatch[5],
Expand Down Expand Up @@ -342,6 +374,7 @@ export class XCTestOutputParser implements IXCTestOutputParser {
private startTest(testIndex: number, runState: ITestRunState) {
runState.started(testIndex);
// clear error state
console.log(">>>>> startTest resetting failed test", testIndex);
runState.failedTest = undefined;
}

Expand All @@ -352,6 +385,7 @@ export class XCTestOutputParser implements IXCTestOutputParser {
runState: ITestRunState
) {
runState.completed(testIndex, timing);
console.log(">>>>> passTest resetting failed test", testIndex);
runState.failedTest = undefined;
}

Expand All @@ -363,6 +397,14 @@ export class XCTestOutputParser implements IXCTestOutputParser {
lineNumber: string,
runState: ITestRunState
) {
console.log(
"!!! >>>>> !! START ERROR MESSAGE",
testIndex,
message,
file,
lineNumber,
!!runState.failedTest
);
// If we were already capturing an error record it and start a new one
if (runState.failedTest) {
const location = sourceLocationToVSCodeLocation(
Expand All @@ -379,6 +421,7 @@ export class XCTestOutputParser implements IXCTestOutputParser {
lineNumber: parseInt(lineNumber),
complete: false,
};
console.log(">>>>>>> SET FAILED TEST TO", runState.failedTest);
}

/** continue capturing error message */
Expand Down Expand Up @@ -407,16 +450,21 @@ export class XCTestOutputParser implements IXCTestOutputParser {
const diff = this.extractDiff(message);
runState.recordIssue(testIndex, message, false, location, diff);
} else {
console.log(">>>>>>>>>> MARKED FAILED TEST WITH NO ATTACHED FAILED TEST >>>>>>>>>>>>>");
console.log(
`>>>>>>>>>> MARKED FAILED TEST WITH NO ATTACHED FAILED TEST ${testIndex} >>>>>>>>>>>>>`
);
runState.recordIssue(testIndex, "Failed", false);
}
runState.completed(testIndex, timing);

console.log(">>>>> failTest resetting failed test", testIndex);
runState.failedTest = undefined;
}

/** Flag we have skipped a test */
private skipTest(testIndex: number, runState: ITestRunState) {
runState.skipped(testIndex);
console.log(">>>>> skipTest resetting failed test", testIndex);
runState.failedTest = undefined;
}

Expand Down
5 changes: 4 additions & 1 deletion src/TestExplorer/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,10 @@ class NonDarwinTestItemFinder implements TestItemFinder {
* Store state of current test run output parse
*/
export class TestRunnerTestRunState implements ITestRunState {
constructor(private testRun: TestRunProxy) {}
constructor(private testRun: TestRunProxy) {
// eslint-disable-next-line no-console
console.log(">>>>>> CREATED TestRunnerTestRunState");
}

public currentTestItem?: vscode.TestItem;
public lastTestItem?: vscode.TestItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ suite("Test Explorer Suite", function () {
});
});

test(`Runs failing test (${runProfile})`, async function () {
test(`swift-testing Runs failing test (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand All @@ -582,7 +582,7 @@ suite("Test Explorer Suite", function () {
});
});

test(`Runs Suite (${runProfile})`, async function () {
test(`swift-testing Runs Suite (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand All @@ -607,7 +607,7 @@ suite("Test Explorer Suite", function () {
});
});

test(`Runs parameterized test (${runProfile})`, async function () {
test(`swift-testing Runs parameterized test (${runProfile})`, async function () {
const testId = "PackageTests.parameterizedTest(_:)";
const testRun = await runTest(testExplorer, runProfile, testId);

Expand Down Expand Up @@ -657,7 +657,7 @@ suite("Test Explorer Suite", function () {
assert.deepEqual(unrunnableChildren, [true, true, true]);
});

test(`Runs Suite (${runProfile})`, async function () {
test(`swift-testing Runs Suite (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand All @@ -682,7 +682,7 @@ suite("Test Explorer Suite", function () {
});
});

test(`Runs All (${runProfile})`, async function () {
test(`swift-testing Runs All (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand Down Expand Up @@ -721,7 +721,7 @@ suite("Test Explorer Suite", function () {
});

suite(`XCTests (${runProfile})`, () => {
test("Runs passing test", async function () {
test(`XCTest Runs passing test (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand All @@ -736,7 +736,7 @@ suite("Test Explorer Suite", function () {
});
});

test("Runs failing test", async function () {
test(`XCTest Runs failing test (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand All @@ -757,7 +757,7 @@ suite("Test Explorer Suite", function () {
});
});

test("Runs Suite", async function () {
test(`XCTest Runs Suite (${runProfile})`, async function () {
const testRun = await runTest(
testExplorer,
runProfile,
Expand Down

0 comments on commit 397da73

Please sign in to comment.