From 60e815d403f54ec26d7738fe6aea9c0d2726d4a6 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Wed, 25 Oct 2023 16:18:52 +0900 Subject: [PATCH] Clean up tests Signed-off-by: Sora Morimoto --- .github/workflows/main.yml | 2 - .prettierignore | 4 +- dune | 2 +- package.json | 9 +-- test/dune | 1 - test/runEsyTests.js | 47 --------------- test/suite/esy.js | 39 ------------ test/suite/esy.test.js | 40 ------------- test/suite/opam.js | 39 ------------ test/suite/opam.test.js | 55 ----------------- test/suite/problems.js | 39 ------------ {test => tests}/fixtures/dune | 0 .../fixtures/sample-esy/.gitignore | 0 .../fixtures/sample-esy/.vscode/settings.json | 0 .../fixtures/sample-esy/bin/CamlUtil.ml | 0 .../fixtures/sample-esy/bin/CamlUtil.mli | 0 .../fixtures/sample-esy/bin/SampleEsyApp.ml | 0 {test => tests}/fixtures/sample-esy/bin/dune | 0 .../fixtures/sample-esy/dune-project | 0 {test => tests}/fixtures/sample-esy/esy.json | 0 .../sample-esy/esy.lock/.gitattributes | 0 .../fixtures/sample-esy/esy.lock/.gitignore | 0 .../fixtures/sample-esy/esy.lock/index.json | 0 .../esy.lock/opam/base-threads.base/opam | 0 .../esy.lock/opam/base-unix.base/opam | 0 .../esy.lock/opam/biniou.1.2.1/opam | 0 .../sample-esy/esy.lock/opam/cppo.1.6.8/opam | 0 .../sample-esy/esy.lock/opam/csexp.1.5.1/opam | 0 .../esy.lock/opam/dune-build-info.2.9.1/opam | 0 .../sample-esy/esy.lock/opam/dune.2.9.1/opam | 0 .../esy.lock/opam/easy-format.1.3.2/opam | 0 .../esy.lock/opam/ocaml-lsp-server.1.9.0/opam | 0 .../opam/ocamlformat-rpc-lib.0.19.0/opam | 0 .../sample-esy/esy.lock/opam/pp.1.1.2/opam | 0 .../opam/ppx_yojson_conv_lib.v0.14.0/opam | 0 .../sample-esy/esy.lock/opam/re.1.10.3/opam | 0 .../sample-esy/esy.lock/opam/result.1.5/opam | 0 .../esy.lock/opam/seq.base/files/META.seq | 0 .../esy.lock/opam/seq.base/files/seq.install | 0 .../sample-esy/esy.lock/opam/seq.base/opam | 0 .../esy.lock/opam/sexplib0.v0.14.0/opam | 0 .../esy.lock/opam/spawn.v0.14.0/opam | 0 .../esy.lock/opam/yojson.1.7.0/opam | 0 .../fixtures/sample-esy/sample-esy.opam | 0 {test => tests}/fixtures/sample-opam/foo.ml | 0 {test => tests}/fixtures/sample-opam/main.ml | 0 .../fixtures/sample-opam/sample-opam.opam | 5 +- .../runBasicTests.js | 10 +--- tests/runEsyTests.js | 23 ++++++++ {test => tests}/runOpamTests.js | 8 +-- tests/suite/basic/index.js | 32 ++++++++++ .../suite/basic}/problems.test.js | 10 ++-- tests/suite/esy/index.js | 32 ++++++++++ tests/suite/esy/languageId.test.js | 58 ++++++++++++++++++ tests/suite/opam/index.js | 32 ++++++++++ tests/suite/opam/languageId.test.js | 59 +++++++++++++++++++ yarn.lock | 31 +++++----- 57 files changed, 271 insertions(+), 306 deletions(-) delete mode 100644 test/dune delete mode 100644 test/runEsyTests.js delete mode 100644 test/suite/esy.js delete mode 100644 test/suite/esy.test.js delete mode 100644 test/suite/opam.js delete mode 100644 test/suite/opam.test.js delete mode 100644 test/suite/problems.js rename {test => tests}/fixtures/dune (100%) rename {test => tests}/fixtures/sample-esy/.gitignore (100%) rename {test => tests}/fixtures/sample-esy/.vscode/settings.json (100%) rename {test => tests}/fixtures/sample-esy/bin/CamlUtil.ml (100%) rename {test => tests}/fixtures/sample-esy/bin/CamlUtil.mli (100%) rename {test => tests}/fixtures/sample-esy/bin/SampleEsyApp.ml (100%) rename {test => tests}/fixtures/sample-esy/bin/dune (100%) rename {test => tests}/fixtures/sample-esy/dune-project (100%) rename {test => tests}/fixtures/sample-esy/esy.json (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/.gitattributes (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/.gitignore (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/index.json (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/base-threads.base/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/base-unix.base/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/biniou.1.2.1/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/cppo.1.6.8/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/csexp.1.5.1/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/dune-build-info.2.9.1/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/dune.2.9.1/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/easy-format.1.3.2/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/ocaml-lsp-server.1.9.0/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/pp.1.1.2/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/re.1.10.3/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/result.1.5/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/seq.base/files/META.seq (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/seq.base/files/seq.install (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/seq.base/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/sexplib0.v0.14.0/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/spawn.v0.14.0/opam (100%) rename {test => tests}/fixtures/sample-esy/esy.lock/opam/yojson.1.7.0/opam (100%) rename {test => tests}/fixtures/sample-esy/sample-esy.opam (100%) rename {test => tests}/fixtures/sample-opam/foo.ml (100%) rename {test => tests}/fixtures/sample-opam/main.ml (100%) rename {test => tests}/fixtures/sample-opam/sample-opam.opam (63%) rename test/runProblemMatcherTests.js => tests/runBasicTests.js (60%) create mode 100644 tests/runEsyTests.js rename {test => tests}/runOpamTests.js (61%) create mode 100644 tests/suite/basic/index.js rename {test/suite => tests/suite/basic}/problems.test.js (88%) create mode 100644 tests/suite/esy/index.js create mode 100644 tests/suite/esy/languageId.test.js create mode 100644 tests/suite/opam/index.js create mode 100644 tests/suite/opam/languageId.test.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 310b0d64e..38b5bf79c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,8 +71,6 @@ jobs: uses: coactions/setup-xvfb@v1 with: run: yarn test - env: - OPAMSWITCH: ${{ github.workspace }} - name: Publish extension to VSCode Marketplace if: success() && runner.os == 'Linux' && startsWith(github.ref, 'refs/tags') diff --git a/.prettierignore b/.prettierignore index 1320d5e97..04b6f0cf6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,8 +5,8 @@ _build/ _opam/ # esy -test/fixtures/sample-esy/_esy/ -test/fixtures/sample-esy/esy.lock/ +tests/fixtures/sample-esy/_esy/ +tests/fixtures/sample-esy/esy.lock/ # Normal npm stuff node_modules/ diff --git a/dune b/dune index a9d401c52..e4db86342 100644 --- a/dune +++ b/dune @@ -1 +1 @@ -(dirs :standard \ node_modules astexplorer) +(dirs :standard \ astexplorer node_modules tests) diff --git a/package.json b/package.json index 459420562..b5b1ab9ca 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,10 @@ "astexplorer" ], "scripts": { - "test:esy": "node ./test/runEsyTests.js", - "test:opam": "node ./test/runOpamTests.js", - "test:problems": "node ./test/runProblemMatcherTests.js", - "test": "npm-run-all -s test:opam test:problems", + "test:basic": "node ./tests/runBasicTests.js", + "test:esy": "node ./tests/runEsyTests.js", + "test:opam": "node ./tests/runOpamTests.js", + "test": "npm-run-all -s test:basic test:opam", "package": "vsce package --out ocaml-platform.vsix --yarn --no-dependencies", "deploy:vsce": "vsce publish --packagePath ocaml-platform.vsix --yarn --no-dependencies", "deploy:ovsx": "ovsx publish --yarn --no-dependencies", @@ -1214,6 +1214,7 @@ "@vscode/vsce": "2.21.1", "esbuild": "0.19.5", "fs-extra": "11.1.1", + "glob": "10.3.10", "mocha": "10.2.0", "npm-run-all": "4.1.5", "ovsx": "0.8.3", diff --git a/test/dune b/test/dune deleted file mode 100644 index 708f5aece..000000000 --- a/test/dune +++ /dev/null @@ -1 +0,0 @@ -(data_only_dirs fixtures) diff --git a/test/runEsyTests.js b/test/runEsyTests.js deleted file mode 100644 index 8fa1b11f4..000000000 --- a/test/runEsyTests.js +++ /dev/null @@ -1,47 +0,0 @@ -const path = require("path"); -const os = require("os"); -const fs = require("fs-extra"); -const cp = require("child_process"); - -const { runTests } = require("@vscode/test-electron"); - -const root = path.dirname(__dirname); -const sampleEsySrc = path.join(root, "test", "fixtures", "sample-esy"); -const projectPath = path.join(os.tmpdir(), "sample-esy"); - -async function main() { - try { - fs.copySync(sampleEsySrc, projectPath); - console.log("Running in", projectPath); - cp.execSync("esy", { cwd: projectPath }); - - fs.writeFileSync( - path.join(projectPath, ".vscode", "settings.json"), - JSON.stringify({ - "ocaml.sandbox": { - root: projectPath, - kind: "esy", - }, - }), - ); - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, "../"); - - // The path to the extension test script - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, "./suite/esy"); - - // Download VS Code, unzip it and run the integration test - await runTests({ - extensionDevelopmentPath, - extensionTestsPath, - launchArgs: ["--disable-extensions"], - }); - } catch (err) { - console.error("Failed to run tests"); - process.exit(1); - } -} - -main(); diff --git a/test/suite/esy.js b/test/suite/esy.js deleted file mode 100644 index 95f634db9..000000000 --- a/test/suite/esy.js +++ /dev/null @@ -1,39 +0,0 @@ -const path = require("path"); -const Mocha = require("mocha"); - -function run() { - // Create the mocha test - const mocha = new Mocha({ - ui: "tdd", - }); - // Use any mocha API - mocha.color(true); - - const testsRoot = path.resolve(__dirname, ".."); - - return new Promise((c, e) => { - const files = ["esy.test.js"].map((f) => - path.resolve(testsRoot, "suite", f), - ); - - // Add files to the test suite - files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - - try { - // Run the mocha test - mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - } catch (err) { - e(err); - } - }); -} - -module.exports = { - run, -}; diff --git a/test/suite/esy.test.js b/test/suite/esy.test.js deleted file mode 100644 index 3750ac5b5..000000000 --- a/test/suite/esy.test.js +++ /dev/null @@ -1,40 +0,0 @@ -const assert = require("assert"); -const path = require("path"); -const vscode = require("vscode"); -const os = require("os"); -const { Uri } = vscode; - -const projectPath = path.join(os.tmpdir(), "sample-esy"); -const projectUri = Uri.file(projectPath); - -suite("Basic tests", () => { - test("Esy", async () => { - await vscode.commands.executeCommand("vscode.openFolder", projectUri); - const ocamlDocument1 = await vscode.workspace.openTextDocument( - Uri.file(path.join(projectPath, "bin", "SampleEsyApp.ml")), - ); - - const ocamlDocument2 = await vscode.workspace.openTextDocument( - Uri.file(path.join(projectPath, "bin", "CamlUtil.ml")), - ); - - assert.strictEqual( - ocamlDocument1.languageId, - "ocaml", - "Must be identified as an OCaml document", - ); - - assert.strictEqual( - ocamlDocument2.languageId, - "ocaml", - "Must be identified as an OCaml document", - ); - - // TODO: the plugin could support build related tasks - // const expected = [ - // { subcommand: "build", group: vscode.TaskGroup.Build }, - // { subcommand: "run", group: undefined } - // ]; - // const tasks = await vscode.tasks.fetchTasks(); - }).timeout(100000000000); // Ridiculous I know. Sorry! -}); diff --git a/test/suite/opam.js b/test/suite/opam.js deleted file mode 100644 index 679d0b89d..000000000 --- a/test/suite/opam.js +++ /dev/null @@ -1,39 +0,0 @@ -const path = require("path"); -const Mocha = require("mocha"); - -function run() { - // Create the mocha test - const mocha = new Mocha({ - ui: "tdd", - }); - // Use any mocha API - mocha.color(true); - - const testsRoot = path.resolve(__dirname, ".."); - - return new Promise((c, e) => { - const files = ["opam.test.js"].map((f) => - path.resolve(testsRoot, "suite", f), - ); - - // Add files to the test suite - files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - - try { - // Run the mocha test - mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - } catch (err) { - e(err); - } - }); -} - -module.exports = { - run, -}; diff --git a/test/suite/opam.test.js b/test/suite/opam.test.js deleted file mode 100644 index b836b5cca..000000000 --- a/test/suite/opam.test.js +++ /dev/null @@ -1,55 +0,0 @@ -const assert = require("assert"); -const cp = require("child_process"); -const fs = require("fs-extra"); -const os = require("os"); -const path = require("path"); -const process = require("process"); -const vscode = require("vscode"); -const { Uri } = vscode; - -const root = path.dirname(path.dirname(__dirname)); -const fixtureSrcDir = path.join(root, "test", "fixtures"); - -suite("Basic tests", () => { - test("Opam tests", async () => { - if (process.platform === "win32" || process.platform === "win64") { - return; - } - - const sampleOpamSrc = path.join(fixtureSrcDir, "sample-opam"); - const projectPath = path.join(os.tmpdir(), "sample-opam"); - const opamRoot = path.join(os.tmpdir(), "opam-root"); - fs.copySync(sampleOpamSrc, projectPath); - cp.execSync(`mkdir -p ${opamRoot}`); - cp.execSync(`sh -c 'opam install . --deps-only --yes > /dev/null'`, { - cwd: projectPath, - }).toString(); - const projectUri = Uri.file(projectPath); - await vscode.commands.executeCommand("vscode.openFolder", projectUri); - const ocamlDocument1 = await vscode.workspace.openTextDocument( - Uri.file(path.join(projectPath, "foo.ml")), - ); - - const ocamlDocument2 = await vscode.workspace.openTextDocument( - Uri.file(path.join(projectPath, "main.ml")), - ); - - assert.strictEqual( - ocamlDocument1.languageId, - "ocaml", - "Must be identified as an OCaml document", - ); - assert.strictEqual( - ocamlDocument2.languageId, - "ocaml", - "Must be identified as an OCaml document", - ); - console.log("Cleaning up (opam)..."); - try { - console.log(" Removing switch"); - console.log(cp.execSync("opam switch remove e2e --yes").toString()); - console.log(" Removing test project"); - fs.removeSync(projectPath); - } catch (e) {} - }).timeout(100000000000); -}); diff --git a/test/suite/problems.js b/test/suite/problems.js deleted file mode 100644 index c4ba8fded..000000000 --- a/test/suite/problems.js +++ /dev/null @@ -1,39 +0,0 @@ -const path = require("path"); -const Mocha = require("mocha"); - -function run() { - // Create the mocha test - const mocha = new Mocha({ - ui: "tdd", - }); - // Use any mocha API - mocha.color(true); - - const testsRoot = path.resolve(__dirname, ".."); - - return new Promise((c, e) => { - const files = ["problems.test.js"].map((f) => - path.resolve(testsRoot, "suite", f), - ); - - // Add files to the test suite - files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - - try { - // Run the mocha test - mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - } catch (err) { - e(err); - } - }); -} - -module.exports = { - run, -}; diff --git a/test/fixtures/dune b/tests/fixtures/dune similarity index 100% rename from test/fixtures/dune rename to tests/fixtures/dune diff --git a/test/fixtures/sample-esy/.gitignore b/tests/fixtures/sample-esy/.gitignore similarity index 100% rename from test/fixtures/sample-esy/.gitignore rename to tests/fixtures/sample-esy/.gitignore diff --git a/test/fixtures/sample-esy/.vscode/settings.json b/tests/fixtures/sample-esy/.vscode/settings.json similarity index 100% rename from test/fixtures/sample-esy/.vscode/settings.json rename to tests/fixtures/sample-esy/.vscode/settings.json diff --git a/test/fixtures/sample-esy/bin/CamlUtil.ml b/tests/fixtures/sample-esy/bin/CamlUtil.ml similarity index 100% rename from test/fixtures/sample-esy/bin/CamlUtil.ml rename to tests/fixtures/sample-esy/bin/CamlUtil.ml diff --git a/test/fixtures/sample-esy/bin/CamlUtil.mli b/tests/fixtures/sample-esy/bin/CamlUtil.mli similarity index 100% rename from test/fixtures/sample-esy/bin/CamlUtil.mli rename to tests/fixtures/sample-esy/bin/CamlUtil.mli diff --git a/test/fixtures/sample-esy/bin/SampleEsyApp.ml b/tests/fixtures/sample-esy/bin/SampleEsyApp.ml similarity index 100% rename from test/fixtures/sample-esy/bin/SampleEsyApp.ml rename to tests/fixtures/sample-esy/bin/SampleEsyApp.ml diff --git a/test/fixtures/sample-esy/bin/dune b/tests/fixtures/sample-esy/bin/dune similarity index 100% rename from test/fixtures/sample-esy/bin/dune rename to tests/fixtures/sample-esy/bin/dune diff --git a/test/fixtures/sample-esy/dune-project b/tests/fixtures/sample-esy/dune-project similarity index 100% rename from test/fixtures/sample-esy/dune-project rename to tests/fixtures/sample-esy/dune-project diff --git a/test/fixtures/sample-esy/esy.json b/tests/fixtures/sample-esy/esy.json similarity index 100% rename from test/fixtures/sample-esy/esy.json rename to tests/fixtures/sample-esy/esy.json diff --git a/test/fixtures/sample-esy/esy.lock/.gitattributes b/tests/fixtures/sample-esy/esy.lock/.gitattributes similarity index 100% rename from test/fixtures/sample-esy/esy.lock/.gitattributes rename to tests/fixtures/sample-esy/esy.lock/.gitattributes diff --git a/test/fixtures/sample-esy/esy.lock/.gitignore b/tests/fixtures/sample-esy/esy.lock/.gitignore similarity index 100% rename from test/fixtures/sample-esy/esy.lock/.gitignore rename to tests/fixtures/sample-esy/esy.lock/.gitignore diff --git a/test/fixtures/sample-esy/esy.lock/index.json b/tests/fixtures/sample-esy/esy.lock/index.json similarity index 100% rename from test/fixtures/sample-esy/esy.lock/index.json rename to tests/fixtures/sample-esy/esy.lock/index.json diff --git a/test/fixtures/sample-esy/esy.lock/opam/base-threads.base/opam b/tests/fixtures/sample-esy/esy.lock/opam/base-threads.base/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/base-threads.base/opam rename to tests/fixtures/sample-esy/esy.lock/opam/base-threads.base/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/base-unix.base/opam b/tests/fixtures/sample-esy/esy.lock/opam/base-unix.base/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/base-unix.base/opam rename to tests/fixtures/sample-esy/esy.lock/opam/base-unix.base/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/biniou.1.2.1/opam b/tests/fixtures/sample-esy/esy.lock/opam/biniou.1.2.1/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/biniou.1.2.1/opam rename to tests/fixtures/sample-esy/esy.lock/opam/biniou.1.2.1/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/cppo.1.6.8/opam b/tests/fixtures/sample-esy/esy.lock/opam/cppo.1.6.8/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/cppo.1.6.8/opam rename to tests/fixtures/sample-esy/esy.lock/opam/cppo.1.6.8/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/csexp.1.5.1/opam b/tests/fixtures/sample-esy/esy.lock/opam/csexp.1.5.1/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/csexp.1.5.1/opam rename to tests/fixtures/sample-esy/esy.lock/opam/csexp.1.5.1/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/dune-build-info.2.9.1/opam b/tests/fixtures/sample-esy/esy.lock/opam/dune-build-info.2.9.1/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/dune-build-info.2.9.1/opam rename to tests/fixtures/sample-esy/esy.lock/opam/dune-build-info.2.9.1/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/dune.2.9.1/opam b/tests/fixtures/sample-esy/esy.lock/opam/dune.2.9.1/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/dune.2.9.1/opam rename to tests/fixtures/sample-esy/esy.lock/opam/dune.2.9.1/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/easy-format.1.3.2/opam b/tests/fixtures/sample-esy/esy.lock/opam/easy-format.1.3.2/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/easy-format.1.3.2/opam rename to tests/fixtures/sample-esy/esy.lock/opam/easy-format.1.3.2/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/ocaml-lsp-server.1.9.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/ocaml-lsp-server.1.9.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/ocaml-lsp-server.1.9.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/ocaml-lsp-server.1.9.0/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/ocamlformat-rpc-lib.0.19.0/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/pp.1.1.2/opam b/tests/fixtures/sample-esy/esy.lock/opam/pp.1.1.2/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/pp.1.1.2/opam rename to tests/fixtures/sample-esy/esy.lock/opam/pp.1.1.2/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/ppx_yojson_conv_lib.v0.14.0/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/re.1.10.3/opam b/tests/fixtures/sample-esy/esy.lock/opam/re.1.10.3/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/re.1.10.3/opam rename to tests/fixtures/sample-esy/esy.lock/opam/re.1.10.3/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/result.1.5/opam b/tests/fixtures/sample-esy/esy.lock/opam/result.1.5/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/result.1.5/opam rename to tests/fixtures/sample-esy/esy.lock/opam/result.1.5/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/seq.base/files/META.seq b/tests/fixtures/sample-esy/esy.lock/opam/seq.base/files/META.seq similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/seq.base/files/META.seq rename to tests/fixtures/sample-esy/esy.lock/opam/seq.base/files/META.seq diff --git a/test/fixtures/sample-esy/esy.lock/opam/seq.base/files/seq.install b/tests/fixtures/sample-esy/esy.lock/opam/seq.base/files/seq.install similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/seq.base/files/seq.install rename to tests/fixtures/sample-esy/esy.lock/opam/seq.base/files/seq.install diff --git a/test/fixtures/sample-esy/esy.lock/opam/seq.base/opam b/tests/fixtures/sample-esy/esy.lock/opam/seq.base/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/seq.base/opam rename to tests/fixtures/sample-esy/esy.lock/opam/seq.base/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/sexplib0.v0.14.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/sexplib0.v0.14.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/sexplib0.v0.14.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/sexplib0.v0.14.0/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/spawn.v0.14.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/spawn.v0.14.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/spawn.v0.14.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/spawn.v0.14.0/opam diff --git a/test/fixtures/sample-esy/esy.lock/opam/yojson.1.7.0/opam b/tests/fixtures/sample-esy/esy.lock/opam/yojson.1.7.0/opam similarity index 100% rename from test/fixtures/sample-esy/esy.lock/opam/yojson.1.7.0/opam rename to tests/fixtures/sample-esy/esy.lock/opam/yojson.1.7.0/opam diff --git a/test/fixtures/sample-esy/sample-esy.opam b/tests/fixtures/sample-esy/sample-esy.opam similarity index 100% rename from test/fixtures/sample-esy/sample-esy.opam rename to tests/fixtures/sample-esy/sample-esy.opam diff --git a/test/fixtures/sample-opam/foo.ml b/tests/fixtures/sample-opam/foo.ml similarity index 100% rename from test/fixtures/sample-opam/foo.ml rename to tests/fixtures/sample-opam/foo.ml diff --git a/test/fixtures/sample-opam/main.ml b/tests/fixtures/sample-opam/main.ml similarity index 100% rename from test/fixtures/sample-opam/main.ml rename to tests/fixtures/sample-opam/main.ml diff --git a/test/fixtures/sample-opam/sample-opam.opam b/tests/fixtures/sample-opam/sample-opam.opam similarity index 63% rename from test/fixtures/sample-opam/sample-opam.opam rename to tests/fixtures/sample-opam/sample-opam.opam index 8aece4d32..5739b09c9 100644 --- a/test/fixtures/sample-opam/sample-opam.opam +++ b/tests/fixtures/sample-opam/sample-opam.opam @@ -6,7 +6,4 @@ homepage: "foo" description: "Description" synopsis: "Synopsis" bug-reports: "https//foo.bar" -depends: [ - "ocaml" {>= "4.04.2" & < "5.00.0"} - "base" {>= "v0.12" } -] +depends: ["ocaml" "base"] diff --git a/test/runProblemMatcherTests.js b/tests/runBasicTests.js similarity index 60% rename from test/runProblemMatcherTests.js rename to tests/runBasicTests.js index 581da1469..0393c0e51 100644 --- a/test/runProblemMatcherTests.js +++ b/tests/runBasicTests.js @@ -1,24 +1,20 @@ -const path = require("path"); +const path = require("node:path"); const { runTests } = require("@vscode/test-electron"); async function main() { try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` const extensionDevelopmentPath = path.resolve(__dirname, "../"); - // The path to the extension test script - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, "./suite/problems"); + const extensionTestsPath = path.resolve(__dirname, "./suite/basic"); - // Download VS Code, unzip it and run the integration test await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ["--disable-extensions"], }); } catch (err) { + console.error(err); console.error("Failed to run tests"); process.exit(1); } diff --git a/tests/runEsyTests.js b/tests/runEsyTests.js new file mode 100644 index 000000000..d0b9c161c --- /dev/null +++ b/tests/runEsyTests.js @@ -0,0 +1,23 @@ +const path = require("node:path"); + +const { runTests } = require("@vscode/test-electron"); + +async function main() { + try { + const extensionDevelopmentPath = path.resolve(__dirname, "../"); + + const extensionTestsPath = path.resolve(__dirname, "./suite/esy"); + + await runTests({ + extensionDevelopmentPath, + extensionTestsPath, + launchArgs: ["--disable-extensions"], + }); + } catch (err) { + console.error(err); + console.error("Failed to run tests"); + process.exit(1); + } +} + +main(); diff --git a/test/runOpamTests.js b/tests/runOpamTests.js similarity index 61% rename from test/runOpamTests.js rename to tests/runOpamTests.js index d11b51d66..c7b73832e 100644 --- a/test/runOpamTests.js +++ b/tests/runOpamTests.js @@ -1,24 +1,20 @@ -const path = require("path"); +const path = require("node:path"); const { runTests } = require("@vscode/test-electron"); async function main() { try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` const extensionDevelopmentPath = path.resolve(__dirname, "../"); - // The path to the extension test script - // Passed to --extensionTestsPath const extensionTestsPath = path.resolve(__dirname, "./suite/opam"); - // Download VS Code, unzip it and run the integration test await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ["--disable-extensions"], }); } catch (err) { + console.error(err); console.error("Failed to run tests"); process.exit(1); } diff --git a/tests/suite/basic/index.js b/tests/suite/basic/index.js new file mode 100644 index 000000000..22769d1a6 --- /dev/null +++ b/tests/suite/basic/index.js @@ -0,0 +1,32 @@ +const path = require("node:path"); + +const { globSync } = require("glob"); +const Mocha = require("mocha"); + +async function run() { + const mocha = new Mocha({ ui: "tdd", color: true, timeout: Infinity }); + + const testsRoot = __dirname; + + return new Promise((resolve, reject) => { + const files = globSync("**/*.test.js", { cwd: testsRoot }); + + for (const file of files) { + mocha.addFile(path.resolve(testsRoot, file)); + } + + try { + mocha.run((failures) => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(); + } + }); + } catch (err) { + reject(err); + } + }); +} + +module.exports = { run }; diff --git a/test/suite/problems.test.js b/tests/suite/basic/problems.test.js similarity index 88% rename from test/suite/problems.test.js rename to tests/suite/basic/problems.test.js index 1f70cd956..eb10b3abb 100644 --- a/test/suite/problems.test.js +++ b/tests/suite/basic/problems.test.js @@ -1,4 +1,4 @@ -const assert = require("assert"); +const assert = require("node:assert"); const problemLocations = { 'File "file.ml", line 4, characters 6-7:': [ @@ -48,8 +48,8 @@ const problemMessages = { ], }; -suite("Basic tests", () => { - test("Problem Matcher tests", async () => { +suite("basic", () => { + test("problem matcher", async () => { const locationRegex = new RegExp( '^\\s*\\bFile\\b\\s*"(.*)",\\s*\\blines?\\b\\s*(\\d+)(?:-(\\d+))?(?:,\\s*\\bcharacters\\b\\s*(\\d+)-(\\d+)\\s*)?:\\s*$', ); @@ -65,7 +65,7 @@ suite("Basic tests", () => { null, "Location regex should match: " + problem, ); - assert.deepStrictEqual(captures.slice(1), expected); + assert.deepStrictEqual(captures?.slice(1), expected); } for (const [problem, expected] of Object.entries(problemMessages)) { @@ -75,7 +75,7 @@ suite("Basic tests", () => { null, "Message regex should match: " + problem, ); - assert.deepStrictEqual(captures.slice(1), expected); + assert.deepStrictEqual(captures?.slice(1), expected); } }); }); diff --git a/tests/suite/esy/index.js b/tests/suite/esy/index.js new file mode 100644 index 000000000..22769d1a6 --- /dev/null +++ b/tests/suite/esy/index.js @@ -0,0 +1,32 @@ +const path = require("node:path"); + +const { globSync } = require("glob"); +const Mocha = require("mocha"); + +async function run() { + const mocha = new Mocha({ ui: "tdd", color: true, timeout: Infinity }); + + const testsRoot = __dirname; + + return new Promise((resolve, reject) => { + const files = globSync("**/*.test.js", { cwd: testsRoot }); + + for (const file of files) { + mocha.addFile(path.resolve(testsRoot, file)); + } + + try { + mocha.run((failures) => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(); + } + }); + } catch (err) { + reject(err); + } + }); +} + +module.exports = { run }; diff --git a/tests/suite/esy/languageId.test.js b/tests/suite/esy/languageId.test.js new file mode 100644 index 000000000..bdeb4f40d --- /dev/null +++ b/tests/suite/esy/languageId.test.js @@ -0,0 +1,58 @@ +const assert = require("node:assert"); +const child_process = require("node:child_process"); +const os = require("node:os"); +const path = require("node:path"); +const util = require("node:util"); + +const fs = require("fs-extra"); +const vscode = require("vscode"); +const { Uri } = require("vscode"); + +const exec = util.promisify(child_process.exec); + +const root = path.resolve(__dirname, "../../../"); +const fixtureSrcDir = path.join(root, "tests", "fixtures"); +const sampleEsySrc = path.join(fixtureSrcDir, "sample-opam"); +const projectPath = path.join(os.tmpdir(), "sample-opam"); + +setup(async () => { + await fs.copy(sampleEsySrc, projectPath); + + await exec("esy", { cwd: projectPath }); + + await fs.writeFile( + path.join(projectPath, ".vscode", "settings.json"), + JSON.stringify({ "ocaml.sandbox": { root: projectPath, kind: "esy" } }), + ); + + await vscode.commands.executeCommand( + "vscode.openFolder", + Uri.file(projectPath), + ); +}); + +teardown(async () => { + await fs.remove(projectPath); +}); + +suite("esy", () => { + test("languageId", async () => { + const ocamlDocument1 = await vscode.workspace.openTextDocument( + Uri.file(path.join(projectPath, "bin", "SampleEsyApp.ml")), + ); + const ocamlDocument2 = await vscode.workspace.openTextDocument( + Uri.file(path.join(projectPath, "bin", "CamlUtil.ml")), + ); + + assert.strictEqual( + ocamlDocument1.languageId, + "ocaml", + "Must be identified as an OCaml document", + ); + assert.strictEqual( + ocamlDocument2.languageId, + "ocaml", + "Must be identified as an OCaml document", + ); + }); +}); diff --git a/tests/suite/opam/index.js b/tests/suite/opam/index.js new file mode 100644 index 000000000..22769d1a6 --- /dev/null +++ b/tests/suite/opam/index.js @@ -0,0 +1,32 @@ +const path = require("node:path"); + +const { globSync } = require("glob"); +const Mocha = require("mocha"); + +async function run() { + const mocha = new Mocha({ ui: "tdd", color: true, timeout: Infinity }); + + const testsRoot = __dirname; + + return new Promise((resolve, reject) => { + const files = globSync("**/*.test.js", { cwd: testsRoot }); + + for (const file of files) { + mocha.addFile(path.resolve(testsRoot, file)); + } + + try { + mocha.run((failures) => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(); + } + }); + } catch (err) { + reject(err); + } + }); +} + +module.exports = { run }; diff --git a/tests/suite/opam/languageId.test.js b/tests/suite/opam/languageId.test.js new file mode 100644 index 000000000..57c679bb4 --- /dev/null +++ b/tests/suite/opam/languageId.test.js @@ -0,0 +1,59 @@ +const assert = require("node:assert"); +const child_process = require("node:child_process"); +const os = require("node:os"); +const path = require("node:path"); +const process = require("node:process"); +const util = require("node:util"); + +const fs = require("fs-extra"); +const vscode = require("vscode"); +const { Uri } = require("vscode"); + +const exec = util.promisify(child_process.exec); + +const root = path.resolve(__dirname, "../../../"); +const fixtureSrcDir = path.join(root, "tests", "fixtures"); +const sampleOpamSrc = path.join(fixtureSrcDir, "sample-opam"); +const projectPath = path.join(os.tmpdir(), "sample-opam"); + +setup(async () => { + await fs.copy(sampleOpamSrc, projectPath); + + await exec("opam install . --deps-only --yes", { + cwd: projectPath, + env: { ...process.env, PATH: process.env.PATH, OPAMSWITCH: root }, + }); + + await vscode.commands.executeCommand( + "vscode.openFolder", + Uri.file(projectPath), + ); +}); + +teardown(async () => { + await fs.remove(projectPath); +}); + +suite("opam", () => { + if (process.platform === "win32") return; + + test("languageId", async () => { + const ocamlDocument1 = await vscode.workspace.openTextDocument( + Uri.file(path.join(projectPath, "foo.ml")), + ); + const ocamlDocument2 = await vscode.workspace.openTextDocument( + Uri.file(path.join(projectPath, "main.ml")), + ); + + assert.strictEqual( + ocamlDocument1.languageId, + "ocaml", + "Must be identified as an OCaml document", + ); + assert.strictEqual( + ocamlDocument2.languageId, + "ocaml", + "Must be identified as an OCaml document", + ); + }); +}); diff --git a/yarn.lock b/yarn.lock index 5bc7b38b5..65fbb5a05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2945,21 +2945,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:7.2.0": - version: 7.2.0 - resolution: "glob@npm:7.2.0" - dependencies: - fs.realpath: "npm:^1.0.0" - inflight: "npm:^1.0.4" - inherits: "npm:2" - minimatch: "npm:^3.0.4" - once: "npm:^1.3.0" - path-is-absolute: "npm:^1.0.0" - checksum: 478b40e38be5a3d514e64950e1e07e0ac120585add6a37c98d0ed24d72d9127d734d2a125786073c8deb687096e84ae82b641c441a869ada3a9cc91b68978632 - languageName: node - linkType: hard - -"glob@npm:^10.2.2": +"glob@npm:10.3.10, glob@npm:^10.2.2": version: 10.3.10 resolution: "glob@npm:10.3.10" dependencies: @@ -2974,6 +2960,20 @@ __metadata: languageName: node linkType: hard +"glob@npm:7.2.0": + version: 7.2.0 + resolution: "glob@npm:7.2.0" + dependencies: + fs.realpath: "npm:^1.0.0" + inflight: "npm:^1.0.4" + inherits: "npm:2" + minimatch: "npm:^3.0.4" + once: "npm:^1.3.0" + path-is-absolute: "npm:^1.0.0" + checksum: 478b40e38be5a3d514e64950e1e07e0ac120585add6a37c98d0ed24d72d9127d734d2a125786073c8deb687096e84ae82b641c441a869ada3a9cc91b68978632 + languageName: node + linkType: hard + "glob@npm:^7.0.6, glob@npm:^7.1.3, glob@npm:^7.1.4": version: 7.2.3 resolution: "glob@npm:7.2.3" @@ -4600,6 +4600,7 @@ __metadata: "@vscode/vsce": "npm:2.21.1" esbuild: "npm:0.19.5" fs-extra: "npm:11.1.1" + glob: "npm:10.3.10" mocha: "npm:10.2.0" npm-run-all: "npm:4.1.5" ovsx: "npm:0.8.3"