@iamsergio/qttest-utils 2.2.0 โ†’ 2.2.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/Changelog CHANGED
@@ -2,12 +2,44 @@
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
+
15
+ ## [2.2.1] - 2024-05-02
16
+
17
+ ### ๐Ÿ› Bug Fixes
18
+
19
+ - Fix running non-Qt tests
20
+ - Harden code against exception when reading .tap file
21
+
22
+ ### ๐Ÿงช Testing
23
+
24
+ - Try fixing tests on macOS/Windows
25
+ - Try harder to fix macOS/Windows tests
26
+
27
+ ### โš™๏ธ Miscellaneous Tasks
28
+
29
+ - Ran code format on tests
30
+ - Run codeformat on qttest.ts
31
+ - Bump version
32
+
5
33
  ## [2.2.0] - 2024-04-25
6
34
 
7
35
  ### ๐Ÿš€ Features
8
36
 
9
37
  - Allow to workaround microsoft/vscode-cmake-tools-api/issues/7
10
38
 
39
+ ### โš™๏ธ Miscellaneous Tasks
40
+
41
+ - Bump version
42
+
11
43
  ## [2.1.1] - 2024-04-25
12
44
 
13
45
  ### ๐Ÿ› Bug Fixes
package/out/cmake.js CHANGED
@@ -42,7 +42,9 @@ 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();
@@ -70,6 +72,20 @@ class CMakeTests {
70
72
  test.cwd = testJSON.cwd;
71
73
  return test;
72
74
  });
75
+ // filter invalid tests:
76
+ tests = tests.filter((test) => {
77
+ // pretty print test
78
+ if (!test.command || test.command.length == 0)
79
+ return false;
80
+ let testExecutablePath = test.executablePath();
81
+ let baseName = path_1.default.basename(testExecutablePath).toLowerCase();
82
+ if (baseName.endsWith(".exe"))
83
+ baseName = baseName.substring(0, baseName.length - 4);
84
+ // People doing complicated things in add_test()
85
+ if (baseName == "ctest" || baseName === "cmake")
86
+ return false;
87
+ return true;
88
+ });
73
89
  return tests;
74
90
  }
75
91
  /// Returns the cmake target name for the specified executable
@@ -122,7 +138,7 @@ class CMakeTests {
122
138
  // files aren't equal!
123
139
  return false;
124
140
  }
125
- const fs = require('fs');
141
+ const fs = require("fs");
126
142
  if (fs.existsSync(file2)) {
127
143
  // It's a real file, not bogus.
128
144
  return false;
@@ -178,7 +194,8 @@ class CMakeTests {
178
194
  }
179
195
  }
180
196
  }
181
- (0, qttest_1.logMessage)("cppFilesForExecutable: Could not find cpp files for executable " + executable);
197
+ (0, qttest_1.logMessage)("cppFilesForExecutable: Could not find cpp files for executable " +
198
+ executable);
182
199
  return [];
183
200
  }
184
201
  }
package/out/qttest.js CHANGED
@@ -102,7 +102,9 @@ class QtTest {
102
102
  reject(new Error("qttest: File doesn't exit: " + this.filename));
103
103
  return;
104
104
  }
105
- const child = (0, child_process_1.spawn)(this.filename, ["-functions"], { cwd: this.buildDirPath });
105
+ const child = (0, child_process_1.spawn)(this.filename, ["-functions"], {
106
+ cwd: this.buildDirPath,
107
+ });
106
108
  child.stdout.on("data", (chunk) => {
107
109
  output += chunk.toString();
108
110
  });
