Skip to content

Commit 69e4793

Browse files
committed
Add Emacs regression tests for PSES
This adds regression tests written in Emacs to validate that PSES can be connected (and reports diagnostics) with a client that isn't VS Code, namely [Eglot](https://github.com/joaotavora/eglot).
1 parent 9ce4762 commit 69e4793

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/emacs-test.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Emacs"
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
tags: [ v* ]
7+
pull_request:
8+
# The branches below must be a subset of the branches above
9+
branches: [ master ]
10+
paths-ignore: [ '**/*.md' ]
11+
12+
jobs:
13+
test:
14+
name: Test PSES with Emacs via Eglot
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Build PSES
21+
shell: pwsh
22+
run: tools/azurePipelinesBuild.ps1
23+
24+
- name: Install Emacs
25+
uses: purcell/[email protected]
26+
with:
27+
version: '28.1'
28+
29+
- name: Run ERT
30+
run: emacs -batch -l ert -l test/emacs-test.el -f ert-run-tests-batch-and-exit

test/emacs-test.el

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
;;; emacs-test.el --- Integration testing script -*- lexical-binding: t; -*-
2+
3+
;; Copyright (c) Microsoft Corporation.
4+
;; Licensed under the MIT License.
5+
6+
;; Author: Andy Schwartzmeyer <[email protected]>
7+
;; Keywords: PowerShell, LSP
8+
9+
;;; Code:
10+
11+
(require 'ert)
12+
13+
;; Improved TLS Security.
14+
(with-eval-after-load 'gnutls
15+
(custom-set-variables
16+
'(gnutls-verify-error t)
17+
'(gnutls-min-prime-bits 3072)))
18+
19+
;; Package setup.
20+
(require 'package)
21+
(add-to-list 'package-archives
22+
'("melpa" . "https://melpa.org/packages/") t)
23+
(package-initialize)
24+
25+
(require 'flymake)
26+
27+
(unless (package-installed-p 'powershell)
28+
(package-refresh-contents)
29+
(package-install 'powershell))
30+
(require 'powershell)
31+
32+
(unless (package-installed-p 'eglot)
33+
(package-refresh-contents)
34+
(package-install 'eglot))
35+
(require 'eglot)
36+
37+
(ert-deftest powershell-editor-services ()
38+
"Eglot should connect to PowerShell Editor Services."
39+
(let* ((repo (project-root (project-current)))
40+
(start-script (expand-file-name "module/PowerShellEditorServices/Start-EditorServices.ps1" repo))
41+
(module-path (expand-file-name "module" repo))
42+
(log-path (expand-file-name "test/emacs-test.log" repo))
43+
(session-path (expand-file-name "test/emacs-session.json" repo))
44+
(test-script (expand-file-name "test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1" repo))
45+
(eglot-sync-connect t))
46+
(add-to-list
47+
'eglot-server-programs
48+
`(powershell-mode
49+
. ("pwsh" "-NoLogo" "-NoProfile" "-Command" ,start-script
50+
"-HostName" "Emacs" "-HostProfileId" "Emacs" "-HostVersion" "1.0.0"
51+
"-BundledModulesPath" ,module-path
52+
"-LogPath" ,log-path "-LogLevel" "Diagnostic"
53+
"-SessionDetailsPath" ,session-path
54+
"-Stdio")))
55+
(with-current-buffer (find-file-noselect test-script)
56+
(should (eq major-mode 'powershell-mode))
57+
(should (apply #'eglot--connect (eglot--guess-contact)))
58+
(should (eglot-current-server))
59+
(let ((lsp (eglot-current-server)))
60+
(should (string= (oref lsp project-nickname) "PowerShellEditorServices"))
61+
(should (eq (oref lsp major-mode) 'powershell-mode))
62+
(should (string= (oref lsp language-id) "powershell")))
63+
(sleep-for 3) ; TODO: Wait for "textDocument/publishDiagnostics" instead
64+
(flymake-start)
65+
(goto-char (point-min))
66+
(flymake-goto-next-error)
67+
(should (eq 'flymake-warning (face-at-point))))))
68+
69+
(provide 'emacs-test)
70+
;;; emacs-test.el ends here

0 commit comments

Comments
 (0)