Skip to content

Commit 986b1e5

Browse files
committed
Add Emacs regression tests for PSES
1 parent 9ce4762 commit 986b1e5

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/emacs-session.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"started","languageServiceTransport":"Stdio"}

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)