@iamsergio/qttest-utils 2.2.2 → 2.5.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/out/test.js CHANGED
@@ -2,205 +2,229 @@
2
2
  // SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3
3
  // Author: Sergio Martins <sergio.martins@kdab.com>
4
4
  // SPDX-License-Identifier: MIT
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  const cmake_1 = require("./cmake");
16
7
  const qttest_1 = require("./qttest");
17
8
  // Be sure to build the Qt tests with CMake first
18
9
  // See .github/workflows/ci.yml
19
- function runTests(buildDirPath) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- let qt = new qttest_1.QtTests();
22
- yield qt.discoverViaCMake(buildDirPath);
23
- let expected_executables = [
24
- "test/qt_test/build-dev/test1",
25
- "test/qt_test/build-dev/test2",
26
- "test/qt_test/build-dev/test3",
27
- "test/qt_test/build-dev/non_qttest",
28
- ];
29
- if (qt.qtTestExecutables.length != expected_executables.length) {
30
- console.error("Expected 3 executables, got " + qt.qtTestExecutables.length);
31
- process.exit(1);
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
- }
44
- // 1. Test that the executable test names are correct:
45
- var i = 0;
46
- for (var executable of qt.qtTestExecutables) {
47
- let expected = expected_executables[i];
48
- if (executable.relativeFilename() != expected) {
49
- console.error("Expected executable " +
50
- expected +
51
- ", got " +
52
- executable.relativeFilename());
53
- process.exit(1);
54
- }
55
- i++;
56
- }
57
- // 2. Test that the discovered slots are correct:
58
- yield qt.dumpTestSlots();
59
- let expected_slots = {
60
- "test/qt_test/build-dev/test1": ["testA", "testB", "testC"],
61
- "test/qt_test/build-dev/test2": ["testD", "testE", "testF"],
62
- "test/qt_test/build-dev/test3": ["testAbortsEverythig", "testH", "testI"],
63
- };
64
- for (var executable of qt.qtTestExecutables) {
65
- var i = 0;
66
- for (let slot of executable.slots) {
67
- let expected_slot = expected_slots[executable.relativeFilename()][i];
68
- if (slot.name != expected_slot) {
69
- console.error("Expected slot " + expected_slot + ", got " + slot.name);
70
- process.exit(1);
71
- }
72
- i++;
73
- }
74
- }
75
- // 3. Run the tests:
76
- let expected_success = [true, false, false];
10
+ async function runTests(buildDirPath) {
11
+ let qt = new qttest_1.QtTests();
12
+ await qt.discoverViaCMake(buildDirPath);
13
+ let expected_executables = [
14
+ "test/qt_test/build-dev/test1",
15
+ "test/qt_test/build-dev/test2",
16
+ "test/qt_test/build-dev/test3",
17
+ "test/qt_test/build-dev/non_qttest",
18
+ ];
19
+ if (qt.qtTestExecutables.length != expected_executables.length) {
20
+ console.error("Expected 3 executables, got " + qt.qtTestExecutables.length);
21
+ process.exit(1);
22
+ }
23
+ await qt.removeNonLinking();
24
+ /// On macOS and Windows we don't have ldd or equivalent, so we can't check if the test links to QtTest
25
+ /// Use the help way instead
26
+ await qt.removeByRunningHelp();
27
+ /// Remove the non-qttest executable from qt.qtTestExecutables
28
+ qt.qtTestExecutables = qt.qtTestExecutables.filter((e) => !e.filenameWithoutExtension().endsWith("non_qttest"));
29
+ if (qt.qtTestExecutables.length != 3) {
30
+ console.error("Expected 3 executables, at this point got " +
31
+ qt.qtTestExecutables.length);
32
+ process.exit(1);
33
+ }
34
+ // 1. Test that the executable test names are correct:
35
+ var i = 0;
36
+ for (var executable of qt.qtTestExecutables) {
37
+ let expected = expected_executables[i];
38
+ if (executable.relativeFilename() != expected) {
39
+ console.error("Expected executable " +
40
+ expected +
41
+ ", got " +
42
+ executable.relativeFilename());
43
+ process.exit(1);
44
+ }
45
+ i++;
46
+ }
47
+ // 2. Test that the discovered slots are correct:
48
+ await qt.dumpTestSlots();
49
+ let expected_slots = {
50
+ "test/qt_test/build-dev/test1": ["testA", "testB", "testC", "testXFAIL"],
51
+ "test/qt_test/build-dev/test2": [
52
+ "testD",
53
+ "testE",
54
+ "testF",
55
+ "testXPASS",
56
+ "testMixXFAILWithFAIL",
57
+ ],
58
+ "test/qt_test/build-dev/test3": ["testAbortsEverythig", "testH", "testI"],
59
+ };
60
+ for (var executable of qt.qtTestExecutables) {
77
61
  var i = 0;
78
- for (var executable of qt.qtTestExecutables) {
79
- yield executable.runTest();
80
- let wasSuccess = executable.lastExitCode === 0;
81
- if (wasSuccess && !expected_success[i]) {
82
- console.error("Expected test to fail: " + executable.filename);
62
+ for (let slot of executable.slots) {
63
+ let expected_slot = expected_slots[executable.relativeFilename()][i];
64
+ if (slot.name != expected_slot) {
65
+ console.error("Expected slot " + expected_slot + ", got " + slot.name);
83
66
  process.exit(1);
84
67
  }
85
- else if (!wasSuccess && expected_success[i]) {
86
- console.error("Expected test to pass: " + executable.filename);
87
- process.exit(1);
88
- }
89
- if (process.platform === "linux") {
90
- if (!executable.linksToQtTestLib()) {
91
- console.error("Expected test to link to QtTest: " + executable.filename);
92
- process.exit(1);
93
- }
94
- }
95
68
  i++;
96
69
  }
97
- // 4. Run individual slots:
98
- let slot = qt.qtTestExecutables[0].slots[0];
99
- yield slot.runTest();
100
- if (slot.lastTestFailure) {
101
- console.error("Expected test to pass: " + slot.name);
70
+ }
71
+ // 3. Run the tests:
72
+ let expected_success = [true, false, false];
73
+ var i = 0;
74
+ for (var executable of qt.qtTestExecutables) {
75
+ await executable.runTest();
76
+ let wasSuccess = executable.lastExitCode === 0;
77
+ if (wasSuccess && !expected_success[i]) {
78
+ console.error("Expected test to fail: " + executable.filename);
102
79
  process.exit(1);
103
80
  }
104
- let slot2 = qt.qtTestExecutables[1].slots[2];
105
- yield slot2.runTest();
106
- if (!slot2.lastTestFailure) {
107
- console.error("Expected test to fail: " + slot2.name);
81
+ else if (!wasSuccess && expected_success[i]) {
82
+ console.error("Expected test to pass: " + executable.filename);
108
83
  process.exit(1);
109
84
  }
110
- // 5. Test executablesContainingSlot
111
- let executables = qt.executablesContainingSlot("testB");
112
- if (executables.length != 1) {
113
- console.error("Expected 1 executable, got " + executables.length);
114
- process.exit(1);
115
- }
116
- if (!executables[0].filenameWithoutExtension().endsWith("test1")) {
117
- console.error("Expected filename to end with test1");
118
- process.exit(1);
119
- }
120
- executables = qt.executablesContainingSlot("non_existing");
121
- if (executables.length != 0) {
122
- console.error("Expected 0 executables, got " + executables.length);
123
- process.exit(1);
85
+ if (process.platform === "linux") {
86
+ if (!executable.linksToQtTestLib()) {
87
+ console.error("Expected test to link to QtTest: " + executable.filename);
88
+ process.exit(1);
89
+ }
124
90
  }
125
- });
91
+ i++;
92
+ }
93
+ // 4. Run individual slots:
94
+ let slot = qt.qtTestExecutables[0].slots[0];
95
+ await slot.runTest();
96
+ if (slot.lastTestFailure) {
97
+ console.error("Expected test to pass: " + slot.name);
98
+ process.exit(1);
99
+ }
100
+ let slot2 = qt.qtTestExecutables[1].slots[2];
101
+ await slot2.runTest();
102
+ if (!slot2.lastTestFailure) {
103
+ console.error("Expected test to fail: " + slot2.name);
104
+ process.exit(1);
105
+ }
106
+ // 5. Test executablesContainingSlot
107
+ let executables = qt.executablesContainingSlot("testB");
108
+ if (executables.length != 1) {
109
+ console.error("Expected 1 executable, got " + executables.length);
110
+ process.exit(1);
111
+ }
112
+ if (!executables[0].filenameWithoutExtension().endsWith("test1")) {
113
+ console.error("Expected filename to end with test1");
114
+ process.exit(1);
115
+ }
116
+ executables = qt.executablesContainingSlot("non_existing");
117
+ if (executables.length != 0) {
118
+ console.error("Expected 0 executables, got " + executables.length);
119
+ process.exit(1);
120
+ }
121
+ // 6. Run a slot that has XFAIL
122
+ slot = qt.qtTestExecutables[0].slots[3];
123
+ if (slot.name != "testXFAIL") {
124
+ console.error("Expected slot name to be testXFAIL");
125
+ process.exit(1);
126
+ }
127
+ await slot.runTest();
128
+ if (slot.lastTestFailure) {
129
+ console.error("Expected test to pass: " + slot.name);
130
+ process.exit(1);
131
+ }
132
+ // 7. Run a slot that has XPASS
133
+ slot = qt.qtTestExecutables[1].slots[3];
134
+ if (slot.name != "testXPASS") {
135
+ console.error("Expected slot name to be testXPASS");
136
+ process.exit(1);
137
+ }
138
+ await slot.runTest();
139
+ if (!slot.lastTestFailure) {
140
+ console.error("Expected test to fail: " + slot.name);
141
+ process.exit(1);
142
+ }
143
+ // 8. Run a slot that has both XFAIL and FAIL
144
+ slot = qt.qtTestExecutables[1].slots[4];
145
+ if (slot.name != "testMixXFAILWithFAIL") {
146
+ console.error("Expected slot name to be testMixXFAILWithFAIL");
147
+ process.exit(1);
148
+ }
149
+ await slot.runTest();
150
+ if (!slot.lastTestFailure) {
151
+ console.error("Expected test to fail: " + slot.name);
152
+ process.exit(1);
153
+ }
126
154
  }
127
- function runCodeModelTests(codeModelFile) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- const fs = require("fs");
130
- let codemodelStr = fs.readFileSync(codeModelFile, "utf8");
131
- let codemodelJson = JSON.parse(codemodelStr);
132
- let cmake = new cmake_1.CMakeTests("random");
133
- let files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test1", codemodelJson);
134
- if (files.length != 1) {
135
- console.error("Expected 1 file, got " + files.length);
136
- process.exit(1);
137
- }
138
- let expected = "/vscode-qttest/test/qt_test/test1.cpp";
139
- let got = files[0].replace(/\\/g, "/");
140
- if (got != expected) {
141
- console.error("Expected " + expected + ", got " + got);
142
- process.exit(1);
143
- }
144
- let targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test1", codemodelJson);
145
- if (targetName != "test1") {
146
- console.error("Expected test1, got " + targetName);
147
- process.exit(1);
148
- }
149
- // test windows back slashes:
150
- files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test2", codemodelJson);
151
- if (files.length != 1) {
152
- console.error("Expected 1 file, got " + files.length);
153
- process.exit(1);
154
- }
155
- targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test2", codemodelJson);
156
- if (targetName != "test2") {
157
- console.error("Expected test2, got " + targetName);
158
- process.exit(1);
159
- }
160
- // test workaround for microsoft/vscode-cmake-tools-api/issues/7
161
- files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
162
- /*workaround=*/ false);
163
- if (files.length !== 0) {
164
- console.error("Expected 0 files, got " + files.length);
165
- process.exit(1);
166
- }
167
- files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
168
- /*workaround=*/ true);
169
- if (files.length !== 1) {
170
- console.error("Expected 0 files, got " + files.length);
171
- process.exit(1);
172
- }
173
- targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
174
- /*workaround=*/ false);
175
- if (targetName) {
176
- console.error("Expected null, got " + targetName);
177
- process.exit(1);
178
- }
179
- targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
180
- /*workaround=*/ true);
181
- if (targetName != "test3") {
182
- console.error("Expected null, got " + targetName);
183
- process.exit(1);
184
- }
185
- });
155
+ async function runCodeModelTests(codeModelFile) {
156
+ const fs = require("fs");
157
+ let codemodelStr = fs.readFileSync(codeModelFile, "utf8");
158
+ let codemodelJson = JSON.parse(codemodelStr);
159
+ let cmake = new cmake_1.CMakeTests("random");
160
+ let files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test1", codemodelJson);
161
+ if (files.length != 1) {
162
+ console.error("Expected 1 file, got " + files.length);
163
+ process.exit(1);
164
+ }
165
+ let expected = "/vscode-qttest/test/qt_test/test1.cpp";
166
+ let got = files[0].replace(/\\/g, "/");
167
+ if (got != expected) {
168
+ console.error("Expected " + expected + ", got " + got);
169
+ process.exit(1);
170
+ }
171
+ let targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test1", codemodelJson);
172
+ if (targetName != "test1") {
173
+ console.error("Expected test1, got " + targetName);
174
+ process.exit(1);
175
+ }
176
+ // test windows back slashes:
177
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test2", codemodelJson);
178
+ if (files.length != 1) {
179
+ console.error("Expected 1 file, got " + files.length);
180
+ process.exit(1);
181
+ }
182
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test2", codemodelJson);
183
+ if (targetName != "test2") {
184
+ console.error("Expected test2, got " + targetName);
185
+ process.exit(1);
186
+ }
187
+ // test workaround for microsoft/vscode-cmake-tools-api/issues/7
188
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
189
+ /*workaround=*/ false);
190
+ if (files.length !== 0) {
191
+ console.error("Expected 0 files, got " + files.length);
192
+ process.exit(1);
193
+ }
194
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
195
+ /*workaround=*/ true);
196
+ if (files.length !== 1) {
197
+ console.error("Expected 0 files, got " + files.length);
198
+ process.exit(1);
199
+ }
200
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
201
+ /*workaround=*/ false);
202
+ if (targetName) {
203
+ console.error("Expected null, got " + targetName);
204
+ process.exit(1);
205
+ }
206
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson,
207
+ /*workaround=*/ true);
208
+ if (targetName != "test3") {
209
+ console.error("Expected null, got " + targetName);
210
+ process.exit(1);
211
+ }
186
212
  }
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
- });
213
+ async function runNonQtTest(buildDirPath) {
214
+ let qt = new qttest_1.QtTests();
215
+ await qt.discoverViaCMake(buildDirPath);
216
+ var nonQtExecutable = undefined;
217
+ for (let executable of qt.qtTestExecutables) {
218
+ if (executable.filenameWithoutExtension().endsWith("non_qttest")) {
219
+ nonQtExecutable = executable;
220
+ break;
221
+ }
222
+ }
223
+ if (nonQtExecutable === undefined) {
224
+ console.error("Expected to find non-Qt test executable");
225
+ process.exit(1);
226
+ }
227
+ await nonQtExecutable.runTest();
204
228
  }
