@iamsergio/qttest-utils 2.1.1 → 2.2.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/Changelog CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
 
4
4
 
5
+ ## [2.2.0] - 2024-04-25
6
+
7
+ ### 🚀 Features
8
+
9
+ - Allow to workaround microsoft/vscode-cmake-tools-api/issues/7
10
+
5
11
  ## [2.1.1] - 2024-04-25
6
12
 
7
13
  ### 🐛 Bug Fixes
@@ -11,6 +17,7 @@
11
17
  ### ⚙️ Miscellaneous Tasks
12
18
 
13
19
  - Improve CONTRIBUTING.md
20
+ - Bump version
14
21
 
15
22
  ## [2.1.0] - 2024-04-25
16
23
 
package/out/cmake.d.ts CHANGED
@@ -13,8 +13,9 @@ export declare class CMakeTests {
13
13
  */
14
14
  tests(): Promise<CMakeTest[] | undefined>;
15
15
  private ctestJsonToList;
16
- targetNameForExecutable(executable: string, codemodel: any): string | undefined;
17
- cppFilesForExecutable(executable: string, codemodel: any): string[];
16
+ targetNameForExecutable(executable: string, codemodel: any, workaround?: boolean): string | undefined;
17
+ filenamesAreEqual(file1: string, file2: string, workaround?: boolean): boolean;
18
+ cppFilesForExecutable(executable: string, codemodel: any, workaround?: boolean): string[];
18
19
  }
19
20
  export declare class CMakeTest {
20
21
  command: string[];
package/out/cmake.js CHANGED
@@ -74,13 +74,7 @@ class CMakeTests {
74
74
  }
75
75
  /// Returns the cmake target name for the specified executable
76
76
  /// codemodel should have a "projects" key at root.
77
- targetNameForExecutable(executable, codemodel) {
78
- // simplify:
79
- if (executable.endsWith(".exe")) {
80
- executable = executable.substring(0, executable.length - 4);
81
- }
82
- // replace backslashes with forward slashes
83
- executable = executable.replace(/\\/g, "/");
77
+ targetNameForExecutable(executable, codemodel, workaround = false) {
84
78
  let projects = codemodel["projects"];
85
79
  if (!projects)
86
80
  return undefined;
@@ -96,9 +90,7 @@ class CMakeTests {
96
90
  if (artifact.endsWith(".exe")) {
97
91
  artifact = artifact.substring(0, artifact.length - 4);
98
92
  }
99
- // replace backslashes with forward slashes
100
- artifact = artifact.replace(/\\/g, "/");
101
- if (artifact == executable) {
93
+ if (this.filenamesAreEqual(executable, artifact, workaround)) {
102
94
  let name = target["name"];
103
95
  if (name) {
104
96
  // We found the target name
@@ -110,16 +102,39 @@ class CMakeTests {
110
102
  }
111
103
  return undefined;
112
104
  }
105
+ /// Returns whether the two filenames are equal
106
+ /// If workaround is true, then we workaround microsoft/vscode-cmake-tools-api/issues/7 where
107
+ /// the basename is correct but the path is bogus, and we only compare the basenames
108
+ filenamesAreEqual(file1, file2, workaround = false) {
109
+ if (file1.endsWith(".exe"))
110
+ file1 = file1.substring(0, file1.length - 4);
111
+ if (file2.endsWith(".exe"))
112
+ file2 = file2.substring(0, file2.length - 4);
113
+ file1 = file1.replace(/\\/g, "/");
114
+ file2 = file2.replace(/\\/g, "/");
115
+ if (process.platform === "win32") {
116
+ file1 = file1.toLowerCase();
117
+ file2 = file2.toLowerCase();
118
+ }
119
+ if (file1 == file2)
120
+ return true;
121
+ if (!workaround) {
122
+ // files aren't equal!
123
+ return false;
124
+ }
125
+ const fs = require('fs');
126
+ if (fs.existsSync(file2)) {
127
+ // It's a real file, not bogus.
128
+ return false;
129
+ }
130
+ /// Compare only basename, since path is bogus
131
+ return path_1.default.basename(file1, ".exe") == path_1.default.basename(file2, ".exe");
132
+ }
113
133
  /// Returns the list of .cpp files for the specified executable
114
134
  /// codemodel is the CMake codemodel JSON object
115
135
  /// codemodel should have a "projects" key at root.
116
- cppFilesForExecutable(executable, codemodel) {
117
- // simplify:
118
- if (executable.endsWith(".exe")) {
119
- executable = executable.substring(0, executable.length - 4);
120
- }
121
- // replace backslashes with forward slashes
122
- executable = executable.replace(/\\/g, "/");
136
+ /// @param workaround If true, worksaround https://github.com/microsoft/vscode-cmake-tools-api/issues/7
137
+ cppFilesForExecutable(executable, codemodel, workaround = false) {
123
138
  let projects = codemodel["projects"];
124
139
  if (!projects)
125
140
  return [];
@@ -141,7 +156,7 @@ class CMakeTests {
141
156
  }
142
157
  // replace backslashes with forward slashes
143
158
  artifact = artifact.replace(/\\/g, "/");
144
- if (artifact == executable) {
159
+ if (this.filenamesAreEqual(executable, artifact, workaround)) {
145
160
  let fileGroups = target["fileGroups"];
146
161
  if (!fileGroups)
147
162
  continue;
package/out/test.js CHANGED
@@ -143,6 +143,27 @@ function runCodeModelTests(codeModelFile) {
143
143
  console.error("Expected test2, got " + targetName);
144
144
  process.exit(1);
145
145
  }
146
+ // 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);
148
+ if (files.length !== 0) {
149
+ console.error("Expected 0 files, got " + files.length);
150
+ process.exit(1);
151
+ }
152
+ files = cmake.cppFilesForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ true);
153
+ if (files.length !== 1) {
154
+ console.error("Expected 0 files, got " + files.length);
155
+ process.exit(1);
156
+ }
157
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ false);
158
+ if (targetName) {
159
+ console.error("Expected null, got " + targetName);
160
+ process.exit(1);
161
+ }
162
+ targetName = cmake.targetNameForExecutable("/vscode-qttest/test/qt_test/build-dev/test3", codemodelJson, /*workaround=*/ true);
163
+ if (targetName != "test3") {
164
+ console.error("Expected null, got " + targetName);
165
+ process.exit(1);
166
+ }
146
167
  });
147
168
  }
148
169
  runTests("test/qt_test/build-dev/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamsergio/qttest-utils",
3
- "version": "2.1.1",
3
+ "version": "2.2.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",