@iamsergio/qttest-utils 0.4.6 → 0.4.7
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 +3 -0
- package/out/qttest.d.ts +3 -0
- package/out/qttest.js +13 -3
- package/package.json +1 -1
- package/src/example.ts +4 -0
- package/src/qttest.ts +18 -3
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "0.4.7",
|
|
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/src/example.ts
CHANGED
package/src/qttest.ts
CHANGED
|
@@ -7,6 +7,16 @@ import path from "path";
|
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import { CMakeTests } from "./cmake";
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
type LoggerFunction = (arg: string) => void;
|
|
12
|
+
var gLogFunction: LoggerFunction | undefined;
|
|
13
|
+
|
|
14
|
+
function logMessage(message: string) {
|
|
15
|
+
if (gLogFunction) {
|
|
16
|
+
gLogFunction(message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
/**
|
|
11
21
|
* Represents a single QtTest executable.
|
|
12
22
|
* Supports listing the individual test slots
|
|
@@ -170,6 +180,7 @@ export class QtTest {
|
|
|
170
180
|
|
|
171
181
|
return await new Promise((resolve, reject) => {
|
|
172
182
|
let cwdDir = cwd.length > 0 ? cwd : this.buildDirPath;
|
|
183
|
+
logMessage("Running " + this.filename + " " + args.join(" ") + " with cwd=" + cwdDir);
|
|
173
184
|
const child = spawn(this.filename, args, { cwd: cwdDir });
|
|
174
185
|
|
|
175
186
|
child.on("exit", async (code) => {
|
|
@@ -226,7 +237,7 @@ export class QtTest {
|
|
|
226
237
|
var failures = await new Promise<TestFailure[]>((resolve, reject) => {
|
|
227
238
|
fs.readFile(tapFileName, "utf8", (error, data) => {
|
|
228
239
|
if (error) {
|
|
229
|
-
|
|
240
|
+
logMessage("ERROR: Failed to read log file");
|
|
230
241
|
reject(error);
|
|
231
242
|
} else {
|
|
232
243
|
// A fail line is something like:
|
|
@@ -255,7 +266,7 @@ export class QtTest {
|
|
|
255
266
|
if (failedSlot) {
|
|
256
267
|
failedSlot.lastTestFailure = failure;
|
|
257
268
|
} else {
|
|
258
|
-
|
|
269
|
+
logMessage("ERROR: Failed to find slot with name " + failure.name);
|
|
259
270
|
}
|
|
260
271
|
}
|
|
261
272
|
}
|
|
@@ -313,7 +324,7 @@ export class QtTests {
|
|
|
313
324
|
this.qtTestExecutables.push(qtest);
|
|
314
325
|
}
|
|
315
326
|
} else {
|
|
316
|
-
|
|
327
|
+
logMessage("ERROR: Failed to retrieve ctests!");
|
|
317
328
|
}
|
|
318
329
|
}
|
|
319
330
|
|
|
@@ -335,6 +346,10 @@ export class QtTests {
|
|
|
335
346
|
}
|
|
336
347
|
}
|
|
337
348
|
|
|
349
|
+
public setLogFunction(func: LoggerFunction) {
|
|
350
|
+
gLogFunction = func;
|
|
351
|
+
}
|
|
352
|
+
|
|
338
353
|
public async removeByRunningHelp() {
|
|
339
354
|
this.qtTestExecutables = this.qtTestExecutables.filter(async (ex) => await ex.isQtTestViaHelp());
|
|
340
355
|
}
|