emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/yaml-mode ebeb27cbbc 3/6: Add unit test and github actions


From: ELPA Syncer
Subject: [nongnu] elpa/yaml-mode ebeb27cbbc 3/6: Add unit test and github actions configuration
Date: Sat, 22 Oct 2022 06:59:28 -0400 (EDT)

branch: elpa/yaml-mode
commit ebeb27cbbc2b2bc0512fd1be69eb926af79142ee
Author: Shohei YOSHIDA <syohex@gmail.com>
Commit: Shohei YOSHIDA <syohex@gmail.com>

    Add unit test and github actions configuration
---
 .github/workflows/ci.yml |  29 ++++++++++++
 Makefile                 |   8 +++-
 test/yaml-mode-test.el   | 117 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000000..e6fa8a60ed
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,29 @@
+name: CI
+
+on:
+  pull_request:
+  push:
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        emacs_version:
+          - 24.3
+          - 26.3
+          - 27.2
+          - 28.2
+          - snapshot
+    steps:
+    - uses: purcell/setup-emacs@master
+      with:
+        version: ${{ matrix.emacs_version }}
+
+    - uses: actions/checkout@v3
+    - name: Install dependencies
+      run: sudo apt install pandoc aspell
+    - name: Run tests
+      run: |
+        make clean
+        make test
diff --git a/Makefile b/Makefile
index cff86ba0f8..599299f32f 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,12 @@ tardist:
        tar zcvf yaml-mode-$(VERSION).tar.gz yaml-mode-$(VERSION)
        rm -fr yaml-mode-$(VERSION)
 
+.PHONY: test
+test:
+       $(EMACS) -Q -batch -L . \
+               -l test/yaml-mode-test.el \
+               -f ert-run-tests-batch-and-exit
+
+.PHONY: clean
 clean:
        rm -fr \#*\# *.elc *~ *.tar.gz
-
diff --git a/test/yaml-mode-test.el b/test/yaml-mode-test.el
new file mode 100644
index 0000000000..472a13f2fe
--- /dev/null
+++ b/test/yaml-mode-test.el
@@ -0,0 +1,117 @@
+;;;; yaml-mode-test.el --- Tests for yaml-mode  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2010-2022 Yoshiki Kurihara
+
+;; Author: Yoshiki Kurihara <clouder@gmail.com>
+;;         Marshall T. Vandegrift <llasram@gmail.com>
+;; Maintainer: Vasilij Schneidermann <mail@vasilij.de>
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; many test utilities are copied from markdown-mode
+
+;;; Code:
+
+(require 'yaml-mode)
+(require 'ert)
+(require 'cl-lib)
+
+;; for version < 25
+(defconst yaml-test-font-lock-function
+  (if (fboundp 'font-lock-ensure)
+      #'font-lock-ensure #'font-lock-fontify-buffer))
+
+(defmacro yaml-test-string-mode (mode string &rest body)
+  "Run BODY in a temporary buffer containing STRING in MODE."
+  (declare (indent 2))
+  `(let ((win (selected-window)))
+     (unwind-protect
+         (with-temp-buffer
+           (set-window-buffer win (current-buffer) t)
+           (erase-buffer)
+           (insert ,string)
+           (funcall ,mode)
+           (funcall yaml-test-font-lock-function)
+           (setq-default indent-tabs-mode nil)
+           (goto-char (point-min))
+           (prog1 ,@body (kill-buffer))))))
+
+(defmacro yaml-test-string (string &rest body)
+  "Run BODY in a temporary buffer containing STRING in `yaml-mode'."
+  (declare (indent 1))
+  `(yaml-test-string-mode 'yaml-mode ,string ,@body))
+(def-edebug-spec yaml-test-string (form body))
+
+(defun yaml-test-report-property-range (begin end prop)
+  "Report buffer substring and property PROP from BEGIN to END."
+  (message "Buffer substring: %s" (buffer-substring begin (1+ end)))
+  (message "Properties in range are as follows:")
+  (dolist (loc (number-sequence begin end))
+    (message "%d: %s" loc (get-char-property loc prop))))
+
+(defun yaml-test-range-has-property (begin end prop value)
+  "Verify that range BEGIN to END has PROP equal to or containing VALUE."
+  (let (vals fail-loc)
+    (setq fail-loc
+          (catch 'fail
+            (dolist (loc (number-sequence begin end))
+              (setq vals (get-char-property loc prop))
+              (if (and vals (listp vals))
+                  (unless (memq value vals)
+                    (throw 'fail loc))
+                (unless (eq vals value)
+                  (throw 'fail loc))))))
+    (when fail-loc
+      (message "Testing range (%d,%d) for property %s equal to %s."
+               begin end prop value)
+      (message "Expected value (%s) not found in property (%s) at location %d" 
value prop fail-loc)
+      (yaml-test-report-property-range begin end prop))
+    (should-not fail-loc)))
+
+(defun yaml-test-range-has-face (begin end face)
+  "Verify that the range from BEGIN to END has face FACE."
+  (yaml-test-range-has-property begin end 'face face))
+
+;;; major-mode tests:
+
+(ert-deftest test-yaml-major-mode ()
+  "Test auto-mode-alist setting."
+  (dolist (extension '(".yml" ".yaml" ".eyml" ".eyaml" ".raml"))
+    (let ((file (make-temp-file "a" nil extension)))
+      (unwind-protect
+          (with-current-buffer (find-file-noselect file)
+            (should (eq major-mode 'yaml-mode)))
+        (delete-file file)))))
+
+;;; Regression tests:
+
+(ert-deftest highlighting/constant-before-comment ()
+  "Highlighting constant before comment.
+Detail: https://github.com/yoshiki/yaml-mode/issues/96";
+  (yaml-test-string "services:
+  - keystone:
+    tls: True
+  - horizon:
+    tls: True # comment
+"
+    (yaml-test-range-has-face 34 37 'font-lock-constant-face)
+    (yaml-test-range-has-face 61 64 'font-lock-constant-face)))
+
+(provide 'yaml-mode-test)
+
+;;; yaml-mode-test.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]