Author: Ebuka Ezike Date: 2026-01-08T09:56:46Z New Revision: 2573c0bceef9e519a19aeb5381b72b5df38924d5
URL: https://github.com/llvm/llvm-project/commit/2573c0bceef9e519a19aeb5381b72b5df38924d5 DIFF: https://github.com/llvm/llvm-project/commit/2573c0bceef9e519a19aeb5381b72b5df38924d5.diff LOG: [lldb-dap][ext] Setup tests for lldb-dap extension (#174641) This add the basic unit test support for the dap-extension. It also - adds a .prettierignore file to exclude folder not to format. - Includes the test folder in when formatting. uses `vscode-test` from https://code.visualstudio.com/api/working-with-extensions/testing-extension#quick-setup-the-test-cli Follow up from https://github.com/llvm/llvm-project/pull/162635#discussion_r2486112688 Added: lldb/tools/lldb-dap/extension/.prettierignore lldb/tools/lldb-dap/extension/.vscode-test.mjs lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts Modified: lldb/tools/lldb-dap/extension/package.json lldb/tools/lldb-dap/extension/src/utils.ts lldb/tools/lldb-dap/extension/tsconfig.json Removed: ################################################################################ diff --git a/lldb/tools/lldb-dap/extension/.prettierignore b/lldb/tools/lldb-dap/extension/.prettierignore new file mode 100644 index 0000000000000..f553e11245428 --- /dev/null +++ b/lldb/tools/lldb-dap/extension/.prettierignore @@ -0,0 +1,9 @@ +# ignore build artefacts +node_folder/ +out/ +.vscode-test/ + +# user settings +.vscode + +package-lock.json diff --git a/lldb/tools/lldb-dap/extension/.vscode-test.mjs b/lldb/tools/lldb-dap/extension/.vscode-test.mjs new file mode 100644 index 0000000000000..bf53eda27f3d8 --- /dev/null +++ b/lldb/tools/lldb-dap/extension/.vscode-test.mjs @@ -0,0 +1,8 @@ +import { defineConfig } from "@vscode/test-cli"; + +export default defineConfig([ + { + label: "unitTests", + files: "out/test/unit/**/*.test.js", + }, +]); diff --git a/lldb/tools/lldb-dap/extension/package.json b/lldb/tools/lldb-dap/extension/package.json index 781ab65364bd4..bcc38aec260d6 100644 --- a/lldb/tools/lldb-dap/extension/package.json +++ b/lldb/tools/lldb-dap/extension/package.json @@ -33,11 +33,15 @@ "devDependencies": { "@types/node": "^18.19.41", "@types/tabulator-tables": "^6.2.10", + "@types/mocha": "^10.0.10", "@types/vscode": "1.75.0", "@types/vscode-webview": "^1.57.5", "@vscode/debugprotocol": "^1.68.0", + "@vscode/test-cli": "^0.0.12", + "@vscode/test-electron": "^2.5.2", "@vscode/vsce": "^3.2.2", "esbuild": "^0.25.9", + "mocha": "^10.2.0", "prettier": "^3.4.2", "prettier-plugin-curly": "^0.3.1", "prettier-plugin-organize-imports": "^4.3.0", @@ -56,9 +60,12 @@ "bundle-webview": "npm run bundle-symbols-table-view && npm run bundle-tabulator", "vscode:prepublish": "npm run bundle-webview && npm run bundle-extension", "watch": "npm run bundle-webview && tsc -watch -p ./", - "format": "npx prettier './src/' --write", + "format": "npx prettier . --write", "package": "rm -rf ./out && vsce package --out ./out/lldb-dap.vsix", + "compile": "tsc -p ./", "publish": "vsce publish", + "pretest": "npm run compile", + "test": "vscode-test", "vscode-uninstall": "code --uninstall-extension llvm-vs-code-extensions.lldb-dap", "vscode-install": "code --install-extension ./out/lldb-dap.vsix" }, diff --git a/lldb/tools/lldb-dap/extension/src/utils.ts b/lldb/tools/lldb-dap/extension/src/utils.ts index efebe0b0f42ba..310642175abae 100644 --- a/lldb/tools/lldb-dap/extension/src/utils.ts +++ b/lldb/tools/lldb-dap/extension/src/utils.ts @@ -5,7 +5,7 @@ import * as path from "path"; * Expands the character `~` to the user's home directory */ export function expandUser(file_path: string): string { - if (os.platform() == "win32") { + if (os.platform() === "win32") { return file_path; } @@ -18,22 +18,22 @@ export function expandUser(file_path: string): string { } const path_len = file_path.length; - if (path_len == 1) { + if (path_len === 1) { return os.homedir(); } - if (file_path.charAt(1) == path.sep) { + if (file_path.charAt(1) === path.sep) { return path.join(os.homedir(), file_path.substring(1)); } const sep_index = file_path.indexOf(path.sep); - const user_name_end = sep_index == -1 ? file_path.length : sep_index; + const user_name_end = sep_index === -1 ? file_path.length : sep_index; const user_name = file_path.substring(1, user_name_end); try { - if (user_name == os.userInfo().username) { + if (user_name === os.userInfo().username) { return path.join(os.homedir(), file_path.substring(user_name_end)); } - } catch (err) { + } catch (error) { return file_path; } diff --git a/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts b/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts new file mode 100644 index 0000000000000..566495ec19b66 --- /dev/null +++ b/lldb/tools/lldb-dap/extension/test/unit/expandUser.test.ts @@ -0,0 +1,44 @@ +import * as assert from "assert"; +import * as os from "os"; +import * as process from "process"; +import { expandUser } from "../../src/utils"; + +suite("expandUser Test", function () { + const home_env: { [key: string]: string | undefined } = {}; + const local_username = os.userInfo().username; + + suiteSetup(function () { + if (os.platform() === "win32") { + this.skip(); + } + home_env.HOME = process.env.HOME; + process.env.HOME = "/home/buildbot"; + }); + + suiteTeardown(function () { + process.env.HOME = home_env.HOME; + }); + + test("tilde ", function () { + assert.equal(expandUser("~"), "/home/buildbot"); + assert.equal(expandUser("~/"), "/home/buildbot/"); + assert.equal(expandUser("~/worker"), "/home/buildbot/worker"); + }); + + test("tilde with username", function () { + assert.equal(expandUser(`~${local_username}`), "/home/buildbot"); + assert.equal(expandUser(`~${local_username}/`), "/home/buildbot/"); + assert.equal(expandUser(`~${local_username}/dev`), "/home/buildbot/dev"); + + // test unknown user + assert.notEqual(expandUser("~not_a_user"), "/home/build/bot"); + }); + + test("empty", function () { + assert.equal(expandUser(""), ""); + }); + + test("no tilde", function () { + assert.equal(expandUser("/home/buildbot/worker"), "/home/buildbot/worker"); + }); +}); diff --git a/lldb/tools/lldb-dap/extension/tsconfig.json b/lldb/tools/lldb-dap/extension/tsconfig.json index c2d0f2d65a2ad..548fc0202e4d7 100644 --- a/lldb/tools/lldb-dap/extension/tsconfig.json +++ b/lldb/tools/lldb-dap/extension/tsconfig.json @@ -3,16 +3,11 @@ "moduleResolution": "node", "module": "commonjs", "outDir": "out", - "rootDir": "src", + "rootDir": ".", "sourceMap": true, "strict": true, "target": "es6" }, - "include": [ - "src" - ], - "exclude": [ - "node_modules", - "src/webview", - ] + "include": ["src", "test"], + "exclude": [".vscode-test", "node_modules", "src/webview"] } _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
