Skip to content

Commit 1a742c0

Browse files
author
Mate Pek
committed
refactoring
1 parent 917b123 commit 1a742c0

File tree

6 files changed

+47
-157
lines changed

6 files changed

+47
-157
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"icon": "resources/icon.png",
66
"author": "Mate Pek",
77
"publisher": "matepek",
8-
"version": "3.7.0",
8+
"version": "3.6.28",
99
"license": "MIT",
1010
"homepage": "https://github.com/matepek/vscode-catch2-test-adapter",
1111
"repository": {
@@ -61,8 +61,7 @@
6161
"tslib": "^2.3.1",
6262
"vscode-test-adapter-api": "^1.9.0",
6363
"vscode-test-adapter-util": "^0.7.1",
64-
"xml2js": "^0.4.23",
65-
"junit-report-merger": "^2.2.3"
64+
"xml2js": "^0.4.23"
6665
},
6766
"devDependencies": {
6867
"@sentry/node": "^6.11.0",

src/ExecutableConfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { RootSuite } from './RootSuite';
1919
import { readJSONSync } from 'fs-extra';
2020
import { Spawner, DefaultSpawner, SpawnWithExecutor } from './Spawner';
2121
import { RunTask, ExecutionWrapper, FrameworkSpecific } from './AdvancedExecutableInterface';
22-
import { isWin } from '../test/Common';
2322
import { LoggerWrapper } from './LoggerWrapper';
2423

2524
///
@@ -577,7 +576,7 @@ export class ExecutableConfig implements vscode.Disposable {
577576
}
578577

579578
function checkEnvForPath(env: Record<string, string>, log: LoggerWrapper): void {
580-
if (isWin) {
579+
if (process.platform == 'win32') {
581580
checkPathVariance('PATH', env, log);
582581
checkPathVariance('Path', env, log);
583582
checkPathVariance('path', env, log);

src/RunnableFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class RunnableFactory {
164164
const cpputest = runWithHelpRes.stdout.match(
165165
this._cpputest.helpRegex
166166
? new RegExp(this._cpputest.helpRegex, regexFlags)
167-
: /[-g|sg|xg|xsg groupName]... [-n|sn|xn|xsn testName].../,
167+
: /\[-g\|sg\|xg\|xsg groupName\]\.\.\. \[-n\|sn\|xn\|xsn testName\]\.\.\. \[-t groupName\.testName\]\.\.\./,
168168
);
169169
if (cpputest) {
170170
return new CppUTestRunnable(

src/framework/CppUTestRunnable.ts

Lines changed: 18 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import * as fs from 'fs-extra';
2-
import { inspect } from 'util';
3-
import { mergeFiles } from 'junit-report-merger';
1+
import * as fs from 'fs';
2+
import { inspect, promisify } from 'util';
43
import { Suite } from '../Suite';
54
import { AbstractRunnable, RunnableReloadResult } from '../AbstractRunnable';
65
import { CppUTestTest } from './CppUTestTest';
7-
import { Parser } from 'xml2js';
86
import { RunnableProperties } from '../RunnableProperties';
97
import { SharedVariables } from '../SharedVariables';
108
import { RunningRunnable, ProcessResult } from '../RunningRunnable';
@@ -28,67 +26,11 @@ export class CppUTestRunnable extends AbstractRunnable {
2826
return this.properties.testGrouping;
2927
} else {
3028
const grouping = { groupByExecutable: this._getGroupByExecutable() };
29+
grouping.groupByExecutable.groupByTags = { tags: [], tagFormat: '${tag}' };
3130
return grouping;
3231
}
3332
}
3433

35-
private async _reloadFromXml(xmlStr: string, cancellationFlag: CancellationFlag): Promise<RunnableReloadResult> {
36-
const testGrouping = this.getTestGrouping();
37-
38-
interface XmlObject {
39-
[prop: string]: any; //eslint-disable-line
40-
}
41-
42-
let xml: XmlObject = {};
43-
44-
new Parser({ explicitArray: true }).parseString(xmlStr, (err: Error, result: Record<string, unknown>) => {
45-
if (err) {
46-
throw err;
47-
} else {
48-
xml = result;
49-
}
50-
});
51-
52-
const reloadResult = new RunnableReloadResult();
53-
54-
const processTestcases = async (testsuite: any, reloadResult: RunnableReloadResult) => {
55-
const suiteName = testsuite.$.name;
56-
for (let i = 0; i < testsuite.testcase.length; i++) {
57-
if (cancellationFlag.isCancellationRequested) return;
58-
59-
const testCase = testsuite.testcase[i];
60-
const testName = testCase.$.name.startsWith('DISABLED_') ? testCase.$.name.substr(9) : testCase.$.name;
61-
const testNameAsId = suiteName + '.' + testCase.$.name;
62-
63-
const file = testCase.$.file ? await this._resolveSourceFilePath(testCase.$.file) : undefined;
64-
const line = testCase.$.line ? testCase.$.line - 1 : undefined;
65-
66-
reloadResult.add(
67-
...(await this._createSubtreeAndAddTest(
68-
testGrouping,
69-
testNameAsId,
70-
testName,
71-
file,
72-
[suiteName],
73-
(parent: Suite) => new CppUTestTest(this._shared, this, parent, testNameAsId, testName, file, line),
74-
(old: AbstractTest) => (old as CppUTestTest).update(testNameAsId, file, line),
75-
)),
76-
);
77-
}
78-
};
79-
80-
if (xml.testsuites !== undefined) {
81-
for (let i = 0; i < xml.testsuites.testsuite.length; ++i) {
82-
await processTestcases(xml.testsuites.testsuite[i], reloadResult)
83-
.catch((err) => this._shared.log.info('Error', err));
84-
}
85-
} else {
86-
await processTestcases(xml.testsuite, reloadResult);
87-
}
88-
89-
return reloadResult;
90-
}
91-
9234
private async _reloadFromString(
9335
stdOutStr: string,
9436
cancellationFlag: CancellationFlag,
@@ -120,18 +62,18 @@ export class CppUTestRunnable extends AbstractRunnable {
12062
}
12163

12264
protected async _reloadChildren(cancellationFlag: CancellationFlag): Promise<RunnableReloadResult> {
123-
const cacheFile = this.properties.path + '.TestMate.testListCache.xml';
65+
const cacheFile = this.properties.path + '.TestMate.testListCache.txt';
12466

12567
if (this._shared.enabledTestListCaching) {
12668
try {
127-
const cacheStat = await fs.stat(cacheFile);
128-
const execStat = await fs.stat(this.properties.path);
69+
const cacheStat = await promisify(fs.stat)(cacheFile);
70+
const execStat = await promisify(fs.stat)(this.properties.path);
12971

13072
if (cacheStat.size > 0 && cacheStat.mtime > execStat.mtime) {
13173
this._shared.log.info('loading from cache: ', cacheFile);
132-
const xmlStr = await fs.readFile(cacheFile, 'utf8');
74+
const str = await promisify(fs.readFile)(cacheFile, 'utf8');
13375

134-
return await this._reloadFromXml(xmlStr, cancellationFlag);
76+
return await this._reloadFromString(str, cancellationFlag);
13577
}
13678
} catch (e) {
13779
this._shared.log.info('coudnt use cache', e);
@@ -149,47 +91,23 @@ export class CppUTestRunnable extends AbstractRunnable {
14991
);
15092

15193
if (cppUTestListOutput.stderr && !this.properties.ignoreTestEnumerationStdErr) {
152-
this._shared.log.warn('reloadChildren -> cppUTestListOutput.stderr: ', cppUTestListOutput);
94+
this._shared.log.warn('reloadChildren -> googleTestListOutput.stderr: ', cppUTestListOutput);
15395
return await this._createAndAddUnexpectedStdError(cppUTestListOutput.stdout, cppUTestListOutput.stderr);
15496
}
15597

156-
if (cppUTestListOutput.stdout.length === 0) {
157-
this._shared.log.debug(cppUTestListOutput);
158-
throw Error('stoud is empty');
159-
}
160-
161-
const result = this._reloadFromString(cppUTestListOutput.stdout, cancellationFlag);
98+
const result = await this._reloadFromString(cppUTestListOutput.stdout, cancellationFlag);
16299

163100
if (this._shared.enabledTestListCaching) {
164-
//Generate xmls folder
165-
const junitXmlsFolderPath = this.properties.path + '_junit_xmls';
166-
fs.mkdir(junitXmlsFolderPath)
167-
.then(() => this._shared.log.info('junit-xmls folder created', junitXmlsFolderPath))
168-
.catch(err => this._shared.log.error('error creating xmls folder: ', junitXmlsFolderPath, err));
169-
//Generate xml files
170-
const args = this.properties.prependTestListingArgs.concat(['-ojunit']);
171-
const options = { cwd: junitXmlsFolderPath };
172-
await this.properties.spawner
173-
.spawnAsync(this.properties.path, args, options, 30000)
174-
.then(() => this._shared.log.info('create cpputest xmls', this.properties.path, args, options.cwd));
175-
//Merge xmls into single xml
176-
fs.readdir(junitXmlsFolderPath, (err, files) => {
177-
if (files.length > 1) {
178-
mergeFiles(cacheFile, [junitXmlsFolderPath + '/*.xml'])
179-
.then(() => this._shared.log.info('cache xml written', cacheFile))
180-
.catch(err => this._shared.log.warn('combine xml cache file could not create: ', cacheFile, err));
181-
} else {
182-
fs.copyFile(junitXmlsFolderPath + '/' + files[0], cacheFile);
183-
}
184-
});
185-
//Delete xmls folder
186-
fs.remove(junitXmlsFolderPath)
187-
.then(() => this._shared.log.info('junit-xmls folder deleted', junitXmlsFolderPath))
188-
.catch(err => this._shared.log.error('error deleting xmls folder: ', junitXmlsFolderPath, err));
101+
promisify(fs.writeFile)(cacheFile, cppUTestListOutput.stdout).catch(err =>
102+
this._shared.log.warn('couldnt write cache file:', err),
103+
);
189104
}
105+
190106
return result;
191107
}
192108

109+
//TODO:matepek: reviewed until this
110+
193111
protected _getRunParamsInner(childrenToRun: readonly Readonly<AbstractTest>[]): string[] {
194112
// TODO: Add multiple options
195113
const execParams: string[] = [];
@@ -201,7 +119,7 @@ export class CppUTestRunnable extends AbstractRunnable {
201119
return execParams;
202120
}
203121

204-
protected _getDebugParamsInner(childrenToRun: readonly Readonly<AbstractTest>[], breakOnFailure: boolean): string[] {
122+
protected _getDebugParamsInner(childrenToRun: readonly Readonly<AbstractTest>[], _breakOnFailure: boolean): string[] {
205123
// TODO: Proper debug options
206124
// TODO: colouring 'debug.enableOutputColouring'
207125
// TODO: Add multiple options
@@ -333,7 +251,7 @@ export class CppUTestRunnable extends AbstractRunnable {
333251
} else {
334252
if (code !== null && code !== undefined) resolve(ProcessResult.createFromErrorCode(code));
335253
else if (signal !== null && signal !== undefined) resolve(ProcessResult.createFromSignal(signal));
336-
else resolve(ProcessResult.error('unknown sfngvdlfkxdvgn'));
254+
else resolve(ProcessResult.error('unknown sgrstbdfg'));
337255
}
338256
});
339257
})

test/cpp/cpputest/cpputest1.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,40 @@ TEST_GROUP(FirstTestGroup)
1414

1515
TEST(FirstTestGroup, FirstTest)
1616
{
17-
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
17+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
1818
}
1919

2020
TEST(FirstTestGroup, SecondTest)
2121
{
22-
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
22+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
2323
CHECK(false);
2424
}
2525

2626
TEST(FirstTestGroup, ThirdTest)
2727
{
28-
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
28+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
29+
//FAIL("Fail me!");
30+
}
31+
32+
33+
TEST_GROUP(SecondTestGroupt)
34+
{
35+
};
36+
37+
TEST(SecondTestGroupt, FirstTest)
38+
{
39+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
40+
}
41+
42+
TEST(SecondTestGroupt, SecondTest)
43+
{
44+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
45+
CHECK(false);
46+
}
47+
48+
TEST(SecondTestGroupt, ThirdTest)
49+
{
50+
//std::this_thread::sleep_for(std::chrono::milliseconds(2000));
2951
//FAIL("Fail me!");
3052
}
3153

test/framework/CppUTestRunnable.test.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { CppUTestRunnable } from '../../src/framework/CppUTestRunnable';
55
import { RootSuite } from '../../src/RootSuite';
66
import { RunnableProperties } from '../../src/RunnableProperties';
77
import { DefaultSpawner } from '../../src/Spawner';
8-
import { EOL } from 'os';
98

109
///
1110

@@ -166,51 +165,4 @@ describe(pathlib.basename(__filename), function () {
166165
}
167166
});
168167
});
169-
170-
context('Testing _reloadFromXml', function () {
171-
it('should reload ex.1', async function () {
172-
const { root, runnable } = createCppUTestRunnable();
173-
174-
const testOutput: string[] = [
175-
'<?xml version="1.0" encoding="UTF-8" ?>',
176-
'<testsuite errors="0" failures="0" hostname="localhost" name="FirstTestGroup" tests="2" time="4.002" timestamp="2021-08-26T16:19:26">',
177-
'<properties>',
178-
'</properties>',
179-
'<testcase classname="FirstTestGroup" name="SecondTest" assertions="0" time="2.001" file="/mnt/c/Users/testcppcpputestcpputest1.cpp" line="20">',
180-
'</testcase>',
181-
'<testcase classname="FirstTestGroup" name="FirstTest" assertions="0" time="2.001" file="/mnt/c/Users/testcppcpputestcpputest1.cpp" line="15">',
182-
'</testcase>',
183-
'<system-out></system-out>',
184-
'<system-err></system-err>',
185-
'</testsuite>,',
186-
];
187-
const res = await runnable['_reloadFromXml'](testOutput.join(EOL), { isCancellationRequested: false });
188-
189-
const tests = [...res.tests].sort((a, b) => a.testNameAsId.localeCompare(b.testNameAsId));
190-
191-
assert.strictEqual(tests.length, 2);
192-
193-
assert.strictEqual(tests[0].testNameAsId, 'FirstTestGroup.FirstTest');
194-
assert.strictEqual(tests[0].label, 'FirstTest');
195-
assert.strictEqual(tests[0].file, pathlib.normalize('/mnt/c/Users/testcppcpputestcpputest1.cpp'));
196-
assert.strictEqual(tests[0].line, 14);
197-
assert.strictEqual(tests[0].skipped, false);
198-
assert.strictEqual(tests[0].getStaticEvent('1'), undefined);
199-
assert.strictEqual(tests[1].testNameAsId, 'FirstTestGroup.SecondTest');
200-
assert.strictEqual(tests[1].label, 'SecondTest');
201-
assert.strictEqual(tests[1].file, pathlib.normalize('/mnt/c/Users/testcppcpputestcpputest1.cpp'));
202-
assert.strictEqual(tests[1].line, 19);
203-
assert.strictEqual(tests[1].skipped, false);
204-
assert.strictEqual(tests[1].getStaticEvent('1'), undefined);
205-
206-
assert.strictEqual(root.children.length, 1);
207-
const suite1 = root.children[0];
208-
assert.strictEqual(suite1.label, 'name');
209-
if (suite1.type === 'suite') {
210-
assert.strictEqual(suite1.children.length, 2);
211-
} else {
212-
assert.strictEqual(suite1.type, 'suite');
213-
}
214-
});
215-
});
216168
});

0 commit comments

Comments
 (0)