@iamsergio/qttest-utils 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/example.js CHANGED
@@ -30,6 +30,9 @@ function example() {
30
30
  process.exit(1);
31
31
  }
32
32
  let qt = new qttest_1.QtTests();
33
+ qt.setLogFunction((message) => {
34
+ console.log(message);
35
+ });
33
36
  // Gather all tests that would be executed by CTest:
34
37
  yield qt.discoverViaCMake(buildDirPath);
35
38
  // Filter-out the ones that don't link to QtTest (doctests and such)
package/out/qttest.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ type LoggerFunction = (arg: string) => void;
1
2
  /**
2
3
  * Represents a single QtTest executable.
3
4
  * Supports listing the individual test slots
@@ -61,6 +62,7 @@ export declare class QtTests {
61
62
  qtTestExecutables: QtTest[];
62
63
  discoverViaCMake(buildDirPath: string): Promise<void>;
63
64
  removeNonLinking(): Promise<void>;
65
+ setLogFunction(func: LoggerFunction): void;
64
66
  removeByRunningHelp(): Promise<void>;
65
67
  removeMatching(regex: RegExp): void;
66
68
  maintainMatching(regex: RegExp): void;
@@ -72,3 +74,4 @@ export interface TestFailure {
72
74
  filePath: string;
73
75
  lineNumber: number;
74
76
  }
77
+ export {};
package/out/qttest.js CHANGED
@@ -43,6 +43,12 @@ const child_process_1 = require("child_process");
43
43
  const path_1 = __importDefault(require("path"));
44
44
  const fs = __importStar(require("fs"));
45
45
  const cmake_1 = require("./cmake");
46
+ var gLogFunction;
47
+ function logMessage(message) {
48
+ if (gLogFunction) {
49
+ gLogFunction(message);
50
+ }
51
+ }
46
52
  /**
47
53
  * Represents a single QtTest executable.
48
54
  * Supports listing the individual test slots
@@ -187,6 +193,7 @@ class QtTest {
187
193
  args = args.concat("-o").concat(this.txtOutputFileName(slot) + ",txt");
188
194
  return yield new Promise((resolve, reject) => {
189
195
  let cwdDir = cwd.length > 0 ? cwd : this.buildDirPath;
196
+ logMessage("Running " + this.filename + " " + args.join(" ") + " with cwd=" + cwdDir);
190
197
  const child = (0, child_process_1.spawn)(this.filename, args, { cwd: cwdDir });
191
198
  child.on("exit", (code) => __awaiter(this, void 0, void 0, function* () {
192
199
  /// We can code even be null ?
@@ -234,7 +241,7 @@ class QtTest {
234
241
  var failures = yield new Promise((resolve, reject) => {
235
242
  fs.readFile(tapFileName, "utf8", (error, data) => {
236
243
  if (error) {
237
- console.log("Failed to read log file");
244
+ logMessage("ERROR: Failed to read log file");
238
245
  reject(error);
239
246
  }
240
247
  else {
@@ -261,7 +268,7 @@ class QtTest {
261
268
  failedSlot.lastTestFailure = failure;
262
269
  }
263
270
  else {
264
- console.log("Failed to find slot with name " + failure.name);
271
+ logMessage("ERROR: Failed to find slot with name " + failure.name);
265
272
  }
266
273
  }
267
274
  });
@@ -310,7 +317,7 @@ class QtTests {
310
317
  }
311
318
  }
312
319
  else {
313
- console.error("Failed to retrieve ctests!");
320
+ logMessage("ERROR: Failed to retrieve ctests!");
314
321
  }
315
322
  });
316
323
  }
@@ -334,6 +341,9 @@ class QtTests {
334
341
  }
335
342
  });
336
343
  }
344
+ setLogFunction(func) {
345
+ gLogFunction = func;
346
+ }
337
347
  removeByRunningHelp() {
338
348
  return __awaiter(this, void 0, void 0, function* () {
339
349
  this.qtTestExecutables = this.qtTestExecutables.filter((ex) => __awaiter(this, void 0, void 0, function* () { return yield ex.isQtTestViaHelp(); }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "API for listing QtTest executables from a build directory and which individual test slots each executable contains. Useful for a Text Explorer VSCode extension.",
5
5
  "repository": {
6
6
  "type": "git",
package/a DELETED
@@ -1,8 +0,0 @@
1
- const pattern = /at:\s+(.+?)::(.+?)\s+\((.+?):(\d+)\)/gm;
2
- const matches = Array.from(data.matchAll(pattern));
3
- const failingTests = matches.map(match => ({
4
- name: match[2],
5
- filePath: match[3],
6
- lineNumber: parseInt(match[4]),
7
- }));
8
- resolve(failingTests);
@@ -1,11 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- },
6
- {
7
- "path": "../vscode-extension-kdab-qttest/"
8
- }
9
- ],
10
- "settings": {}
11
- }
package/foo DELETED
@@ -1,15 +0,0 @@
1
- TAP version 13
2
- # MyTest
3
- ok 1 - initTestCase()
4
- not ok 2 - testF()
5
- ---
6
- # failed
7
- at: MyTest::testF() (/data/sources/vscode-test-extension/qttest-utils/test/qt_test/test2.cpp:13)
8
- file: /data/sources/vscode-test-extension/qttest-utils/test/qt_test/test2.cpp
9
- line: 13
10
- ...
11
- ok 3 - cleanupTestCase()
12
- 1..3
13
- # tests 3
14
- # pass 2
15
- # fail 1
package/src/cmake.ts DELETED
@@ -1,87 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- // Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- import { spawn } from "child_process";
6
- import path from "path";
7
-
8
- /**
9
- * Represents tests added in cmake (Via add_test())
10
- *
11
- * Contains methods to discover Qt Tests via CMake
12
- */
13
- export class CMakeTests {
14
- // The build dir where we'll run
15
- readonly buildDirPath: string;
16
-
17
- constructor(buildDirPath: string) {
18
- this.buildDirPath = buildDirPath;
19
- }
20
-
21
- /**
22
- * Invokes ctest.exe --show-only=json-v1
23
- *
24
- * @returns a promise with the list of tests
25
- */
26
- public async tests(): Promise<CMakeTest[] | undefined> {
27
-
28
- // TODO: Check if folder exists
29
- if (this.buildDirPath.length == 0) {
30
- console.error("Could not find out cmake build dir");
31
- return undefined;
32
- }
33
-
34
- return new Promise((resolve, reject) => {
35
- const child = spawn("ctest", ["--show-only=json-v1"], { "cwd": this.buildDirPath });
36
- let output = "";
37
- child.stdout.on("data", (chunk) => {
38
- output += chunk.toString();
39
- });
40
-
41
- child.on("exit", (code) => {
42
- if (code === 0) {
43
- resolve(this.ctestJsonToList(output));
44
- } else {
45
- reject(new Error("Failed to run ctest"));
46
- }
47
- });
48
-
49
- return undefined;
50
- });
51
- }
52
-
53
- private ctestJsonToList(json: string): CMakeTest[] {
54
-
55
- let allJSON = JSON.parse(json);
56
-
57
- if (!("tests" in allJSON)) { return []; }
58
-
59
- let tests: CMakeTest[] = allJSON.tests.map((testJSON: any) => {
60
- let test = new CMakeTest();
61
- test.command = testJSON.command;
62
- test.cwd = testJSON.cwd;
63
- return test;
64
- });
65
-
66
- return tests;
67
- }
68
- }
69
-
70
-
71
- /// Represents an inividual CTest test
72
- export class CMakeTest {
73
- public command: string[] = [];
74
- public cwd: string = "";
75
-
76
- public id(): string {
77
- return this.command.join(",");
78
- }
79
-
80
- public label(): string {
81
- return path.basename(this.executablePath());
82
- }
83
-
84
- public executablePath(): string {
85
- return this.command[0];
86
- }
87
- }
package/src/example.ts DELETED
@@ -1,74 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- // Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- import { CMakeTests, CMakeTest } from "./cmake";
6
- import { QtTest, QtTests } from "./qttest";
7
- import fs from 'fs';
8
- import { exec } from "child_process";
9
-
10
- async function example() {
11
- const args = process.argv.slice(2)
12
- if (args.length != 1) {
13
- console.error("ERROR: Expected a single argument with the build-dir with cmake tests!");
14
- process.exit(2);
15
- }
16
-
17
- let buildDirPath = args[0];
18
-
19
- if (!fs.existsSync(buildDirPath)) {
20
- console.error('Directory does not exist!');
21
- process.exit(1);
22
- }
23
-
24
- let qt = new QtTests();
25
-
26
- // Gather all tests that would be executed by CTest:
27
- await qt.discoverViaCMake(buildDirPath);
28
-
29
- // Filter-out the ones that don't link to QtTest (doctests and such)
30
- await qt.removeNonLinking();
31
-
32
- // Example of filtering out by regexp:
33
- qt.removeMatching(/(tst_view|tst_window)/);
34
-
35
- // Uncomment to see example of filtering out by regexp (inverted):
36
- // qt.maintainMatching(/(tst_docks|tst_qtwidgets|tst_multisplitter)/);
37
-
38
- qt.dumpExecutablePaths();
39
- await qt.dumpTestSlots();
40
-
41
- console.log("\nRunning tests...");
42
- for (var executable of qt.qtTestExecutables) {
43
- await executable.runTest();
44
- if (executable.lastExitCode === 0)
45
- console.log(" PASS: " + executable.filename);
46
- else
47
- console.log(" FAIL: " + executable.filename + "; code=" + executable.lastExitCode);
48
- for (let slot of executable.slots!) {
49
- if (slot.lastTestFailure) {
50
- console.log(" failed slot=" + slot.name + "; path=" + slot.lastTestFailure.filePath + "; line=" + slot.lastTestFailure.lineNumber);
51
- }
52
- }
53
- }
54
-
55
- // Also run individual slots, just for example purposes:
56
-
57
- console.log("\nRunning single tests...");
58
- let slot = qt.qtTestExecutables[1].slots![0];
59
- await slot.runTest();
60
- if (slot.lastTestFailure)
61
- console.log(" FAIL:" + JSON.stringify(slot.lastTestFailure));
62
- else
63
- console.log(" PASS:");
64
-
65
- let slot2 = qt.qtTestExecutables[1].slots![2];
66
- await slot2.runTest();
67
- if (slot2.lastTestFailure)
68
- console.log(" FAIL:" + JSON.stringify(slot2.lastTestFailure));
69
- else
70
- console.log(" PASS");
71
-
72
- }
73
-
74
- example();
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- // Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- import { CMakeTests, CMakeTest } from "./cmake";
6
- import { QtTests, QtTest, QtTestSlot } from "./qttest";
7
-
8
- const qttest = {
9
- QtTests, QtTest, QtTestSlot, CMakeTests, CMakeTest
10
- };
11
-
12
- export default qttest;
package/src/qttest.ts DELETED
@@ -1,378 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- // Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- import { spawn } from "child_process";
6
- import path from "path";
7
- import * as fs from 'fs';
8
- import { CMakeTests } from "./cmake";
9
-
10
- /**
11
- * Represents a single QtTest executable.
12
- * Supports listing the individual test slots
13
- */
14
- export class QtTest {
15
- readonly filename: string;
16
- readonly buildDirPath: string;
17
-
18
- /// Allows vscode extensions to associate with a test item
19
- vscodeTestItem: any | undefined;
20
-
21
- /// The list of individual runnable test slots
22
- slots: QtTestSlot[] | null = null;
23
-
24
- /// Set after running
25
- lastExitCode: number = 0;
26
-
27
- constructor(filename: string, buildDirPath: string) {
28
- this.filename = filename;
29
- this.buildDirPath = buildDirPath;
30
- }
31
-
32
- public get id() {
33
- return this.filename;
34
- }
35
-
36
- public get label() {
37
- return path.basename(this.filename);
38
- }
39
-
40
- /**
41
- * Calls "./yourqttest -functions" and stores the results in the slots property.
42
- */
43
- public async parseAvailableSlots(): Promise<void> {
44
- let slotNames: string[] = [];
45
- let output = "";
46
- let err = "";
47
-
48
- await new Promise((resolve, reject) => {
49
- if (!fs.existsSync(this.filename)) {
50
- reject(new Error("File doesn't exit: " + this.filename));
51
- return;
52
- }
53
-
54
- const child = spawn(this.filename, ["-functions"], { cwd: this.buildDirPath });
55
-
56
- child.stdout.on("data", (chunk) => {
57
- output += chunk.toString();
58
- });
59
-
60
- child.stderr.on("data", (chunk) => {
61
- err += chunk.toString();
62
- });
63
-
64
- child.on("exit", (code) => {
65
- if (code === 0) {
66
- slotNames = slotNames.concat(output.split("\n"));
67
- slotNames = slotNames.map(entry => entry.trim().replace("()", ""));
68
- slotNames = slotNames.filter(entry => entry.length > 0);
69
-
70
- if (slotNames.length > 0) {
71
- this.slots = [];
72
- for (var slotName of slotNames) {
73
- var slot = new QtTestSlot(slotName, this);
74
- this.slots.push(slot);
75
- }
76
- }
77
-
78
- resolve(slotNames);
79
- } else {
80
- reject(new Error("Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
81
- }
82
- });
83
- });
84
- }
85
-
86
- /**
87
- * Returns whether this executable links to libQtTest.so.
88
- *
89
- * Useful for Qt autodetection, as some tests are doctest or so.
90
- *
91
- * Only implemented for Linux. Returns undefined on other platforms.
92
- */
93
- public linksToQtTestLib(): Promise<boolean> | undefined {
94
-
95
- let isLinux = process.platform === "linux";
96
- if (!isLinux) { return undefined; }
97
-
98
- return new Promise((resolve, reject) => {
99
- const child = spawn("ldd", [this.filename]);
100
- let output = "";
101
- let result = false;
102
- child.stdout.on("data", (chunk) => {
103
- if (!result) {
104
- if (chunk.toString().includes("libQt5Test.so") || chunk.toString().includes("libQt6Test.so")) {
105
- result = true;
106
- }
107
- }
108
- });
109
-
110
- child.on("exit", (code) => {
111
- if (code === 0) {
112
- resolve(result);
113
- } else {
114
- reject(new Error("Failed to run ldd"));
115
- }
116
- });
117
- });
118
- }
119
-
120
- /// Returns whether this test is a QtTest by running it with -help and checking if the help text looks familiar
121
- /// Note that if this is not a QtTest it might not run help and instead execute the test itself
122
- public async isQtTestViaHelp(): Promise<boolean | undefined> {
123
- return await new Promise((resolve, reject) => {
124
- const child = spawn(this.filename, ["-help"]);
125
- let output = "";
126
- let result = false;
127
- child.stdout.on("data", (chunk) => {
128
- if (!result) {
129
- if (chunk.toString().includes("[testfunction[:testdata]]")) {
130
- result = true;
131
- }
132
- }
133
- });
134
-
135
- child.on("exit", (code) => {
136
- if (code === 0) {
137
- resolve(result);
138
- } else {
139
- resolve(false);
140
- }
141
- });
142
- });
143
- }
144
-
145
- public slotByName(name: string): QtTestSlot | undefined {
146
- if (!this.slots)
147
- return undefined;
148
-
149
- for (let slot of this.slots) {
150
- if (slot.name == name)
151
- return slot;
152
- }
153
-
154
- return undefined;
155
- }
156
-
157
- /// Runs this test
158
- public async runTest(slot?: QtTestSlot, cwd: string = ""): Promise<boolean> {
159
- let args: string[] = [];
160
- if (slot) {
161
- // Runs a single Qt test instead
162
- args = args.concat(slot.name);
163
- } else {
164
- this.clearSubTestStates();
165
- }
166
-
167
- // log to file
168
- args = args.concat("-o").concat(this.tapOutputFileName(slot) + ",tap");
169
- args = args.concat("-o").concat(this.txtOutputFileName(slot) + ",txt");
170
-
171
- return await new Promise((resolve, reject) => {
172
- let cwdDir = cwd.length > 0 ? cwd : this.buildDirPath;
173
- const child = spawn(this.filename, args, { cwd: cwdDir });
174
-
175
- child.on("exit", async (code) => {
176
-
177
- /// We can code even be null ?
178
- if (code == undefined) code = -1;
179
-
180
- if (!slot) {
181
- this.lastExitCode = code;
182
- }
183
-
184
- /// When running a QtTest executable, let's check which sub-tests failed
185
- /// (So VSCode can show some error icon for each fail)
186
- await this.updateSubTestStates(cwdDir, slot);
187
-
188
- if (code === 0) {
189
- resolve(true);
190
- } else {
191
- resolve(false);
192
- }
193
- });
194
- });
195
- }
196
-
197
- /// Using .tap so we don't have to use a separate XML library
198
- /// .tap is plain text and a single regexp can catch the failing tests and line number
199
- public tapOutputFileName(slot?: QtTestSlot): string {
200
- let slotName = slot ? ("_" + slot.name) : "";
201
- return this.label + slotName + ".tap";
202
- }
203
-
204
- public txtOutputFileName(slot?: QtTestSlot): string {
205
- let slotName = slot ? ("_" + slot.name) : "";
206
- return this.label + slotName + ".txt";
207
- }
208
-
209
- public command(): { label: string, executablePath: string, args: string[] } {
210
- return { label: this.label, executablePath: this.filename, args: [] };
211
- }
212
-
213
-
214
- public clearSubTestStates() {
215
- if (this.slots) {
216
- for (let slot of this.slots) {
217
- slot.lastTestFailure = undefined;
218
- }
219
- }
220
- }
221
-
222
- public async updateSubTestStates(cwdDir: string, slot?: QtTestSlot) {
223
-
224
- let tapFileName: string = cwdDir + "/" + this.tapOutputFileName(slot);
225
-
226
- var failures = await new Promise<TestFailure[]>((resolve, reject) => {
227
- fs.readFile(tapFileName, "utf8", (error, data) => {
228
- if (error) {
229
- console.log("Failed to read log file");
230
- reject(error);
231
- } else {
232
- // A fail line is something like:
233
- // at: MyTest::testF() (/some/path/qttest-utils/test/qt_test/test2.cpp:13)
234
-
235
- const pattern = /at:\s+(.+?)::(.+?)\(\)\s+\((.+?):(\d+)\)/gm;
236
- const matches = Array.from(data.matchAll(pattern));
237
- const failedResults = matches.map(match => ({
238
- name: match[2],
239
- filePath: match[3],
240
- lineNumber: parseInt(match[4]),
241
- }));
242
-
243
- resolve(failedResults);
244
- }
245
- });
246
- });
247
-
248
- for (let failure of failures) {
249
- if (slot && slot.name != failure.name) {
250
- // We executed a single slot, ignore anything else
251
- continue;
252
- }
253
-
254
- let failedSlot = this.slotByName(failure.name);
255
- if (failedSlot) {
256
- failedSlot.lastTestFailure = failure;
257
- } else {
258
- console.log("Failed to find slot with name " + failure.name);
259
- }
260
- }
261
- }
262
- }
263
-
264
- /**
265
- * Represents a single Qt test slot
266
- */
267
- export class QtTestSlot {
268
- name: string;
269
-
270
- // The QTest executable this slot belongs to
271
- parentQTest: QtTest;
272
-
273
- /// Allows vscode extensions to associate with a test item
274
- vscodeTestItem: any | undefined;
275
-
276
- /// Set after running
277
- lastTestFailure: TestFailure | undefined;
278
-
279
- constructor(name: string, parent: QtTest) {
280
- this.name = name;
281
- this.parentQTest = parent;
282
- }
283
-
284
- public get id() {
285
- return this.parentQTest.filename + this.name;
286
- }
287
-
288
- public get absoluteFilePath() {
289
- return this.parentQTest.filename;
290
- }
291
-
292
- public async runTest(): Promise<boolean> {
293
- return this.parentQTest.runTest(this);
294
- }
295
-
296
- public command(): { label: string, executablePath: string, args: string[] } {
297
- return { label: this.name, executablePath: this.absoluteFilePath, args: [this.name] };
298
- }
299
- }
300
-
301
- /**
302
- * Represents the list of all QtTest executables in your project
303
- */
304
- export class QtTests {
305
- qtTestExecutables: QtTest[] = [];
306
-
307
- async discoverViaCMake(buildDirPath: string) {
308
- var cmake = new CMakeTests(buildDirPath);
309
- let ctests = await cmake.tests();
310
- if (ctests) {
311
- for (let ctest of ctests) {
312
- let qtest = new QtTest(ctest.executablePath(), buildDirPath);
313
- this.qtTestExecutables.push(qtest);
314
- }
315
- } else {
316
- console.error("Failed to retrieve ctests!");
317
- }
318
- }
319
-
320
- /// Removes any executable (from the list) that doesn't link to libQtTest.so
321
- /// This heuristic tries to filter-out doctest and other non-Qt tests
322
- /// Only implemented for linux for now
323
- public async removeNonLinking() {
324
- let isLinux = process.platform === "linux";
325
- if (!isLinux) { return; }
326
-
327
- let acceptedExecutables: QtTest[] = [];
328
- for (let ex of this.qtTestExecutables) {
329
- let linksToQt = await ex.linksToQtTestLib();
330
- // undefined or true is accepted
331
- if (linksToQt !== false) {
332
- acceptedExecutables.push(ex);
333
- }
334
- this.qtTestExecutables = acceptedExecutables;
335
- }
336
- }
337
-
338
- public async removeByRunningHelp() {
339
- this.qtTestExecutables = this.qtTestExecutables.filter(async (ex) => await ex.isQtTestViaHelp());
340
- }
341
-
342
- /// Removes any executable (from the list) that matches the specified regex
343
- public removeMatching(regex: RegExp) {
344
- this.qtTestExecutables = this.qtTestExecutables.filter((ex) => !regex.test(ex.filename));
345
- }
346
-
347
- /// Removes any executable (from the list) that doesn't match the specified regex
348
- public maintainMatching(regex: RegExp) {
349
- this.qtTestExecutables = this.qtTestExecutables.filter((ex) => regex.test(ex.filename));
350
- }
351
-
352
- public dumpExecutablePaths() {
353
- for (var ex of this.qtTestExecutables) {
354
- console.log(ex.filename);
355
- }
356
- }
357
-
358
- public async dumpTestSlots() {
359
- for (var ex of this.qtTestExecutables) {
360
- if (!ex.slots)
361
- await ex.parseAvailableSlots();
362
-
363
- console.log(ex.filename);
364
- if (ex.slots) {
365
- for (let slot of ex.slots) {
366
- console.log(" - " + slot.name);
367
- }
368
- }
369
- }
370
- }
371
- }
372
-
373
- /// Represents a failure location
374
- export interface TestFailure {
375
- name: string;
376
- filePath: string;
377
- lineNumber: number;
378
- }
package/src/utils.ts DELETED
@@ -1,59 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- // Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- import path from "path";
6
- import * as fs from 'fs';
7
-
8
- /// Returns whether the specified file is an executable
9
- function isExecutable(filePath: string): boolean {
10
- if (process.platform === "win32") {
11
- return path.extname(filePath).toLocaleLowerCase() === ".exe";
12
- } else {
13
- try {
14
- fs.accessSync(filePath, fs.constants.X_OK);
15
- return true;
16
- } catch (err) {
17
- return false;
18
- }
19
- }
20
- }
21
-
22
- /// Returns whether the specified file is a library
23
- function isLibrary(filename: string): boolean {
24
- const split = filename.split(".");
25
-
26
- if (split.length <= 1) { return false; }
27
-
28
- // Find the first non-numeric extension, so we ignore all the trailing numbers in libFoo.so.2.0.9
29
- for (var i = split.length - 1; i >= 0; --i) {
30
- const extension = split[i];
31
- const isNumber = !isNaN(Number(extension));
32
- if (isNumber) { continue; }
33
-
34
- return ["so", "dll", "dylib"].includes(extension);
35
- }
36
-
37
- return false;
38
- }
39
-
40
- /// Recursively looks for executable files in folderPath
41
- function executableFiles(folderPath: string): string[] {
42
- const files = fs.readdirSync(folderPath);
43
- var executables: string[] = [];
44
- for (var file of files) {
45
-
46
- // Ignore CMakeFiles directory, it has some of binaries
47
- if (path.basename(file) === "CMakeFiles") { continue; }
48
-
49
- const childPath = path.join(folderPath, file);
50
- const info = fs.statSync(childPath);
51
- if (info.isDirectory()) {
52
- executables = executables.concat(executableFiles(childPath));
53
- } else if (info.isFile() && !isLibrary(path.basename(childPath)) && isExecutable(childPath)) {
54
- executables.push(childPath);
55
- }
56
- }
57
-
58
- return executables;
59
- }
@@ -1,22 +0,0 @@
1
- # SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2
- # Author: Sergio Martins <sergio.martins@kdab.com>
3
- # SPDX-License-Identifier: MIT
4
-
5
- cmake_minimum_required(VERSION 3.12)
6
- project(qttest)
7
-
8
- find_package(Qt5Test 5.15 REQUIRED)
9
- set(CMAKE_AUTOMOC ON)
10
-
11
- add_executable(test1 test1.cpp)
12
- add_executable(test2 test2.cpp)
13
- add_executable(test3 test3.cpp)
14
-
15
- target_link_libraries(test1 Qt5::Test)
16
- target_link_libraries(test2 Qt5::Test)
17
- target_link_libraries(test3 Qt5::Test)
18
-
19
- enable_testing()
20
- add_test(NAME test1 COMMAND test1)
21
- add_test(NAME test2 COMMAND test2)
22
- add_test(NAME test3 COMMAND test3)
@@ -1,15 +0,0 @@
1
- {
2
- "version": 2,
3
- "configurePresets": [
4
- {
5
- "name": "dev",
6
- "displayName": "dev",
7
- "generator": "Ninja",
8
- "binaryDir": "${sourceDir}/build-dev",
9
- "cacheVariables": {
10
- "CMAKE_BUILD_TYPE": "Debug",
11
- "CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
12
- }
13
- }
14
- ]
15
- }
@@ -1,18 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group
2
- // company <info@kdab.com> Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- #include <QObject>
6
- #include <QtTest>
7
-
8
- class MyTest : public QObject {
9
- Q_OBJECT
10
- private Q_SLOTS:
11
- void testA() {}
12
- void testB() {}
13
- void testC() {}
14
- };
15
-
16
- QTEST_MAIN(MyTest);
17
-
18
- #include <test1.moc>
@@ -1,18 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group
2
- // company <info@kdab.com> Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- #include <QObject>
6
- #include <QtTest>
7
-
8
- class MyTest : public QObject {
9
- Q_OBJECT
10
- private Q_SLOTS:
11
- void testD() {}
12
- void testE() {}
13
- void testF() { QFAIL("failed"); }
14
- };
15
-
16
- QTEST_MAIN(MyTest);
17
-
18
- #include <test2.moc>
@@ -1,18 +0,0 @@
1
- // SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group
2
- // company <info@kdab.com> Author: Sergio Martins <sergio.martins@kdab.com>
3
- // SPDX-License-Identifier: MIT
4
-
5
- #include <QObject>
6
- #include <QtTest>
7
-
8
- class MyTest : public QObject {
9
- Q_OBJECT
10
- private Q_SLOTS:
11
- void testG() {}
12
- void testH() {}
13
- void testI() {}
14
- };
15
-
16
- QTEST_MAIN(MyTest);
17
-
18
- #include <test3.moc>
package/test1.log DELETED
@@ -1,31 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <TestCase name="MyTest">
3
- <Environment>
4
- <QtVersion>5.15.2</QtVersion>
5
- <QtBuild>Qt 5.15.2 (x86_64&#x002D;little_endian&#x002D;lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1&#x002D;6))</QtBuild>
6
- <QTestVersion>5.15.2</QTestVersion>
7
- </Environment>
8
- <TestFunction name="initTestCase">
9
- <Incident type="pass" file="" line="0" />
10
- <Duration msecs="0.312962"/>
11
- </TestFunction>
12
- <TestFunction name="testD">
13
- <Incident type="pass" file="" line="0" />
14
- <Duration msecs="0.010127"/>
15
- </TestFunction>
16
- <TestFunction name="testE">
17
- <Incident type="pass" file="" line="0" />
18
- <Duration msecs="0.005239"/>
19
- </TestFunction>
20
- <TestFunction name="testF">
21
- <Incident type="fail" file="/data/sources/vscode&#x002D;test&#x002D;extension/qttest&#x002D;utils/test/qt_test/test2.cpp" line="13">
22
- <Description><![CDATA[failed]]></Description>
23
- </Incident>
24
- <Duration msecs="0.018438"/>
25
- </TestFunction>
26
- <TestFunction name="cleanupTestCase">
27
- <Incident type="pass" file="" line="0" />
28
- <Duration msecs="0.00426"/>
29
- </TestFunction>
30
- <Duration msecs="0.432951"/>
31
- </TestCase>
package/test1.log1 DELETED
@@ -1,17 +0,0 @@
1
- TAP version 13
2
- # MyTest
3
- ok 1 - initTestCase()
4
- ok 2 - testD()
5
- ok 3 - testE()
6
- not ok 4 - testF()
7
- ---
8
- # failed
9
- at: MyTest::testF() (/data/sources/vscode-test-extension/qttest-utils/test/qt_test/test2.cpp:13)
10
- file: /data/sources/vscode-test-extension/qttest-utils/test/qt_test/test2.cpp
11
- line: 13
12
- ...
13
- ok 5 - cleanupTestCase()
14
- 1..5
15
- # tests 5
16
- # pass 4
17
- # fail 1
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "CommonJS",
4
- "esModuleInterop": true,
5
- "target": "ES6",
6
- "outDir": "out",
7
- "sourceMap": false,
8
- "strict": true,
9
- "declaration": true
10
- },
11
- "include": [
12
- "src/*.ts"
13
- ],
14
- "exclude": [
15
- "node_modules",
16
- "out"
17
- ]
18
- }