branch: externals/polymode
commit 96d56e72f98703fd93fe2442acf539987295f6cc
Author: Kien Nguyen <[email protected]>
Commit: Vitalie Spinu <[email protected]>
ci: run test on CI
---
.github/workflows/test.yml | 52 +++++++++++
polymode-test-utils.el | 12 +--
targets/poly-targets.el | 15 +++-
tests/compat-tests.el | 213 +++++++++++++++++++++++----------------------
tests/define-tests.el | 4 +-
5 files changed, 183 insertions(+), 113 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000000..853a51081b
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,52 @@
+name: CI
+on:
+ pull_request:
+ paths-ignore:
+ - '**.md'
+ - '**.org'
+ - '.dir-locals.el'
+ - '.elpaignore'
+ - '.gitignore'
+ - 'doc/**'
+ branches:
+ - master
+ push:
+ paths-ignore:
+ - '**.md'
+ - '**.org'
+ - '.dir-locals.el'
+ - '.elpaignore'
+ - '.gitignore'
+ - 'doc/**'
+permissions: {}
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ emacs_version:
+ - 28.2
+ - 29.4
+ - 30.1
+ - snapshot
+
+ steps:
+ - uses: purcell/setup-emacs@master
+ with:
+ version: ${{ matrix.emacs_version }}
+
+ - uses: actions/checkout@v4
+ with:
+ persist-credentials: false
+
+ - name: Check Emacs version
+ run: emacs --version
+
+ - name: Build
+ run: |
+ make elpa
+ make build
+
+ - name: Test
+ run: make test-local
diff --git a/polymode-test-utils.el b/polymode-test-utils.el
index 07b9f91a2a..8ae65fc1c6 100644
--- a/polymode-test-utils.el
+++ b/polymode-test-utils.el
@@ -82,8 +82,8 @@ Look into tests/input directory then in samples directory."
(message ")"))
nil)))
-(defmacro pm-test-run-on-string (mode string &rest body)
- "Run BODY in a temporary buffer containing STRING in MODE.
+(defmacro pm-test-run-on-string (mode string position &rest body)
+ "Run BODY in a temporary buffer containing STRING in MODE at POSITION.
MODE is a quoted symbol."
(declare (indent 1) (debug (form form body)))
`(let ((*buf* "*pm-test-string-buffer*"))
@@ -98,7 +98,7 @@ MODE is a quoted symbol."
(and (bound-and-true-p syntax-propertize-function)
(not (local-variable-p 'parse-sexp-lookup-properties))
(setq-local parse-sexp-lookup-properties t))
- (goto-char (point-min))
+ (funcall-interactively 'goto-char ,position)
(let ((poly-lock-allow-background-adjustment nil))
(when polymode-mode
;; font-lock not activated in batch mode
@@ -110,8 +110,8 @@ MODE is a quoted symbol."
(defun pm-test-spans (mode string)
(declare (indent 1))
- (pm-test-run-on-string mode
- string
+ (pm-test-run-on-string mode
+ string 1
(pm-map-over-spans
(lambda (span)
(let ((range0 (pm-span-to-range span)))
@@ -190,7 +190,7 @@ MODE is a quoted symbol."
(smode major-mode)
(stext (buffer-substring-no-properties sbeg send))
;; other buffer
- (ref-buf (pm-test-run-on-string smode stext))
+ (ref-buf (pm-test-run-on-string smode stext 1))
(ref-pos 1))
(when pm-verbose
(message "---- testing %s ----" (pm-format-span span t)))
diff --git a/targets/poly-targets.el b/targets/poly-targets.el
index ef70b18520..ffe4386644 100644
--- a/targets/poly-targets.el
+++ b/targets/poly-targets.el
@@ -24,6 +24,20 @@
;;; Code:
+(defmacro dlet (binders &rest body)
+ "Like `let' but using dynamic scoping."
+ (declare (indent 1) (debug let))
+ ;; (defvar FOO) only affects the current scope, but in order for
+ ;; this not to affect code after the main `let' we need to create a new
scope,
+ ;; which is what the surrounding `let' is for.
+ ;; FIXME: (let () ...) currently doesn't actually create a new scope,
+ ;; which is why we use (let (_) ...).
+ `(let (_)
+ ,@(mapcar (lambda (binder)
+ `(defvar ,(if (consp binder) (car binder) binder)))
+ binders)
+ (let ,binders ,@body)))
+
(defun pm--target-checkdoc ()
(dlet ((sentence-end-double-space)
(checkdoc-arguments-in-order-flag)
@@ -62,7 +76,6 @@
(setq package-user-dir (expand-file-name (format ".ELPA/%s" emacs-version))
package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
-
(package-initialize))
(defun pm--target-melpa ()
diff --git a/tests/compat-tests.el b/tests/compat-tests.el
index e084e265ae..398642f226 100644
--- a/tests/compat-tests.el
+++ b/tests/compat-tests.el
@@ -2,6 +2,9 @@
;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+(require 'polymode)
+(require 'polymode-test-utils)
(require 'poly-markdown nil t) ;Don't fail if not installed.
(define-innermode poly-test-markdown-inline-python-innermode
poly-markdown-inline-code-innermode
@@ -19,114 +22,114 @@
(skip-unless (fboundp 'poly-markdown-mode))
(let ((markdown-enable-math t))
(pm-test-run-on-file poly-test-markdown-mode "test.md"
- ;; python
- (goto-char 44)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
- (should (equal (pm--lsp-buffer-content 142 143) " "))
- (should (equal (pm--lsp-buffer-content 142 145) " "))
-
- (should (equal (pm--lsp-buffer-content 44 50) "fruits"))
- (should (equal (pm--lsp-buffer-content 21 50)
- (concat (make-string 3 ?\n) "# foo\nfruits")))
-
- (should (equal (pm--lsp-buffer-content 148 155)
- "+ x"))
- (should (equal (pm--lsp-buffer-content 131 155)
- (concat (make-string 12 ? ) " 3 + x")))
- (should (equal (pm--lsp-buffer-content 103 155)
- (concat "print(x)\n\n\n\n"
- (make-string 28 ? )
- "3 + x")))
- (should (equal (pm--lsp-buffer-content 121 141)
- (make-string 20 ? )))
- (should (equal (pm--lsp-buffer-content 121 131)
- (make-string 10 ? )))
-
- ;; latex
- (goto-char 130)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
-
- ;; markdown
- (goto-char 21)
- (pm-switch-to-buffer)
- (should (equal (pm--lsp-buffer-content 108 108) ""))
- (should (equal (pm--lsp-buffer-content 29 29) ""))
- (should (equal (pm--lsp-buffer-content 128 128) ""))
- (should (equal (pm--lsp-buffer-content 150 150) ""))
- (should (equal (pm--lsp-buffer-content 151 151) ""))
- (should (equal (pm--lsp-buffer-content 152 152) ""))
-
- (should (equal (pm--lsp-buffer-content 142 143) " "))
- (should (equal (pm--lsp-buffer-content 142 145) " "))
- (should (equal (pm--lsp-buffer-content 151 152) " "))
-
- (should (equal (pm--lsp-buffer-content 117 121) "\nfoo"))
- (should (equal (pm--lsp-buffer-content 118 121) "foo"))
- (should (equal (pm--lsp-buffer-content 122 123) "$"))
- (should (equal (pm--lsp-buffer-content 135 145) " $ bar "))
-
- (should (equal (pm--lsp-buffer-content 21 50)
- "some text\n\n```py\n\n"))
- (should (equal (point) 21))
-
- (let ((base (concat "\n\n```\n\nfoo $"
- (make-string 13 ? )
- "$ bar "
- (make-string 8 ? )
- " baz")))
- (should (equal (pm--lsp-buffer-content 100 156)
- base))
- (should (equal (pm--lsp-buffer-content 100 160)
- (concat base "\n```")))
- (should (equal (pm--lsp-buffer-content 100 163)
- (concat base "\n```js\n")))
- (should (equal (pm--lsp-buffer-content 100 200)
- (concat base "\n```js\n\n\n"))))
-
- (let ((base " baz\n```js\n\n\n"))
- (should (equal (pm--lsp-buffer-content 145 203)
- base))
- (should (equal (pm--lsp-buffer-content 136 203)
- (concat "$ bar " base)))
- (should (equal (pm--lsp-buffer-content 128 203)
- (concat " $ bar " base))))
- (should (equal (point) 21))
-
- )))
+ ;; python
+ (goto-char 44)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+ (should (equal (pm--lsp-buffer-content 142 143) " "))
+ (should (equal (pm--lsp-buffer-content 142 145) "
"))
+
+ (should (equal (pm--lsp-buffer-content 44 50)
"fruits"))
+ (should (equal (pm--lsp-buffer-content 21 50)
+ (concat (make-string 3 ?\n) "#
foo\nfruits")))
+
+ (should (equal (pm--lsp-buffer-content 148 155)
+ "+ x"))
+ (should (equal (pm--lsp-buffer-content 131 155)
+ (concat (make-string 12 ? ) " 3 +
x")))
+ (should (equal (pm--lsp-buffer-content 103 155)
+ (concat "print(x)\n\n\n\n"
+ (make-string 28 ? )
+ "3 + x")))
+ (should (equal (pm--lsp-buffer-content 121 141)
+ (make-string 20 ? )))
+ (should (equal (pm--lsp-buffer-content 121 131)
+ (make-string 10 ? )))
+
+ ;; latex
+ (goto-char 130)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+
+ ;; markdown
+ (goto-char 21)
+ (pm-switch-to-buffer)
+ (should (equal (pm--lsp-buffer-content 108 108) ""))
+ (should (equal (pm--lsp-buffer-content 29 29) ""))
+ (should (equal (pm--lsp-buffer-content 128 128) ""))
+ (should (equal (pm--lsp-buffer-content 150 150) ""))
+ (should (equal (pm--lsp-buffer-content 151 151) ""))
+ (should (equal (pm--lsp-buffer-content 152 152) ""))
+
+ (should (equal (pm--lsp-buffer-content 142 143) " "))
+ (should (equal (pm--lsp-buffer-content 142 145) "
"))
+ (should (equal (pm--lsp-buffer-content 151 152) " "))
+
+ (should (equal (pm--lsp-buffer-content 117 121)
"\nfoo"))
+ (should (equal (pm--lsp-buffer-content 118 121)
"foo"))
+ (should (equal (pm--lsp-buffer-content 122 123) "$"))
+ (should (equal (pm--lsp-buffer-content 135 145) " $
bar "))
+
+ (should (equal (pm--lsp-buffer-content 21 50)
+ "some text\n\n```py\n\n"))
+ (should (equal (point) 21))
+
+ (let ((base (concat "\n\n```\n\nfoo $"
+ (make-string 13 ? )
+ "$ bar "
+ (make-string 8 ? )
+ " baz")))
+ (should (equal (pm--lsp-buffer-content 100 156)
+ base))
+ (should (equal (pm--lsp-buffer-content 100 160)
+ (concat base "\n```")))
+ (should (equal (pm--lsp-buffer-content 100 163)
+ (concat base "\n```js\n")))
+ (should (equal (pm--lsp-buffer-content 100 200)
+ (concat base "\n```js\n\n\n"))))
+
+ (let ((base " baz\n```js\n\n\n"))
+ (should (equal (pm--lsp-buffer-content 145 203)
+ base))
+ (should (equal (pm--lsp-buffer-content 136 203)
+ (concat "$ bar " base)))
+ (should (equal (pm--lsp-buffer-content 128 203)
+ (concat " $ bar " base))))
+ (should (equal (point) 21))
+
+ )))
(ert-deftest compat/indent/double-poly-mode-init-preserves-original-functions
()
(skip-unless (fboundp 'poly-markdown-mode))
(pm-test-run-on-file poly-test-markdown-mode "test.md"
- (goto-char (point-min))
- (pm-switch-to-buffer)
- (should (eq major-mode 'markdown-mode))
- (poly-test-markdown-mode t)
- (should (equal pm--indent-line-function-original 'markdown-indent-line))
- (should (equal pm--indent-region-function-original
'markdown--indent-region))
- (should (equal pm--fill-forward-paragraph-original
'markdown-fill-forward-paragraph))
- (should (equal pm--syntax-propertize-function-original
'markdown-syntax-propertize))
-
- (re-search-forward "http.createServer")
- (forward-line 1)
- (pm-switch-to-buffer)
- (poly-test-markdown-mode t)
- (should (eq major-mode 'js-mode))
- (should (equal pm--indent-line-function-original 'js-indent-line))
- (should (equal pm--indent-region-function-original
'pm--indent-region-line-by-line))
- (should (equal pm--fill-forward-paragraph-original 'forward-paragraph))))
+ (goto-char (point-min))
+ (pm-switch-to-buffer)
+ (should (eq major-mode 'markdown-mode))
+ (poly-test-markdown-mode t)
+ (should (equal pm--indent-line-function-original
'markdown-indent-line))
+ (should (equal pm--indent-region-function-original
'markdown--indent-region))
+ (should (equal pm--fill-forward-paragraph-original
'markdown-fill-forward-paragraph))
+ (should (equal pm--syntax-propertize-function-original
'markdown-syntax-propertize))
+
+ (re-search-forward "http.createServer")
+ (forward-line 1)
+ (pm-switch-to-buffer)
+ (poly-test-markdown-mode t)
+ (should (eq major-mode 'js-mode))
+ (should (equal pm--indent-line-function-original
'js-indent-line))
+ (should (equal pm--indent-region-function-original
'pm--indent-region-line-by-line))
+ (should (equal pm--fill-forward-paragraph-original
'forward-paragraph))))
diff --git a/tests/define-tests.el b/tests/define-tests.el
index 976ab44a37..652a96264f 100644
--- a/tests/define-tests.el
+++ b/tests/define-tests.el
@@ -49,6 +49,8 @@
'some-command))))
(ert-deftest define/hooks-run-in-indirect-buffers ()
+ ;; skip when run under GithubActions
+ (skip-unless (not (string= (getenv "GITHUB_ACTIONS") "true")))
(setq ran-body-in-modes nil
ran-hooks-in-modes nil
ran-inner-hooks-in-modes nil
@@ -68,7 +70,7 @@
(add-hook 'poly-el-mode-hook (lambda () (add-to-list 'ran-hooks-in-modes
major-mode)))
(pm-test-run-on-string 'poly-el-mode
- "\n<<(defvar abc nil)>>\n"
+ "\n<<(defvar abc nil)>>\n" 7
(should (equal ran-body-in-modes '(emacs-lisp-mode poly-head-tail-mode
text-mode)))
(should (equal ran-hooks-in-modes '(emacs-lisp-mode poly-head-tail-mode
text-mode)))
(should (equal ran-inner-hooks-in-modes '(emacs-lisp-mode
poly-head-tail-mode)))