@@ -112,8 +114,8 @@ class QtTest {
112
114
  child.on("exit", (code) => {
113
115
  if (code === 0) {
114
116
  slotNames = slotNames.concat(output.split("\n"));
115
- slotNames = slotNames.map(entry => entry.trim().replace("()", ""));
116
- slotNames = slotNames.filter(entry => entry.length > 0);
117
+ slotNames = slotNames.map((entry) => entry.trim().replace("()", ""));
118
+ slotNames = slotNames.filter((entry) => entry.length > 0);
117
119
  if (slotNames.length > 0) {
118
120
  this.slots = [];
119
121
  for (var slotName of slotNames) {
@@ -124,7 +126,12 @@ class QtTest {
124
126
  resolve(slotNames);
125
127
  }
126
128
  else {
127
- reject(new Error("qttest: Failed to run -functions, stdout=" + output + "; stderr=" + err + "; code=" + code));
129
+ reject(new Error("qttest: Failed to run -functions, stdout=" +
130
+ output +
131
+ "; stderr=" +
132
+ err +
133
+ "; code=" +
134
+ code));
128
135
  }
129
136
  });
130
137
  });
@@ -150,7 +157,8 @@ class QtTest {
150
157
  let result = false;
151
158
  child.stdout.on("data", (chunk) => {
152
159
  if (!result) {
153
- if (chunk.toString().includes("libQt5Test.so") || chunk.toString().includes("libQt6Test.so")) {
160
+ if (chunk.toString().includes("libQt5Test.so") ||
161
+ chunk.toString().includes("libQt6Test.so")) {
154
162
  result = true;
155
163
  }
156
164
  }
@@ -219,7 +227,12 @@ class QtTest {
219
227
  args = args.concat("-o").concat("-,txt");
220
228
  return yield new Promise((resolve, reject) => {
221
229
  let cwdDir = cwd.length > 0 ? cwd : this.buildDirPath;
222
- logMessage("Running " + this.filename + " " + args.join(" ") + " with cwd=" + cwdDir);
230
+ logMessage("Running " +
231
+ this.filename +
232
+ " " +
233
+ args.join(" ") +
234
+ " with cwd=" +
235
+ cwdDir);
223
236
  const child = (0, child_process_1.spawn)(this.filename, args, { cwd: cwdDir });
224
237
  if (this.outputFunc) {
225
238
  // Callers wants the process output:
@@ -239,9 +252,16 @@ class QtTest {
239
252
  if (!slot) {
240
253
  this.lastExitCode = code;
241
254
  }
242
- /// When running a QtTest executable, let's check which sub-tests failed
243
- /// (So VSCode can show some error icon for each fail)
244
- yield this.updateSubTestStates(cwdDir, slot);
255
+ if (this.slots && this.slots.length > 0) {
256
+ /// When running a QtTest executable, let's check which sub-tests failed
257
+ /// (So VSCode can show some error icon for each fail)
258
+ try {
259
+ yield this.updateSubTestStates(cwdDir, slot);
260
+ }
261
+ catch (e) {
262
+ logMessage("Failed to update sub-test states: " + e);
263
+ }
264
+ }
245
265
  if (code === 0) {
246
266
  resolve(true);
247
267
  }
@@ -255,11 +275,11 @@ class QtTest {
255
275
  /// Using .tap so we don't have to use a separate XML library
256
276
  /// .tap is plain text and a single regexp can catch the failing tests and line number
257
277
  tapOutputFileName(slot) {
258
- let slotName = slot ? ("_" + slot.name) : "";
278
+ let slotName = slot ? "_" + slot.name : "";
259
279
  return this.label + slotName + ".tap";
260
280
  }
261
281
  txtOutputFileName(slot) {
262
- let slotName = slot ? ("_" + slot.name) : "";
282
+ let slotName = slot ? "_" + slot.name : "";
263
283
  return this.label + slotName + ".txt";
264
284
  }
265
285
  command() {
@@ -286,7 +306,7 @@ class QtTest {
286
306
  // at: MyTest::testF() (/some/path/qttest-utils/test/qt_test/test2.cpp:13)
287
307
  const pattern = /at:\s+(.+?)::(.+?)\(\)\s+\((.+?):(\d+)\)/gm;
288
308
  const matches = Array.from(data.matchAll(pattern));
289
- const failedResults = matches.map(match => ({
309
+ const failedResults = matches.map((match) => ({
290
310
  name: match[2],
291
311
  filePath: match[3],
292
312
  lineNumber: parseInt(match[4]),
@@ -332,7 +352,11 @@ class QtTestSlot {
332
352
  });
333
353
  }
334
354
  command() {
335
- return { label: this.name, executablePath: this.absoluteFilePath, args: [this.name] };
355
+ return {
356
+ label: this.name,
357
+ executablePath: this.absoluteFilePath,
358
+ args: [this.name],
359
+ };
336
360
  }
337
361
  }
338
362
  exports.QtTestSlot = QtTestSlot;
package/out/test.js CHANGED
@@ -23,19 +23,33 @@ function runTests(buildDirPath) {
23
23
  let expected_executables = [
24
24
  "test/qt_test/build-dev/test1",
25
25
  "test/qt_test/build-dev/test2",
26
- "test/qt_test/build-dev/test3"
26
+ "test/qt_test/build-dev/test3",
27
+ "test/qt_test/build-dev/non_qttest",
27
28
  ];
28
29
  if (qt.qtTestExecutables.length != expected_executables.length) {
29
30
  console.error("Expected 3 executables, got " + qt.qtTestExecutables.length);
30
31
  process.exit(1);
31
32
  }
32
33
  yield qt.removeNonLinking();
34
+ /// On macOS and Windows we don't have ldd or equivalent, so we can't check if the test links to QtTest
35
+ /// Use the help way instead
36
+ yield qt.removeByRunningHelp();
37
+ /// Remove the non-qttest executable from qt.qtTestExecutables
38
+ qt.qtTestExecutables = qt.qtTestExecutables.filter((e) => !e.filenameWithoutExtension().endsWith("non_qttest"));
39
+ if (qt.qtTestExecutables.length != 3) {
40
+ console.error("Expected 3 executables, at this point got " +
41
+ qt.qtTestExecutables.length);
42
+ process.exit(1);
43
+ }
33
44
  // 1. Test that the executable test names are correct:
34
45
  var i = 0;
35
46
  for (var executable of qt.qtTestExecutables) {
36
47
  let expected = expected_executables[i];
37
48
  if (executable.relativeFilename() != expected) {
38
- console.error("Expected executable " + expected + ", got " + executable.relativeFilename());
49
+ console.error("Expected executable " +
50
+ expected +
51
+ ", got " +
52
+ executable.relativeFilename());
39
53
  process.exit(1);
40
54
  }
41
55
  i++;
@@ -112,8 +126,8 @@ function runTests(buildDirPath) {
112
126
  }
113
127
  function runCodeModelTests(codeModelFile) {
114
128
  return __awaiter(this, void 0, void 0, function* () {
115
- const fs = require('fs');
116
- let codemodelStr = fs.readFileSync(codeModelFile, 'utf8');
129
+ const fs = require("fs");
130
+ let codemodelStr = fs.readFileSync(codeModelFile, "utf8");
117
131
  let codemodelJson = JSON.parse(codemodelStr);
118
132
  let cmake = new cmake_1.CMakeTests("random");
119
133
  let files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test1", codemodelJson);
@@ -144,27 +158,50 @@ function runCodeModelTests(codeModelFile) {
144
158
  process.exit(1);
145
159
  }
146
160
  // test workaround for microsoft/vscode-cmake-tools-api/issues/7
147
- files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ false);
161
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
162
+ /*workaround=*/ false);
148
163
  if (files.length !== 0) {
149
164
  console.error("Expected 0 files, got " + files.length);
150
165
  process.exit(1);
151
166
  }
152
- files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ true);
167
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
168
+ /*workaround=*/ true);
153
169
  if (files.length !== 1) {
154
170
  console.error("Expected 0 files, got " + files.length);
155
171
  process.exit(1);
156
172
  }
157
- targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ false);
173
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
174
+ /*workaround=*/ false);
158
175
  if (targetName) {
159
176
  console.error("Expected null, got " + targetName);
160
177
  process.exit(1);
161
178
  }
162
- targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ true);
179
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
180
+ /*workaround=*/ true);
163
181
  if (targetName != "test3") {
164
182
  console.error("Expected null, got " + targetName);
165
183
  process.exit(1);
166
184
  }
167
185
  });
168
186
  }
187
+ function runNonQtTest(buildDirPath) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ let qt = new qttest_1.QtTests();
190
+ yield qt.discoverViaCMake(buildDirPath);
191
+ var nonQtExecutable = undefined;
192
+ for (let executable of qt.qtTestExecutables) {
193
+ if (executable.filenameWithoutExtension().endsWith("non_qttest")) {
194
+ nonQtExecutable = executable;
195
+ break;
196
+ }
197
+ }
198
+ if (nonQtExecutable === undefined) {
199
+ console.error("Expected to find non-Qt test executable");
200
+ process.exit(1);
201
+ }
202
+ yield nonQtExecutable.runTest();
203
+ });
204
+ }
169
205
  runTests("test/qt_test/build-dev/");
206
+ runNonQtTest("test/qt_test/build-dev/");
170
207
  runCodeModelTests("test/test_cmake_codemodel.json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
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",