Skip to content

Add Emacs regression tests for PSES #1820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/emacs-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Emacs"

on:
push:
branches: [ master ]
tags: [ v* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
paths-ignore: [ '**/*.md' ]

jobs:
test:
name: Test PSES with Emacs via Eglot
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build PSES
shell: pwsh
run: tools/azurePipelinesBuild.ps1

- name: Install Emacs
uses: purcell/[email protected]
with:
version: '28.1'

- name: Run ERT
run: emacs -batch -l ert -l test/emacs-test.el -f ert-run-tests-batch-and-exit
70 changes: 70 additions & 0 deletions test/emacs-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
;;; emacs-test.el --- Integration testing script -*- lexical-binding: t; -*-

;; Copyright (c) Microsoft Corporation.
;; Licensed under the MIT License.

;; Author: Andy Schwartzmeyer <[email protected]>
;; Keywords: PowerShell, LSP

;;; Code:

(require 'ert)

;; Improved TLS Security.
(with-eval-after-load 'gnutls
(custom-set-variables
'(gnutls-verify-error t)
'(gnutls-min-prime-bits 3072)))

;; Package setup.
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(require 'flymake)

(unless (package-installed-p 'powershell)
(package-refresh-contents)
(package-install 'powershell))
(require 'powershell)

(unless (package-installed-p 'eglot)
(package-refresh-contents)
(package-install 'eglot))
(require 'eglot)

(ert-deftest powershell-editor-services ()
"Eglot should connect to PowerShell Editor Services."
(let* ((repo (project-root (project-current)))
(start-script (expand-file-name "module/PowerShellEditorServices/Start-EditorServices.ps1" repo))
(module-path (expand-file-name "module" repo))
(log-path (expand-file-name "test/emacs-test.log" repo))
(session-path (expand-file-name "test/emacs-session.json" repo))
(test-script (expand-file-name "test/PowerShellEditorServices.Test.Shared/Debugging/VariableTest.ps1" repo))
(eglot-sync-connect t))
(add-to-list
'eglot-server-programs
`(powershell-mode
. ("pwsh" "-NoLogo" "-NoProfile" "-Command" ,start-script
"-HostName" "Emacs" "-HostProfileId" "Emacs" "-HostVersion" "1.0.0"
"-BundledModulesPath" ,module-path
"-LogPath" ,log-path "-LogLevel" "Diagnostic"
"-SessionDetailsPath" ,session-path
"-Stdio")))
(with-current-buffer (find-file-noselect test-script)
(should (eq major-mode 'powershell-mode))
(should (apply #'eglot--connect (eglot--guess-contact)))
(should (eglot-current-server))
(let ((lsp (eglot-current-server)))
(should (string= (oref lsp project-nickname) "PowerShellEditorServices"))
(should (eq (oref lsp major-mode) 'powershell-mode))
(should (string= (oref lsp language-id) "powershell")))
(sleep-for 3) ; TODO: Wait for "textDocument/publishDiagnostics" instead
(flymake-start)
(goto-char (point-min))
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))))))

(provide 'emacs-test)
;;; emacs-test.el ends here