@iamsergio/qttest-utils 0.4.1 → 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/utils.js CHANGED
@@ -1,85 +1,85 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- const path_1 = __importDefault(require("path"));
33
- const fs = __importStar(require("fs"));
34
- /// Returns whether the specified file is an executable
35
- function isExecutable(filePath) {
36
- if (process.platform === "win32") {
37
- return path_1.default.extname(filePath).toLocaleLowerCase() === ".exe";
38
- }
39
- else {
40
- try {
41
- fs.accessSync(filePath, fs.constants.X_OK);
42
- return true;
43
- }
44
- catch (err) {
45
- return false;
46
- }
47
- }
48
- }
49
- /// Returns whether the specified file is a library
50
- function isLibrary(filename) {
51
- const split = filename.split(".");
52
- if (split.length <= 1) {
53
- return false;
54
- }
55
- // Find the first non-numeric extension, so we ignore all the trailing numbers in libFoo.so.2.0.9
56
- for (var i = split.length - 1; i >= 0; --i) {
57
- const extension = split[i];
58
- const isNumber = !isNaN(Number(extension));
59
- if (isNumber) {
60
- continue;
61
- }
62
- return ["so", "dll", "dylib"].includes(extension);
63
- }
64
- return false;
65
- }
66
- /// Recursively looks for executable files in folderPath
67
- function executableFiles(folderPath) {
68
- const files = fs.readdirSync(folderPath);
69
- var executables = [];
70
- for (var file of files) {
71
- // Ignore CMakeFiles directory, it has some of binaries
72
- if (path_1.default.basename(file) === "CMakeFiles") {
73
- continue;
74
- }
75
- const childPath = path_1.default.join(folderPath, file);
76
- const info = fs.statSync(childPath);
77
- if (info.isDirectory()) {
78
- executables = executables.concat(executableFiles(childPath));
79
- }
80
- else if (info.isFile() && !isLibrary(path_1.default.basename(childPath)) && isExecutable(childPath)) {
81
- executables.push(childPath);
82
- }
83
- }
84
- return executables;
85
- }
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 __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ const path_1 = __importDefault(require("path"));
33
+ const fs = __importStar(require("fs"));
34
+ /// Returns whether the specified file is an executable
35
+ function isExecutable(filePath) {
36
+ if (process.platform === "win32") {
37
+ return path_1.default.extname(filePath).toLocaleLowerCase() === ".exe";
38
+ }
39
+ else {
40
+ try {
41
+ fs.accessSync(filePath, fs.constants.X_OK);
42
+ return true;
43
+ }
44
+ catch (err) {
45
+ return false;
46
+ }
47
+ }
48
+ }
49
+ /// Returns whether the specified file is a library
50
+ function isLibrary(filename) {
51
+ const split = filename.split(".");
52
+ if (split.length <= 1) {
53
+ return false;
54
+ }
55
+ // Find the first non-numeric extension, so we ignore all the trailing numbers in libFoo.so.2.0.9
56
+ for (var i = split.length - 1; i >= 0; --i) {
57
+ const extension = split[i];
58
+ const isNumber = !isNaN(Number(extension));
59
+ if (isNumber) {
60
+ continue;
61
+ }
62
+ return ["so", "dll", "dylib"].includes(extension);
63
+ }
64
+ return false;
65
+ }
66
+ /// Recursively looks for executable files in folderPath
67
+ function executableFiles(folderPath) {
68
+ const files = fs.readdirSync(folderPath);
69
+ var executables = [];
70
+ for (var file of files) {
71
+ // Ignore CMakeFiles directory, it has some of binaries
72
+ if (path_1.default.basename(file) === "CMakeFiles") {
73
+ continue;
74
+ }
75
+ const childPath = path_1.default.join(folderPath, file);
76
+ const info = fs.statSync(childPath);
77
+ if (info.isDirectory()) {
78
+ executables = executables.concat(executableFiles(childPath));
79
+ }
80
+ else if (info.isFile() && !isLibrary(path_1.default.basename(childPath)) && isExecutable(childPath)) {
81
+ executables.push(childPath);
82
+ }
83
+ }
84
+ return executables;
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "0.4.1",
3
+ "version": "0.4.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
  "scripts": {
6
6
  "build": "tsc"
package/src/qttest.ts CHANGED
@@ -44,7 +44,7 @@ export class QtTest {
44
44
  return;
45
45
  }
46
46
 
47
- const child = spawn(this.filename, ["-functions"]);
47
+ const child = spawn(this.filename, ["-functions"], {cwd: this.buildDirPath});
48
48
 
49
49
  child.stdout.on("data", (chunk) => {
50
50
  output += chunk.toString();
package/out/ctest.d.ts DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Represents cmake's CTest
3
- *
4
- * Contains methods to discover Qt Tests
5
- */
6
- export declare class CTest {
7
- readonly buildDirPath: string;
8
- constructor(buildDirPath: string);
9
- /**
10
- * Invokes ctest.exe --show-only=json-v1
11
- *
12
- * @returns a promise with the list of tests
13
- */
14
- ctestTests(): Promise<CTestTest[] | undefined>;
15
- private ctestJsonToList;
16
- }
17
- export declare class CTestTest {
18
- command: string[];
19
- cwd: string;
20
- id(): string;
21
- label(): string;
22
- executablePath(): string;
23
- }
package/out/ctest.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CTestTest = exports.CTest = void 0;
16
- const child_process_1 = require("child_process");
17
- const path_1 = __importDefault(require("path"));
18
- /**
19
- * Represents cmake's CTest
20
- *
21
- * Contains methods to discover Qt Tests
22
- */
23
- class CTest {
24
- constructor(buildDirPath) {
25
- this.buildDirPath = buildDirPath;
26
- }
27
- /**
28
- * Invokes ctest.exe --show-only=json-v1
29
- *
30
- * @returns a promise with the list of tests
31
- */
32
- ctestTests() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- // TODO: Check if folder exists
35
- if (this.buildDirPath.length == 0) {
36
- console.error("Could not find out cmake build dir");
37
- return undefined;
38
- }
39
- return new Promise((resolve, reject) => {
40
- const child = (0, child_process_1.spawn)("ctest", ["--show-only=json-v1"], { "cwd": this.buildDirPath });
41
- let output = "";
42
- child.stdout.on("data", (chunk) => {
43
- output += chunk.toString();
44
- });
45
- child.on("exit", (code) => {
46
- if (code === 0) {
47
- resolve(this.ctestJsonToList(output));
48
- }
49
- else {
50
- reject(new Error("Failed to run ctest"));
51
- }
52
- });
53
- return undefined;
54
- });
55
- });
56
- }
57
- ctestJsonToList(json) {
58
- let allJSON = JSON.parse(json);
59
- if (!("tests" in allJSON)) {
60
- return [];
61
- }
62
- let tests = allJSON.tests.map((testJSON) => {
63
- let test = new CTestTest();
64
- test.command = testJSON.command;
65
- test.cwd = testJSON.cwd;
66
- return test;
67
- });
68
- return tests;
69
- }
70
- }
71
- exports.CTest = CTest;
72
- /// Represents an inividual CTest test
73
- class CTestTest {
74
- constructor() {
75
- this.command = [];
76
- this.cwd = "";
77
- }
78
- id() {
79
- return this.command.join(",");
80
- }
81
- label() {
82
- return path_1.default.basename(this.executablePath());
83
- }
84
- executablePath() {
85
- return this.command[0];
86
- }
87
- }
88
- exports.CTestTest = CTestTest;
package/out/foo.d.ts DELETED
File without changes
package/out/foo.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- console.log("");
package/out/runtests.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/out/runtests.js DELETED
@@ -1,26 +0,0 @@
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 __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
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const qttest_1 = require("./qttest");
16
- function run_tests(buildPath) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- let qt = new qttest_1.QtTests();
19
- yield qt.discoverViaCMake(buildPath);
20
- yield qt.removeNonLinking();
21
- for (var testExecutable of qt.qtTestExacutables) {
22
- console.log(testExecutable.filename);
23
- }
24
- });
25
- }
26
- run_tests("/data/sources/kddockwidgets/build-dev");