Skip to content

Commit

Permalink
Add one test (#294)
Browse files Browse the repository at this point in the history
* Add one test

* install erlang

* use sudo

* use port for macos

* update for mac

* timeout to 1 minute

* remove macOS, unstable between runs

* add rebar3 ct
  • Loading branch information
pgourlain authored May 16, 2024
1 parent ee831c0 commit 4bc7871
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 32 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/pr-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [macos-latest, ubuntu-latest]
os: [ubuntu-latest]
node:
- 20
steps:
- run: sudo apt-get install erlang
if: runner.os == 'Linux'
- run: |
brew install erlang@26
if: runner.os =='macOS'
- run: |
VERSION=$(ls /opt/homebrew/Cellar/erlang/)
export PATH=$PATH:/opt/homebrew/Cellar/erlang/$VERSION/bin
erl -version
name: setup path
if: runner.os =='macOS'
- name: Checkout Source
uses: actions/checkout@v4
- name: Install Node ${{ matrix.node }}
Expand All @@ -31,4 +42,7 @@ jobs:
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'
if: runner.os != 'Linux'
- run: |
./rebar3 ct
5 changes: 5 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
workspaceFolder: './test/test-fixtures',
mocha: {
ui: 'tdd',
timeout: 60000
}
});
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/test-temp/",
"${workspaceFolder}/test/test-fixtures/",
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceRoot}/out/test/test-suite"
],
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js"],
// "preLaunchTask": "prepareTest",
"preLaunchTask": "prepareTest",
// "postDebugTask": "cleanTestFolder"
}
]
Expand Down
9 changes: 8 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
// A task runner that calls a custom npm script that compiles the extension.
{
"version": "2.0.0",
"tasks": []
"tasks": [
{
"label": "prepareTest",
"dependsOn": [
"npm: pretest"
]
},
]
}
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ node_modules
src/
tsconfig.json
webpack.config.js
.vscode-test/**

4 changes: 2 additions & 2 deletions lib/lsp/lsp-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ErlangLanguageClient extends LanguageClient {
//
// For user-interactive operations (e.g. applyFixIt, applyTweaks), we will
// prompt up the failure to users.
outChannel: vscode.OutputChannel;
outChannel?: vscode.OutputChannel;

handleFailedRequest<T>(type: MessageSignature, error: any,
defaultValue: T): T {
Expand All @@ -43,7 +43,7 @@ export class ErlangLanguageClient extends LanguageClient {


onReady(): Promise<void> {
this.outChannel.appendLine("LanguageClient is ready");
this.outChannel?.appendLine("LanguageClient is ready");
clientIsReady = true;
return super.onReady();
}
Expand Down
23 changes: 0 additions & 23 deletions test/runTest.ts

This file was deleted.

12 changes: 12 additions & 0 deletions test/test-fixtures/fixture-navigation/navigation_source.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-module(navigation_source).

-export([start/0]).

start() ->
L = [1,2,3,4,5,6,7,8],
lists:filter(fun myfilter1/1, L),
lists:filter(fun navigation_target:myexportedfilter/1, L).


myfilter1(_X) ->
true.
7 changes: 7 additions & 0 deletions test/test-fixtures/fixture-navigation/navigation_target.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-module(navigation_target).


-export([myexportedfilter/1]).

myexportedfilter(_X) ->
ok.
5 changes: 5 additions & 0 deletions test/test-fixtures/fixture1/fixture1.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-module(fixture1).


start() -> ok.

41 changes: 39 additions & 2 deletions test/test-suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,49 @@ import * as fs from 'fs';
import * as path from 'path';
import { env } from 'process';
import * as vscode from 'vscode';
import * as vscodeclient from 'vscode-languageclient'
import * as erlExtension from '../../lib/extension';



function openTextDocument(fileRelativePath: string ) : Thenable<vscode.TextDocument>
{
const wk = vscode.workspace.workspaceFolders[0];
if (!fileRelativePath.startsWith("/")) {
fileRelativePath = "/" + fileRelativePath;
}
const filepath = path.join(wk.uri.fsPath, fileRelativePath);
return vscode.workspace.openTextDocument(filepath);
}

suite('Erlang Language Extension', () => {
after(() => {
vscode.window.showInformationMessage('All tests done!');
});
test('Extension should be present', () => {
assert.ok(vscode.extensions.getExtension('pgourlain.erlang'));
test('Extension should be present', async () => {
const myExtension = vscode.extensions.getExtension('pgourlain.erlang');
await myExtension.activate();
assert.ok(myExtension);
});

test('Diagnostics should be generated', async () => {
//use console.info('...') to write on output during test

const document = await openTextDocument("/fixture1/fixture1.erl");
assert.ok(document != null);
assert.equal('erlang', document.languageId);

const waitForDiags = new Promise<readonly vscode.Uri[]>((resolve, reject) => {
const disposeToken = vscode.languages.onDidChangeDiagnostics(
async (ev) => {
disposeToken.dispose();
resolve(ev.uris);
}
)
});
const uris = await waitForDiags;
assert.equal(true, uris.length > 0);
const diags = vscode.languages.getDiagnostics(uris[0]);
assert.equal(1, diags.length);
});
});

0 comments on commit 4bc7871

Please sign in to comment.