205
229
  runTests("test/qt_test/build-dev/");
206
230
  runNonQtTest("test/qt_test/build-dev/");
package/out/utils.js CHANGED
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  }) : function(o, v) {
19
19
  o["default"] = v;
20
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
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
40
  };
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "2.2.2",
3
+ "version": "2.5.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",
7
- "url": "https://github.com/KDAB/qttest-utils.git"
7
+ "url": "git+https://github.com/KDAB/qttest-utils.git"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc"
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build"
11
12
  },
12
13
  "main": "out/index.js",
13
14
  "typings": "./out/index.d.ts",
15
+ "files": [
16
+ "out/*.js",
17
+ "out/*.d.ts",
18
+ "README.md",
19
+ "CHANGELOG.md"
20
+ ],
14
21
  "keywords": [
15
22
  "KDAB",
16
23
  "QtTest",
@@ -18,9 +25,15 @@
18
25
  ],
19
26
  "author": "sergio.martins@kdab.com",
20
27
  "license": "MIT",
28
+ "engines": {
29
+ "node": ">=22.0.0"
30
+ },
21
31
  "devDependencies": {
22
- "@types/node": "^18.15.0",
23
- "ts-node": "^10.9.1",
24
- "typescript": "^5.4.4"
32
+ "@types/node": "^22.0.0",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.7.2"
35
+ },
36
+ "dependencies": {
37
+ "tap-parser": "^16.0.1"
25
38
  }
