@iamsergio/qttest-utils 0.3.0 → 0.4.0
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/package.json +1 -1
- package/src/qttest.ts +20 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iamsergio/qttest-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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
|
"scripts": {
|
|
6
6
|
"build": "tsc"
|
package/src/qttest.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
import path from "path";
|
|
7
|
+
import * as fs from 'fs';
|
|
7
8
|
import { CMakeTests } from "./cmake";
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -12,10 +13,13 @@ import { CMakeTests } from "./cmake";
|
|
|
12
13
|
*/
|
|
13
14
|
export class QtTest {
|
|
14
15
|
readonly filename: string;
|
|
16
|
+
readonly buildDirPath: string;
|
|
17
|
+
|
|
15
18
|
slots: QtTestSlot[] | null = null;
|
|
16
19
|
|
|
17
|
-
constructor(filename: string) {
|
|
20
|
+
constructor(filename: string, buildDirPath: string) {
|
|
18
21
|
this.filename = filename;
|
|
22
|
+
this.buildDirPath = buildDirPath;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
public get id() {
|
|
@@ -32,14 +36,24 @@ export class QtTest {
|
|
|
32
36
|
public async parseAvailableSlots(): Promise<void> {
|
|
33
37
|
let slotNames: string[] = [];
|
|
34
38
|
let output = "";
|
|
39
|
+
let err = "";
|
|
35
40
|
|
|
36
41
|
await new Promise((resolve, reject) => {
|
|
42
|
+
if (!fs.existsSync(this.filename)) {
|
|
43
|
+
reject(new Error("File doesn't exit: " + this.filename));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
const child = spawn(this.filename, ["-functions"]);
|
|
38
48
|
|
|
39
49
|
child.stdout.on("data", (chunk) => {
|
|
40
50
|
output += chunk.toString();
|
|
41
51
|
});
|
|
42
52
|
|
|
53
|
+
child.stderr.on("data", (chunk) => {
|
|
54
|
+
err += chunk.toString();
|
|
55
|
+
});
|
|
56
|
+
|
|
43
57
|
child.on("exit", (code) => {
|
|
44
58
|
if (code === 0) {
|
|
45
59
|
slotNames = slotNames.concat(output.split("\n"));
|
|
@@ -56,7 +70,7 @@ export class QtTest {
|
|
|
56
70
|
|
|
57
71
|
resolve(slotNames);
|
|
58
72
|
} else {
|
|
59
|
-
reject(new Error("Failed to run -functions"));
|
|
73
|
+
reject(new Error("Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
|
|
60
74
|
}
|
|
61
75
|
});
|
|
62
76
|
});
|
|
@@ -122,7 +136,7 @@ export class QtTest {
|
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
/// Runs this test
|
|
125
|
-
public async runTest(slotName?: string): Promise<boolean> {
|
|
139
|
+
public async runTest(slotName?: string, cwd: string = ""): Promise<boolean> {
|
|
126
140
|
let args: string[] = [];
|
|
127
141
|
if (slotName) {
|
|
128
142
|
// Runs a single Qt test instead
|
|
@@ -130,7 +144,8 @@ export class QtTest {
|
|
|
130
144
|
}
|
|
131
145
|
|
|
132
146
|
return await new Promise((resolve, reject) => {
|
|
133
|
-
|
|
147
|
+
let opts = cwd.length > 0 ? {cwd: cwd} : {cwd: this.buildDirPath};
|
|
148
|
+
const child = spawn(this.filename, args, opts);
|
|
134
149
|
child.stdout.on("data", (chunk) => {
|
|
135
150
|
// chunk.toString()
|
|
136
151
|
});
|
|
@@ -192,7 +207,7 @@ export class QtTests {
|
|
|
192
207
|
let ctests = await cmake.tests();
|
|
193
208
|
if (ctests) {
|
|
194
209
|
for (let ctest of ctests) {
|
|
195
|
-
let qtest = new QtTest(ctest.executablePath());
|
|
210
|
+
let qtest = new QtTest(ctest.executablePath(), buildDirPath);
|
|
196
211
|
this.qtTestExecutables.push(qtest);
|
|
197
212
|
}
|
|
198
213
|
} else {
|