@iamsergio/qttest-utils 0.4.0 → 0.4.2
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/cmake.d.ts +23 -23
- package/out/cmake.js +91 -91
- package/out/example.d.ts +1 -1
- package/out/example.js +45 -45
- package/out/index.d.ts +10 -10
- package/out/index.js +11 -11
- package/out/qttest.d.ts +60 -59
- package/out/qttest.js +291 -257
- package/out/utils.d.ts +1 -1
- package/out/utils.js +85 -85
- package/package.json +1 -1
- package/src/qttest.ts +1 -1
- package/out/ctest.d.ts +0 -23
- package/out/ctest.js +0 -88
- package/out/foo.d.ts +0 -0
- package/out/foo.js +0 -2
- package/out/runtests.d.ts +0 -1
- package/out/runtests.js +0 -26
package/out/qttest.js
CHANGED
|
@@ -1,257 +1,291 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
|
3
|
-
// Author: Sergio Martins <sergio.martins@kdab.com>
|
|
4
|
-
// SPDX-License-Identifier: MIT
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
|
3
|
+
// Author: Sergio Martins <sergio.martins@kdab.com>
|
|
4
|
+
// SPDX-License-Identifier: MIT
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.QtTests = exports.QtTestSlot = exports.QtTest = void 0;
|
|
42
|
+
const child_process_1 = require("child_process");
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const cmake_1 = require("./cmake");
|
|
46
|
+
/**
|
|
47
|
+
* Represents a single QtTest executable.
|
|
48
|
+
* Supports listing the individual test slots
|
|
49
|
+
*/
|
|
50
|
+
class QtTest {
|
|
51
|
+
constructor(filename, buildDirPath) {
|
|
52
|
+
this.slots = null;
|
|
53
|
+
this.filename = filename;
|
|
54
|
+
this.buildDirPath = buildDirPath;
|
|
55
|
+
}
|
|
56
|
+
get id() {
|
|
57
|
+
return this.filename;
|
|
58
|
+
}
|
|
59
|
+
get label() {
|
|
60
|
+
return path_1.default.basename(this.filename);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Calls "./yourqttest -functions" and stores the results in the slots property.
|
|
64
|
+
*/
|
|
65
|
+
parseAvailableSlots() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
let slotNames = [];
|
|
68
|
+
let output = "";
|
|
69
|
+
let err = "";
|
|
70
|
+
yield new Promise((resolve, reject) => {
|
|
71
|
+
if (!fs.existsSync(this.filename)) {
|
|
72
|
+
reject(new Error("File doesn't exit: " + this.filename));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const child = (0, child_process_1.spawn)(this.filename, ["-functions"], { cwd: this.buildDirPath });
|
|
76
|
+
child.stdout.on("data", (chunk) => {
|
|
77
|
+
output += chunk.toString();
|
|
78
|
+
});
|
|
79
|
+
child.stderr.on("data", (chunk) => {
|
|
80
|
+
err += chunk.toString();
|
|
81
|
+
});
|
|
82
|
+
child.on("exit", (code) => {
|
|
83
|
+
if (code === 0) {
|
|
84
|
+
slotNames = slotNames.concat(output.split("\n"));
|
|
85
|
+
slotNames = slotNames.map(entry => entry.trim().replace("()", ""));
|
|
86
|
+
slotNames = slotNames.filter(entry => entry.length > 0);
|
|
87
|
+
if (slotNames.length > 0) {
|
|
88
|
+
this.slots = [];
|
|
89
|
+
for (var slotName of slotNames) {
|
|
90
|
+
var slot = new QtTestSlot(slotName, this);
|
|
91
|
+
this.slots.push(slot);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
resolve(slotNames);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
reject(new Error("Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns whether this executable links to libQtTest.so.
|
|
105
|
+
*
|
|
106
|
+
* Useful for Qt autodetection, as some tests are doctest or so.
|
|
107
|
+
*
|
|
108
|
+
* Only implemented for Linux. Returns undefined on other platforms.
|
|
109
|
+
*/
|
|
110
|
+
linksToQtTestLib() {
|
|
111
|
+
let isLinux = process.platform === "linux";
|
|
112
|
+
if (!isLinux) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
const child = (0, child_process_1.spawn)("ldd", [this.filename]);
|
|
117
|
+
let output = "";
|
|
118
|
+
let result = false;
|
|
119
|
+
child.stdout.on("data", (chunk) => {
|
|
120
|
+
if (!result) {
|
|
121
|
+
if (chunk.toString().includes("libQt5Test.so") || chunk.toString().includes("libQt6Test.so")) {
|
|
122
|
+
result = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
child.on("exit", (code) => {
|
|
127
|
+
if (code === 0) {
|
|
128
|
+
resolve(result);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
reject(new Error("Failed to run ldd"));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/// Returns whether this test is a QtTest by running it with -help and checking if the help text looks familiar
|
|
137
|
+
/// Note that if this is not a QtTest it might not run help and instead execute the test itself
|
|
138
|
+
isQtTestViaHelp() {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
return yield new Promise((resolve, reject) => {
|
|
141
|
+
const child = (0, child_process_1.spawn)(this.filename, ["-help"]);
|
|
142
|
+
let output = "";
|
|
143
|
+
let result = false;
|
|
144
|
+
child.stdout.on("data", (chunk) => {
|
|
145
|
+
if (!result) {
|
|
146
|
+
if (chunk.toString().includes("[testfunction[:testdata]]")) {
|
|
147
|
+
result = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
child.on("exit", (code) => {
|
|
152
|
+
if (code === 0) {
|
|
153
|
+
resolve(result);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
resolve(false);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/// Runs this test
|
|
163
|
+
runTest(slotName, cwd = "") {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
let args = [];
|
|
166
|
+
if (slotName) {
|
|
167
|
+
// Runs a single Qt test instead
|
|
168
|
+
args = args.concat(slotName);
|
|
169
|
+
}
|
|
170
|
+
return yield new Promise((resolve, reject) => {
|
|
171
|
+
let opts = cwd.length > 0 ? { cwd: cwd } : { cwd: this.buildDirPath };
|
|
172
|
+
const child = (0, child_process_1.spawn)(this.filename, args, opts);
|
|
173
|
+
child.stdout.on("data", (chunk) => {
|
|
174
|
+
// chunk.toString()
|
|
175
|
+
});
|
|
176
|
+
child.on("exit", (code) => {
|
|
177
|
+
if (code === 0) {
|
|
178
|
+
resolve(true);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
resolve(false);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
command() {
|
|
188
|
+
return { label: this.label, executablePath: this.filename, args: [] };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.QtTest = QtTest;
|
|
192
|
+
/**
|
|
193
|
+
* Represents a single Qt test slot
|
|
194
|
+
*/
|
|
195
|
+
class QtTestSlot {
|
|
196
|
+
constructor(name, parent) {
|
|
197
|
+
this.name = name;
|
|
198
|
+
this.parentQTest = parent;
|
|
199
|
+
}
|
|
200
|
+
get id() {
|
|
201
|
+
return this.parentQTest.filename + this.name;
|
|
202
|
+
}
|
|
203
|
+
get absoluteFilePath() {
|
|
204
|
+
return this.parentQTest.filename;
|
|
205
|
+
}
|
|
206
|
+
runTest() {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
return this.parentQTest.runTest(this.name);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
command() {
|
|
212
|
+
return { label: this.name, executablePath: this.absoluteFilePath, args: [this.name] };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.QtTestSlot = QtTestSlot;
|
|
216
|
+
/**
|
|
217
|
+
* Represents the list of all QtTest executables in your project
|
|
218
|
+
*/
|
|
219
|
+
class QtTests {
|
|
220
|
+
constructor() {
|
|
221
|
+
this.qtTestExecutables = [];
|
|
222
|
+
}
|
|
223
|
+
discoverViaCMake(buildDirPath) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
var cmake = new cmake_1.CMakeTests(buildDirPath);
|
|
226
|
+
let ctests = yield cmake.tests();
|
|
227
|
+
if (ctests) {
|
|
228
|
+
for (let ctest of ctests) {
|
|
229
|
+
let qtest = new QtTest(ctest.executablePath(), buildDirPath);
|
|
230
|
+
this.qtTestExecutables.push(qtest);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
console.error("Failed to retrieve ctests!");
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/// Removes any executable (from the list) that doesn't link to libQtTest.so
|
|
239
|
+
/// This heuristic tries to filter-out doctest and other non-Qt tests
|
|
240
|
+
/// Only implemented for linux for now
|
|
241
|
+
removeNonLinking() {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
let isLinux = process.platform === "linux";
|
|
244
|
+
if (!isLinux) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let acceptedExecutables = [];
|
|
248
|
+
for (let ex of this.qtTestExecutables) {
|
|
249
|
+
let linksToQt = yield ex.linksToQtTestLib();
|
|
250
|
+
// undefined or true is accepted
|
|
251
|
+
if (linksToQt !== false) {
|
|
252
|
+
acceptedExecutables.push(ex);
|
|
253
|
+
}
|
|
254
|
+
this.qtTestExecutables = acceptedExecutables;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
removeByRunningHelp() {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
this.qtTestExecutables = this.qtTestExecutables.filter((ex) => __awaiter(this, void 0, void 0, function* () { return yield ex.isQtTestViaHelp(); }));
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/// Removes any executable (from the list) that matches the specified regex
|
|
264
|
+
removeMatching(regex) {
|
|
265
|
+
this.qtTestExecutables = this.qtTestExecutables.filter((ex) => !regex.test(ex.filename));
|
|
266
|
+
}
|
|
267
|
+
/// Removes any executable (from the list) that doesn't match the specified regex
|
|
268
|
+
maintainMatching(regex) {
|
|
269
|
+
this.qtTestExecutables = this.qtTestExecutables.filter((ex) => regex.test(ex.filename));
|
|
270
|
+
}
|
|
271
|
+
dumpExecutablePaths() {
|
|
272
|
+
for (var ex of this.qtTestExecutables) {
|
|
273
|
+
console.log(ex.filename);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
dumpTestSlots() {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
for (var ex of this.qtTestExecutables) {
|
|
279
|
+
if (!ex.slots)
|
|
280
|
+
yield ex.parseAvailableSlots();
|
|
281
|
+
console.log(ex.filename);
|
|
282
|
+
if (ex.slots) {
|
|
283
|
+
for (let slot of ex.slots) {
|
|
284
|
+
console.log(" - " + slot.name);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.QtTests = QtTests;
|
package/out/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|