@iamsergio/qttest-utils 0.3.1 → 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 +2 -2
- package/src/qttest.ts +14 -4
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"
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
"ts-node": "^10.9.1",
|
|
20
20
|
"typescript": "^4.9.5"
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
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() {
|
|
@@ -35,6 +39,11 @@ export class QtTest {
|
|
|
35
39
|
let err = "";
|
|
36
40
|
|
|
37
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
|
+
|
|
38
47
|
const child = spawn(this.filename, ["-functions"]);
|
|
39
48
|
|
|
40
49
|
child.stdout.on("data", (chunk) => {
|
|
@@ -127,7 +136,7 @@ export class QtTest {
|
|
|
127
136
|
}
|
|
128
137
|
|
|
129
138
|
/// Runs this test
|
|
130
|
-
public async runTest(slotName?: string): Promise<boolean> {
|
|
139
|
+
public async runTest(slotName?: string, cwd: string = ""): Promise<boolean> {
|
|
131
140
|
let args: string[] = [];
|
|
132
141
|
if (slotName) {
|
|
133
142
|
// Runs a single Qt test instead
|
|
@@ -135,7 +144,8 @@ export class QtTest {
|
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
return await new Promise((resolve, reject) => {
|
|
138
|
-
|
|
147
|
+
let opts = cwd.length > 0 ? {cwd: cwd} : {cwd: this.buildDirPath};
|
|
148
|
+
const child = spawn(this.filename, args, opts);
|
|
139
149
|
child.stdout.on("data", (chunk) => {
|
|
140
150
|
// chunk.toString()
|
|
141
151
|
});
|
|
@@ -197,7 +207,7 @@ export class QtTests {
|
|
|
197
207
|
let ctests = await cmake.tests();
|
|
198
208
|
if (ctests) {
|
|
199
209
|
for (let ctest of ctests) {
|
|
200
|
-
let qtest = new QtTest(ctest.executablePath());
|
|
210
|
+
let qtest = new QtTest(ctest.executablePath(), buildDirPath);
|
|
201
211
|
this.qtTestExecutables.push(qtest);
|
|
202
212
|
}
|
|
203
213
|
} else {
|