Skip to content

Commit

Permalink
master: fixed some GoogleTest cout issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed Feb 5, 2022
1 parent 2cca86a commit a60d43f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 50 deletions.
16 changes: 5 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,7 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"todo-tree.general.tags": [
"BUG",
"HACK",
"FIXME",
"TODO",
"TODO:future",
"TODO:nice",
"TODO:release",
"XXX"
],
"todo-tree.general.tags": ["BUG", "HACK", "FIXME", "TODO", "TODO:future", "TODO:nice", "TODO:release", "XXX"],
"todo-tree.highlights.customHighlight": {
"TODO:future": {
"type": "none"
Expand All @@ -136,5 +127,8 @@
"type": "tag",
"background": "yellow"
}
},
"[xml]": {
"editor.defaultFormatter": "DotJoshJohnson.xml"
}
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.0.25]

- fixed GoogleTest cout and cerr parsin [issue#329](https://github.com/matepek/vscode-catch2-test-adapter/issues/329) and [issue#323](https://github.com/matepek/vscode-catch2-test-adapter/issues/323).

## [4.0.24] - 2022-02-01

## Changed
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ export abstract class AbstractExecutable<TestT extends AbstractTest = AbstractTe
protected processStdErr(testRun: vscode.TestRun, runPrefix: string, str: string): void {
testRun.appendOutput(runPrefix + '⬇ std::cerr:\r\n');
const indented = reindentStr(0, 2, str);
testRun.appendOutput(indented.map(x => runPrefix + '> ' + x + '\r\n').join(''));
testRun.appendOutput(indented.map(x => runPrefix + x + '\r\n').join(''));
testRun.appendOutput(runPrefix + '⬆ std::cerr\r\n');
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ConfigOfExecGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
private async _createSuiteByUri(filePath: string): Promise<ExecutableFactory> {
const relPath = pathlib.relative(this._shared.workspaceFolder.uri.fsPath, filePath);

let varToValue: ResolveRuleAsync[] = [];
const varToValue: ResolveRuleAsync[] = [];

const subPath = createPythonIndexerForPathVariable;

Expand All @@ -242,7 +242,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
const baseFilename = pathlib.basename(filename, extFilename);
const relDirpath = pathlib.dirname(relPath);

varToValue = [
varToValue.push(
{ resolve: '${filename}', rule: filename }, // redundant but might faster
{ resolve: '${relDirpath}', rule: relDirpath }, // redundant but might faster
subFilename('filename', filename),
Expand All @@ -253,7 +253,7 @@ export class ConfigOfExecGroup implements vscode.Disposable {
{ resolve: '${extFilename}', rule: extFilename },
{ resolve: '${baseFilename}', rule: baseFilename },
...this._shared.varToValue,
];
);
} catch (e) {
this._shared.log.exceptionS(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/DOCExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ abstract class TagProcessorBase implements XmlTagProcessor {
} else if (processor === null) {
// known tag, do nothing
} else {
this.builder.addOutputLine(1, '> ' + dataTrimmed);
this.builder.addOutputLine(1, dataTrimmed);
}
}

Expand Down
73 changes: 43 additions & 30 deletions src/framework/GoogleTestExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,50 @@ export class GoogleTestExecutable extends AbstractExecutable<GoogleTestTest> {
const data = { lastBuilder: undefined as TestResultBuilder | undefined };
// we dont need this now: const rngSeed: number | undefined = typeof this._shared.rngSeed === 'number' ? this._shared.rngSeed : undefined;

const parser = new TextStreamParser(this.shared.log, {
async online(line: string): Promise<void | LineProcessor> {
const beginMatch = testBeginRe.exec(line);
if (beginMatch) {
const testNameAsId = beginMatch[1];
const testName = beginMatch[3];
const suiteName = beginMatch[2];
let test = executable._getTest(testNameAsId);
if (!test) {
log.info('TestCase not found in children', testNameAsId);
test = await executable._createAndAddTest(testName, suiteName, undefined, undefined, undefined, undefined);
unexpectedTests.push(test);
} else {
expectedToRunAndFoundTests.push(test);
}
data.lastBuilder = new TestResultBuilder(test, testRun, runInfo.runPrefix, false);
return new TestCaseProcessor(executable.shared, testEndRe(test.id), data.lastBuilder);
} else if (line.startsWith('[----------] Global test environment tear-down')) {
return new NoOpLineProcessor();
} else {
if (
line === '' ||
['Running main()', 'Note: Google Test filter =', '[==========]', '[----------]'].some(x =>
line.startsWith(x),
)
) {
//skip
const parser = new TextStreamParser(
this.shared.log,
{
async online(line: string): Promise<void | LineProcessor> {
const beginMatch = testBeginRe.exec(line);
if (beginMatch) {
const testNameAsId = beginMatch[1];
const testName = beginMatch[3];
const suiteName = beginMatch[2];
let test = executable._getTest(testNameAsId);
if (!test) {
log.info('TestCase not found in children', testNameAsId);
test = await executable._createAndAddTest(
testName,
suiteName,
undefined,
undefined,
undefined,
undefined,
);
unexpectedTests.push(test);
} else {
expectedToRunAndFoundTests.push(test);
}
data.lastBuilder = new TestResultBuilder(test, testRun, runInfo.runPrefix, false);
return new TestCaseProcessor(executable.shared, testEndRe(test.id), data.lastBuilder);
} else if (line.startsWith('[----------] Global test environment tear-down')) {
return new NoOpLineProcessor();
} else {
testRun.appendOutput(runInfo.runPrefix + line + '\r\n');
if (
line === '' ||
['Running main()', 'Note: Google Test filter =', '[==========]', '[----------]'].some(x =>
line.startsWith(x),
)
) {
//skip
} else {
testRun.appendOutput(runInfo.runPrefix + line + '\r\n');
}
}
}
},
},
});
false,
);

await pipeProcess2Parser(runInfo, parser, (data: string) =>
executable.processStdErr(testRun, runInfo.runPrefix, data),
Expand Down Expand Up @@ -444,6 +455,8 @@ class TestCaseProcessor implements LineProcessor {
break;
}
}

this.testCaseShared.builder.addOutputLine(1, line);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/util/TextStreamParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { debugBreak } from './DevelopmentHelper';
import { ParserInterface } from './ParserInterface';

export class TextStreamParser implements ParserInterface {
constructor(private readonly log: LoggerWrapper, rootProcessor: RootLineProcessor) {
constructor(
private readonly log: LoggerWrapper,
rootProcessor: RootLineProcessor,
private readonly handleStdErr = true,
) {
this.topProcessor = rootProcessor;
this.alwaysonlineCb = rootProcessor.alwaysonline;
}
Expand Down Expand Up @@ -52,9 +56,9 @@ export class TextStreamParser implements ParserInterface {
}
}

writeStdErr(data: string): Promise<true> {
this.write(data);
return Promise.resolve(true);
writeStdErr(data: string): Promise<boolean> {
if (this.handleStdErr) this.write(data);
return Promise.resolve(this.handleStdErr);
}

private _process(): void {
Expand Down
6 changes: 6 additions & 0 deletions test/cpp/gtest/gtest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

TEST(Std, NoOutput)
{
std::cout << "cout\n"; // (1)
std::cerr << "cerr\n"; // (2)
}

0 comments on commit a60d43f

Please sign in to comment.