26
39
  }
package/CONTRIBUTING.md DELETED
@@ -1,34 +0,0 @@
1
- # Tips for contributors
2
-
3
- ## Prepare your development environment
4
-
5
- Just follow `.devcontainer/Dockerfile` to see what's needed.<br?>
6
- Basically it's just `nodejs` >= v18 `tsc` and `npm`. <br>
7
- Qt5, cmake and ninja if you want to run the tests.
8
-
9
-
10
- ## Running tests
11
-
12
- ```bash
13
- tsc
14
- node out/test.js
15
- ```
16
-
17
- Or simply let GitHub actions run the tests for you.<br>
18
- See `ci.yml` for how we run the tests.
19
-
20
- ## Install git-cliff
21
-
22
- ```bash
23
- cargo install git-cliff
24
- ```
25
-
26
- ## Releasing
27
-
28
- (Replace 1.0.0 with actual version used)
29
- - Get a version compatible with semver, run ` git cliff --bump | head -n 5`, replace NEW_VERSION
30
- - export NEW_VERSION=v1.0.0
31
- - Make sure Github Actions CI is green
32
- - npm version $NEW_VERSION # ignore the error
33
- - git cliff --tag $NEW_VERSION > Changelog
34
- - git add Changelog package.json package-lock.json && git commit -m "chore: bump version" && git tag -a ${NEW_VERSION} -m "${NEW_VERSION}" && git push && git push --tags && npm publish