@iamsergio/qttest-utils 2.2.1 → 2.3.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "2.3.0"
3
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## [2.3.0](https://github.com/KDAB/qttest-utils/compare/v2.2.2...v2.3.0) (2024-06-06)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add support for QEXPECT_FAIL ([0037921](https://github.com/KDAB/qttest-utils/commit/003792112bd6093640e772dcfd109812f38324bd))
9
+ * Add support for XPASS ([a60be6b](https://github.com/KDAB/qttest-utils/commit/a60be6b81f22d3a18ee624e2414e91c37e2c607f))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * Fix JSON output from ctest not being received ([9cea2c3](https://github.com/KDAB/qttest-utils/commit/9cea2c3dd4b5798f7f6f0bf382e5eca1694f0eb2))
15
+ * Use tap-parser instead of regexp to parse tap files ([3d9f1f5](https://github.com/KDAB/qttest-utils/commit/3d9f1f5abc77d2af1a57ba6a75b89c8a3ad424ed))
package/CONTRIBUTING.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Prepare your development environment
4
4
 
5
- Just follow `.devcontainer/Dockerfile` to see what's needed.<br?>
5
+ Just follow `.devcontainer/Dockerfile` to see what's needed.<br>
6
6
  Basically it's just `nodejs` >= v18 `tsc` and `npm`. <br>
7
7
  Qt5, cmake and ninja if you want to run the tests.
8
8
 
@@ -10,8 +10,7 @@ Qt5, cmake and ninja if you want to run the tests.
10
10
  ## Running tests
11
11
 
12
12
  ```bash
13
- tsc
14
- node out/test.js
13
+ sh test.sh
15
14
  ```
16
15
 
17
16
  Or simply let GitHub actions run the tests for you.<br>
package/Changelog CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
 
4
4
 
5
+ ## [2.2.2] - 2024-05-02
6
+
7
+ ### 🐛 Bug Fixes
8
+
9
+ - Filter out weird tests
10
+
11
+ ### ⚙️ Miscellaneous Tasks
12
+
13
+ - Code format cmake.ts
14
+
5
15
  ## [2.2.1] - 2024-05-02
6
16
 
7
17
  ### 🐛 Bug Fixes
@@ -18,6 +28,7 @@
18
28
 
19
29
  - Ran code format on tests
20
30
  - Run codeformat on qttest.ts
31
+ - Bump version
21
32
 
22
33
  ## [2.2.0] - 2024-04-25
23
34
 
package/out/cmake.js CHANGED
@@ -42,14 +42,23 @@ class CMakeTests {
42
42
  }
43
43
  return new Promise((resolve, reject) => {
44
44
  (0, qttest_1.logMessage)("Running ctest --show-only=json-v1 with cwd=" + this.buildDirPath);
45
- const child = (0, child_process_1.spawn)("ctest", ["--show-only=json-v1"], { "cwd": this.buildDirPath });
45
+ const child = (0, child_process_1.spawn)("ctest", ["--show-only=json-v1"], {
46
+ cwd: this.buildDirPath,
47
+ });
46
48
  let output = "";
47
49
  child.stdout.on("data", (chunk) => {
48
50
  output += chunk.toString();
49
51
  });
50
- child.on("exit", (code) => {
52
+ child.on("close", (code) => {
51
53
  if (code === 0) {
52
- resolve(this.ctestJsonToList(output));
54
+ if (output.length == 0) {
55
+ console.error("ctestJsonToList: Empty json output. Command was ctest --show-only=json-v1 , in " +
56
+ this.buildDirPath);
57
+ reject(new Error("Failed to get ctest JSON output"));
58
+ }
59
+ else {
60
+ resolve(this.ctestJsonToList(output));
61
+ }
53
62
  }
54
63
  else {
55
64
  reject(new Error("Failed to run ctest"));
@@ -70,6 +79,20 @@ class CMakeTests {
70
79
  test.cwd = testJSON.cwd;
71
80
  return test;
72
81
  });
82
+ // filter invalid tests:
83
+ tests = tests.filter((test) => {
84
+ // pretty print test
85
+ if (!test.command || test.command.length == 0)
86
+ return false;
87
+ let testExecutablePath = test.executablePath();
88
+ let baseName = path_1.default.basename(testExecutablePath).toLowerCase();
89
+ if (baseName.endsWith(".exe"))
90
+ baseName = baseName.substring(0, baseName.length - 4);
91
+ // People doing complicated things in add_test()
92
+ if (baseName == "ctest" || baseName === "cmake")
93
+ return false;
94
+ return true;
95
+ });
73
96
  return tests;
74
97
  }
75
98
  /// Returns the cmake target name for the specified executable
@@ -122,7 +145,7 @@ class CMakeTests {
122
145
  // files aren't equal!
123
146
  return false;
124
147
  }
125
- const fs = require('fs');
148
+ const fs = require("fs");
126
149
  if (fs.existsSync(file2)) {
127
150
  // It's a real file, not bogus.
128
151
  return false;
@@ -178,7 +201,8 @@ class CMakeTests {
178
201
  }
179
202
  }
180
203
  }
181
- (0, qttest_1.logMessage)("cppFilesForExecutable: Could not find cpp files for executable " + executable);
204
+ (0, qttest_1.logMessage)("cppFilesForExecutable: Could not find cpp files for executable " +
205
+ executable);
182
206
  return [];
183
207
  }
184
208
  }
package/out/qttest.js CHANGED
@@ -43,6 +43,7 @@ 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
+ const tap_parser_1 = require("tap-parser");
46
47
  var gLogFunction;
47
48
  function logMessage(message) {
48
49
  if (gLogFunction) {
@@ -211,8 +212,8 @@ class QtTest {
211
212
  return undefined;
212
213
  }
213
214
  /// Runs this test
214
- runTest(slot, cwd = "") {
215
- return __awaiter(this, void 0, void 0, function* () {
215
+ runTest(slot_1) {
216
+ return __awaiter(this, arguments, void 0, function* (slot, cwd = "") {
216
217
  let args = [];
217
218
  if (slot) {
218
219
  // Runs a single Qt test instead
@@ -255,7 +256,12 @@ class QtTest {
255
256
  if (this.slots && this.slots.length > 0) {
256
257
  /// When running a QtTest executable, let's check which sub-tests failed
257
258
  /// (So VSCode can show some error icon for each fail)
258
- yield this.updateSubTestStates(cwdDir, slot);
259
+ try {
260
+ yield this.updateSubTestStates(cwdDir, slot);
261
+ }
262
+ catch (e) {
263
+ logMessage("Failed to update sub-test states: " + e);
264
+ }
259
265
  }
260
266
  if (code === 0) {
261
267
  resolve(true);
@@ -297,15 +303,48 @@ class QtTest {
297
303
  reject(error);
298
304
  }
299
305
  else {
300
- // A fail line is something like:
301
- // at: MyTest::testF() (/some/path/qttest-utils/test/qt_test/test2.cpp:13)
302
- const pattern = /at:\s+(.+?)::(.+?)\(\)\s+\((.+?):(\d+)\)/gm;
303
- const matches = Array.from(data.matchAll(pattern));
304
- const failedResults = matches.map((match) => ({
305
- name: match[2],
306
- filePath: match[3],
307
- lineNumber: parseInt(match[4]),
308
- }));
306
+ let failedResults = [];
307
+ try {
308
+ const tap_events = tap_parser_1.Parser.parse(data);
309
+ for (let event of tap_events) {
310
+ try {
311
+ if (event.length < 2)
312
+ continue;
313
+ if (event.at(0) != "assert")
314
+ continue;
315
+ var obj = event.at(1);
316
+ let pass = obj["ok"] === true;
317
+ let xfail = !pass && obj["todo"] !== false;
318
+ if (xfail) {
319
+ // This is a QEXPECT_FAIL test, all good.
320
+ // QtTest outputs it as "todo"
321
+ continue;
322
+ }
323
+ // There's an QEXPECT_FAIL but test passed, not good.
324
+ let xpass = pass && obj["todo"].includes("returned TRUE unexpectedly");
325
+ if (!pass || xpass) {
326
+ // We found a failure
327
+ var name = obj["name"].replace(/\(.*\)/, "");
328
+ var filename = "";
329
+ var lineNumber = -1;
330
+ if (obj["diag"]) {
331
+ filename = obj["diag"]["file"];
332
+ lineNumber = obj["diag"]["line"];
333
+ }
334
+ else {
335
+ // A XPASS for example misses file:line info. Nothing we can do, it's a Qt bug arguably.
336
+ }
337
+ failedResults.push({
338
+ name: name,
339
+ filePath: filename,
340
+ lineNumber: lineNumber,
341
+ });
342
+ }
343
+ }
344
+ catch (e) { }
345
+ }
346
+ }
347
+ catch (e) { }
309
348
  resolve(failedResults);
310
349
  }
311
350
  });
package/out/test.js CHANGED
@@ -57,8 +57,14 @@ function runTests(buildDirPath) {
57
57
  // 2. Test that the discovered slots are correct:
58
58
  yield qt.dumpTestSlots();
59
59
  let expected_slots = {
60
- "test/qt_test/build-dev/test1": ["testA", "testB", "testC"],
61
- "test/qt_test/build-dev/test2": ["testD", "testE", "testF"],
60
+ "test/qt_test/build-dev/test1": ["testA", "testB", "testC", "testXFAIL"],
61
+ "test/qt_test/build-dev/test2": [
62
+ "testD",
63
+ "testE",
64
+ "testF",
65
+ "testXPASS",
66
+ "testMixXFAILWithFAIL",
67
+ ],
62
68
  "test/qt_test/build-dev/test3": ["testAbortsEverythig", "testH", "testI"],
63
69
  };
64
70
  for (var executable of qt.qtTestExecutables) {
@@ -122,6 +128,39 @@ function runTests(buildDirPath) {
122
128
  console.error("Expected 0 executables, got " + executables.length);
123
129
  process.exit(1);
124
130
  }
131
+ // 6. Run a slot that has XFAIL
132
+ slot = qt.qtTestExecutables[0].slots[3];
133
+ if (slot.name != "testXFAIL") {
134
+ console.error("Expected slot name to be testXFAIL");
135
+ process.exit(1);
136
+ }
137
+ yield slot.runTest();
138
+ if (slot.lastTestFailure) {
139
+ console.error("Expected test to pass: " + slot.name);
140
+ process.exit(1);
141
+ }
142
+ // 7. Run a slot that has XPASS
143
+ slot = qt.qtTestExecutables[1].slots[3];
144
+ if (slot.name != "testXPASS") {
145
+ console.error("Expected slot name to be testXPASS");
146
+ process.exit(1);
147
+ }
148
+ yield slot.runTest();
149
+ if (!slot.lastTestFailure) {
150
+ console.error("Expected test to fail: " + slot.name);
151
+ process.exit(1);
152
+ }
153
+ // 8. Run a slot that has both XFAIL and FAIL
154
+ slot = qt.qtTestExecutables[1].slots[4];
155
+ if (slot.name != "testMixXFAILWithFAIL") {
156
+ console.error("Expected slot name to be testMixXFAILWithFAIL");
157
+ process.exit(1);
158
+ }
159
+ yield slot.runTest();
160
+ if (!slot.lastTestFailure) {
161
+ console.error("Expected test to fail: " + slot.name);
162
+ process.exit(1);
163
+ }
125
164
  });
126
165
  }
127
166
  function runCodeModelTests(codeModelFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "2.2.1",
3
+ "version": "2.3.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
  "repository": {
6
6
  "type": "git",
@@ -22,5 +22,8 @@
22
22
  "@types/node": "^18.15.0",
23
23
  "ts-node": "^10.9.1",
24
24
  "typescript": "^5.4.4"
25
+ },
26
+ "dependencies": {
27
+ "tap-parser": "^16.0.1"
25
28
  }
26
29
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "package-name": "",
5
+ "component": "",
6
+ "changelog-path": "Changelog",
7
+ "release-type": "node",
8
+ "bump-minor-pre-major": false,
9
+ "bump-patch-for-minor-pre-major": false,
10
+ "draft": false,
11
+ "prerelease": false,
12
+ "pull-request-title-pattern": "chore: Bump to v${version}"
13
+ }
14
+ },
15
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
16
+ }
package/test.sh ADDED
@@ -0,0 +1,7 @@
1
+ cmake --preset=dev -S test/qt_test && \
2
+ cmake --build test/qt_test/build-dev && \
3
+ tsc && node out/test.js && \
4
+ rm -rf test/qt_test/build-dev && \
5
+ cmake --preset=dev6 -S test/qt_test && \
6
+ cmake --build test/qt_test/build-dev && \
7
+ tsc && node out/test.js