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

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

[nongnu] elpa/subed 4cab871f58 03/22: Add undercover support for coverag


From: ELPA Syncer
Subject: [nongnu] elpa/subed 4cab871f58 03/22: Add undercover support for coverage testing
Date: Tue, 1 Feb 2022 14:05:29 -0500 (EST)

branch: elpa/subed
commit 4cab871f583a4e4567fb84159d9da647a925904d
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>

    Add undercover support for coverage testing
    
    * Makefile (test-coverage): New target.
    (clean): Clean coverage data.
    (checkdoc): New target. Add subed-vtt and subed-ass.
    (test): Break out subtargets.
    * subed/subed-common.el (subed-enable-loop-over-current-subtitle):
    Pass along quiet flag.
    * subed/subed-ass.el (subed): Require subed.
    * subed/subed.el: Don't require the mode files.
    * tests/test-subed-ass.el: Load undercover-init.el.
    * tests/test-subed-common.el: Load undercover-init.el.
    ("Temporarily disabling point-to-player syncing"): Modify test to
    accommodate edebug from undercover.
    * tests/test-subed-mpv.el ("./tests/undercover-init.el"): Load 
undercover-init.el.
    * tests/test-subed-srt.el ("./tests/undercover-init.el"): Load 
undercover-init.el.
    * tests/test-subed-vtt.el ("./tests/undercover-init.el"): Load 
undercover-init.el.
---
 Makefile                   | 13 +++++++++++-
 subed/subed-ass.el         | 49 ++++++++++++++++++++++++++++------------------
 subed/subed-common.el      |  2 +-
 subed/subed-srt.el         |  1 +
 subed/subed-vtt.el         | 44 +++++++++++++++++++++++------------------
 subed/subed.el             |  3 ---
 tests/test-subed-ass.el    |  3 ++-
 tests/test-subed-common.el | 16 ++++++++-------
 tests/test-subed-mpv.el    |  4 ++--
 tests/test-subed-srt.el    |  5 ++---
 tests/test-subed-vtt.el    |  3 ++-
 11 files changed, 86 insertions(+), 57 deletions(-)

diff --git a/Makefile b/Makefile
index 91871cd8cc..d756e975bf 100644
--- a/Makefile
+++ b/Makefile
@@ -4,17 +4,28 @@
 
 clean:
        find . -name "*.elc" -delete
+       rm -f coverage/.*.json
 
-test:
+test: test-coverage package-lint checkdoc
+
+test-coverage:
+       UNDERCOVER_FORCE=true emacs -batch -L . -f package-initialize -f 
buttercup-run-discover
+
+test-only:
        emacs -batch -f package-initialize -L . -f buttercup-run-discover
+
+package-lint:
        emacs --no-init-file -f package-initialize --batch \
                  --eval "(require 'package-lint)" \
              --file package-lint-batch-and-exit \
              ./subed/subed.el
+checkdoc:
        emacs --quick --batch --eval "(checkdoc-file \"subed/subed.el\")"
        emacs --quick --batch --eval "(checkdoc-file \"subed/subed-config.el\")"
        emacs --quick --batch --eval "(checkdoc-file \"subed/subed-mpv.el\")"
        emacs --quick --batch --eval "(checkdoc-file \"subed/subed-srt.el\")"
+       emacs --quick --batch --eval "(checkdoc-file \"subed/subed-vtt.el\")"
+       emacs --quick --batch --eval "(checkdoc-file \"subed/subed-ass.el\")"
 
 autoloads:
        emacs --quick --batch --eval "(progn (setq generated-autoload-file 
(expand-file-name \"subed-autoloads.el\" \"subed\") backup-inhibited t) \
diff --git a/subed/subed-ass.el b/subed/subed-ass.el
index 3b5e46040d..15b4e9e5b6 100644
--- a/subed/subed-ass.el
+++ b/subed/subed-ass.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'subed)
 (require 'subed-config)
 (require 'subed-debug)
 (require 'subed-common)
@@ -63,13 +64,16 @@ Use the format-specific function for MAJOR-MODE."
            (truncate msecs))))))
 
 (cl-defmethod subed--msecs-to-timestamp (msecs &context (major-mode 
subed-ass-mode))
-  "Convert MSECS to string in the format H:MM:SS.CS."
+  "Convert MSECS to string in the format H:MM:SS.CS.
+Use the format-specific function for MAJOR-MODE."
   ;; We need to wrap format-seconds in save-match-data because it does regexp
   ;; stuff and we need to preserve our own match-data.
   (concat (save-match-data (format-seconds "%h:%02m:%02s" (/ msecs 1000)))
           "." (format "%02d" (/ (mod msecs 1000) 10))))
 
 (cl-defmethod subed--subtitle-id (&context (major-mode subed-ass-mode))
+  "Return the ID of the subtitle at point or nil if there is no ID.
+Use the format-specific function for MAJOR-MODE."
   (save-excursion
     (when (and (subed--jump-to-subtitle-time-start)
                (looking-at subed--regexp-timestamp))
@@ -78,7 +82,7 @@ Use the format-specific function for MAJOR-MODE."
 (cl-defmethod subed--subtitle-id-at-msecs (msecs &context (major-mode 
subed-ass-mode))
   "Return the ID of the subtitle at MSECS milliseconds.
 Return nil if there is no subtitle at MSECS.
-Use the format-specific function for BACKEND."
+Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (save-excursion
       (goto-char (point-min))
@@ -135,7 +139,8 @@ Use the format-specific function for MAJOR-MODE."
 (cl-defmethod subed--jump-to-subtitle-time-start (&context (major-mode 
subed-ass-mode) &optional sub-id)
   "Move point to subtitle's start time.
 If SUB-ID is not given, use subtitle on point.
-Return point or nil if no start time could be found."
+Return point or nil if no start time could be found.
+Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (when (subed-jump-to-subtitle-id sub-id)
       (when (re-search-forward subed--regexp-timestamp (line-end-position) t)
@@ -144,8 +149,9 @@ Return point or nil if no start time could be found."
 
 (cl-defmethod subed--jump-to-subtitle-time-stop (&context (major-mode 
subed-ass-mode) &optional sub-id)
   "Move point to subtitle's stop time.
-If SUB-ID is not given, use subtitle on point.
-Return point or nil if no stop time could be found."
+If SUB-ID is not given, use subtitle on point.  Return point or
+nil if no stop time could be found.  Use the format-specific
+function for MAJOR-MODE."
   (save-match-data
     (when (subed-jump-to-subtitle-id sub-id)
       (re-search-forward (concat "\\(?:" subed--regexp-timestamp "\\),") 
(point-at-eol) t)
@@ -154,8 +160,9 @@ Return point or nil if no stop time could be found."
 
 (cl-defmethod subed--jump-to-subtitle-text (&context (major-mode 
subed-ass-mode) &optional sub-id)
   "Move point on the first character of subtitle's text.
-If SUB-ID is not given, use subtitle on point.
-Return point or nil if a the subtitle's text can't be found."
+If SUB-ID is not given, use subtitle on point.  Return point or
+nil if a the subtitle's text can't be found.  Use the
+format-specific function for MAJOR-MODE."
   (when (subed-jump-to-subtitle-id sub-id)
     (beginning-of-line)
     (when (looking-at ".*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,.*?,")
@@ -164,9 +171,9 @@ Return point or nil if a the subtitle's text can't be 
found."
 
 (cl-defmethod subed--jump-to-subtitle-end (&context (major-mode 
subed-ass-mode) &optional sub-id)
   "Move point after the last character of the subtitle's text.
-If SUB-ID is not given, use subtitle on point.
-Return point or nil if point did not change or if no subtitle end
-can be found."
+If SUB-ID is not given, use subtitle on point.  Return point or
+nil if point did not change or if no subtitle end can be found.
+Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (let ((orig-point (point)))
       (when (subed-jump-to-subtitle-text sub-id)
@@ -176,7 +183,8 @@ can be found."
 
 (cl-defmethod subed--forward-subtitle-id (&context (major-mode subed-ass-mode))
   "Move point to next subtitle's ID.
-Return point or nil if there is no next subtitle."
+Return point or nil if there is no next subtitle.  Use the
+format-specific function for MAJOR-MODE."
   (save-match-data
     (let ((pos (point)))
       (forward-line 1)
@@ -190,7 +198,8 @@ Return point or nil if there is no next subtitle."
 
 (cl-defmethod subed--backward-subtitle-id (&context (major-mode 
subed-ass-mode))
   "Move point to previous subtitle's ID.
-Return point or nil if there is no previous subtitle."
+Return point or nil if there is no previous subtitle.  Use the
+format-specific function for MAJOR-MODE."
   (let ((orig-point (point)))
     (when (subed-jump-to-subtitle-id)
       (forward-line -1)
@@ -211,7 +220,8 @@ STOP defaults to (+ START `subed-subtitle-spacing')
 TEXT defaults to an empty string.
 
 A newline is appended to TEXT, meaning you'll get two trailing
-newlines if TEXT is nil or empty."
+newlines if TEXT is nil or empty.  Use the format-specific
+function for MAJOR-MODE."
   (format "Dialogue: 0,%s,%s,Default,,0,0,0,,%s\n"
           (subed-msecs-to-timestamp (or start 0))
           (subed-msecs-to-timestamp (or stop (+ (or start 0)
@@ -225,8 +235,8 @@ ID and START default to 0.
 STOP defaults to (+ START `subed-subtitle-spacing')
 TEXT defaults to an empty string.
 
-Move point to the text of the inserted subtitle.
-Return new point."
+Move point to the text of the inserted subtitle.  Return new
+point.  Use the format-specific function for MAJOR-MODE."
   (subed-jump-to-subtitle-id)
   (insert (subed-make-subtitle id start stop text))
   (forward-line -1)
@@ -239,8 +249,8 @@ ID, START default to 0.
 STOP defaults to (+ START `subed-subtitle-spacing')
 TEXT defaults to an empty string.
 
-Move point to the text of the inserted subtitle.
-Return new point."
+Move point to the text of the inserted subtitle.  Return new
+point.  Use the format-specific function for MAJOR-MODE."
   (unless (subed-forward-subtitle-id)
     ;; Point is on last subtitle or buffer is empty
     (subed-jump-to-subtitle-end)
@@ -251,7 +261,8 @@ Return new point."
 
 (cl-defmethod subed--merge-with-next (&context (major-mode subed-ass-mode))
   "Merge the current subtitle with the next subtitle.
-Update the end timestamp accordingly."
+Update the end timestamp accordingly.  Use the format-specific
+function for MAJOR-MODE."
   (save-excursion
     (subed-jump-to-subtitle-end)
     (let ((pos (point)) new-end)
@@ -269,7 +280,7 @@ Update the end timestamp accordingly."
 ;;;###autoload
 (define-derived-mode subed-ass-mode subed-mode "Subed-ASS"
   "Major mode for editing Advanced SubStation Alpha subtitle files."
-  (setq-local subed--subtitle-format "ass")  
+  (setq-local subed--subtitle-format "ass")
   (setq-local subed--regexp-timestamp subed-ass--regexp-timestamp)
   (setq-local subed--regexp-separator subed-ass--regexp-separator)
   (setq-local font-lock-defaults '(subed-ass-font-lock-keywords)))
diff --git a/subed/subed-common.el b/subed/subed-common.el
index af3e8337b6..bfc3a46f0b 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -1305,7 +1305,7 @@ If QUIET is non-nil, do not display a message in the 
minibuffer."
     (add-hook 'subed-subtitle-motion-hook #'subed--set-subtitle-loop :append 
:local)
     (subed-debug "Enabling loop: %s - %s" subed--subtitle-loop-start 
subed--subtitle-loop-stop)
     (when (subed-sync-point-to-player-p)
-      (subed-disable-sync-point-to-player)
+      (subed-disable-sync-point-to-player quiet)
       (setq subed--enable-point-to-player-sync-after-disabling-loop t))
     (unless quiet
       (message "Enabled looping over current subtitle"))))
diff --git a/subed/subed-srt.el b/subed/subed-srt.el
index ad231ce8f9..44f8ce06c0 100644
--- a/subed/subed-srt.el
+++ b/subed/subed-srt.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'subed)
 (require 'subed-config)
 (require 'subed-debug)
 (require 'subed-common)
diff --git a/subed/subed-vtt.el b/subed/subed-vtt.el
index 15cf027b3b..45f7ce8400 100644
--- a/subed/subed-vtt.el
+++ b/subed/subed-vtt.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'subed)
 (require 'subed-config)
 (require 'subed-debug)
 (require 'subed-common)
@@ -48,7 +49,8 @@
 
 (cl-defmethod subed--timestamp-to-msecs (time-string &context (major-mode 
subed-vtt-mode))
   "Find HH:MM:SS.MS pattern in TIME-STRING and convert it to milliseconds.
-Return nil if TIME-STRING doesn't match the pattern."
+Return nil if TIME-STRING doesn't match the pattern.
+Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (when (string-match subed--regexp-timestamp time-string)
       (let ((hours (string-to-number (or (match-string 2 time-string) "0")))
@@ -61,7 +63,8 @@ Return nil if TIME-STRING doesn't match the pattern."
            (truncate msecs))))))
 
 (cl-defmethod subed--msecs-to-timestamp (msecs &context (major-mode 
subed-vtt-mode))
-  "Convert MSECS to string in the format HH:MM:SS.MS."
+  "Convert MSECS to string in the format HH:MM:SS.MS.
+Use the format-specific function for MAJOR-MODE."
   ;; We need to wrap format-seconds in save-match-data because it does regexp
   ;; stuff and we need to preserve our own match-data.
   (concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000)))
@@ -144,7 +147,8 @@ Use the format-specific function for MAJOR-MODE."
 (cl-defmethod subed--jump-to-subtitle-time-stop (&context (major-mode 
subed-vtt-mode) &optional sub-id)
   "Move point to subtitle's stop time.
 If SUB-ID is not given, use subtitle on point.
-Return point or nil if no stop time could be found."
+Return point or nil if no stop time could be found.
+Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (when (subed-jump-to-subtitle-id sub-id)
       (re-search-forward " *--> *" (point-at-eol) t)
@@ -154,7 +158,8 @@ Return point or nil if no stop time could be found."
 (cl-defmethod subed--jump-to-subtitle-text (&context (major-mode 
subed-vtt-mode) &optional sub-id)
   "Move point on the first character of subtitle's text.
 If SUB-ID is not given, use subtitle on point.
-Return point or nil if a the subtitle's text can't be found."
+Return point or nil if a the subtitle's text can't be found.
+Use the format-specific function for MAJOR-MODE."
   (when (subed-jump-to-subtitle-id sub-id)
     (forward-line 1)
     (point)))
@@ -163,7 +168,7 @@ Return point or nil if a the subtitle's text can't be 
found."
   "Move point after the last character of the subtitle's text.
 If SUB-ID is not given, use subtitle on point.
 Return point or nil if point did not change or if no subtitle end
-can be found."
+can be found.  Use the format-specific function for MAJOR-MODE."
   (save-match-data
     (let ((orig-point (point)))
       (subed-jump-to-subtitle-text sub-id)
@@ -181,14 +186,16 @@ can be found."
 
 (cl-defmethod subed--forward-subtitle-id (&context (major-mode subed-vtt-mode))
   "Move point to next subtitle's ID.
-Return point or nil if there is no next subtitle."
+Return point or nil if there is no next subtitle.  Use the
+format-specific function for MAJOR-MODE."
   (save-match-data
     (when (re-search-forward (concat subed--regexp-separator 
subed--regexp-timestamp) nil t)
       (subed-jump-to-subtitle-id))))
 
 (cl-defmethod subed--backward-subtitle-id (&context (major-mode 
subed-vtt-mode))
   "Move point to previous subtitle's ID.
-Return point or nil if there is no previous subtitle."
+Return point or nil if there is no previous subtitle.  Use the
+format-specific function for MAJOR-MODE."
   (let ((orig-point (point)))
     (when (subed-jump-to-subtitle-id)
       (if (re-search-backward (concat "\\(" subed--regexp-separator 
"\\|\\`[[:space:]]*\\)\\(" subed--regexp-timestamp "\\)") nil t)
@@ -208,7 +215,8 @@ STOP defaults to (+ START `subed-subtitle-spacing')
 TEXT defaults to an empty string.
 
 A newline is appended to TEXT, meaning you'll get two trailing
-newlines if TEXT is nil or empty."
+newlines if TEXT is nil or empty.  Use the format-specific
+function for MAJOR-MODE."
   (format "%s --> %s\n%s\n"
           (subed-msecs-to-timestamp (or start 0))
           (subed-msecs-to-timestamp (or stop (+ (or start 0)
@@ -222,8 +230,8 @@ ID and START default to 0.
 STOP defaults to (+ START `subed-subtitle-spacing')
 TEXT defaults to an empty string.
 
-Move point to the text of the inserted subtitle.
-Return new point."
+Move point to the text of the inserted subtitle.  Return new
+point.  Use the format-specific function for MAJOR-MODE."
   (subed-jump-to-subtitle-id)
   (insert (subed-make-subtitle id start stop text))
   (save-match-data
@@ -278,7 +286,8 @@ Use the format-specific function for MAJOR-MODE."
 
 
 (cl-defmethod subed--sanitize (&context (major-mode subed-vtt-mode))
-  "Remove surplus newlines and whitespace."
+  "Remove surplus newlines and whitespace.
+Use the format-specific function for MAJOR-MODE."
   (atomic-change-group
     (save-match-data
       (subed-save-excursion
@@ -324,7 +333,8 @@ Use the format-specific function for MAJOR-MODE."
              (replace-match " --> "))))))))
 
 (cl-defmethod subed--validate (&context (major-mode subed-vtt-mode))
-  "Move point to the first invalid subtitle and report an error."
+  "Move point to the first invalid subtitle and report an error.
+Use the format-specific function for MAJOR-MODE."
   (when (> (buffer-size) 0)
     (atomic-change-group
       (save-match-data
@@ -348,7 +358,8 @@ Use the format-specific function for MAJOR-MODE."
           (goto-char orig-point))))))
 
 (cl-defmethod subed--sort (&context (major-mode subed-vtt-mode))
-  "Sanitize, then sort subtitles by start time."
+  "Sanitize, then sort subtitles by start time.
+Use the format-specific function for MAJOR-MODE."
   (atomic-change-group
     (subed-sanitize)
     (subed-validate)
@@ -365,18 +376,13 @@ Use the format-specific function for MAJOR-MODE."
                 ;; startkeyfun (return sort value of current record/subtitle)
                 #'subed-subtitle-msecs-start))))
 
-
-(cl-defmethod subed--init :after (&context (major-mode subed-vtt-mode))
-  "This function is called when subed-mode is entered for a SRT file."
-  )
-
 ;;;###autoload
 (define-derived-mode subed-vtt-mode subed-mode "Subed-VTT"
   "Major mode for editing WebVTT subtitle files."
   (setq-local subed--subtitle-format "vtt")
   (setq-local subed--regexp-timestamp subed-vtt--regexp-timestamp)
   (setq-local subed--regexp-separator subed-vtt--regexp-separator)
-  (setq-local font-lock-defaults '(subed-vtt-font-lock-keywords))  
+  (setq-local font-lock-defaults '(subed-vtt-font-lock-keywords))
   ;; Support for fill-paragraph (M-q)
   (let ((timestamps-regexp (concat subed--regexp-timestamp
                                    " *--> *"
diff --git a/subed/subed.el b/subed/subed.el
index b3c31f0650..aacd4c6036 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -35,9 +35,6 @@
 (require 'subed-config)
 (require 'subed-debug)
 (require 'subed-common)
-(require 'subed-srt)
-(require 'subed-vtt)
-(require 'subed-ass)
 (require 'subed-mpv)
 
 (defconst subed-mpv-frame-step-map
diff --git a/tests/test-subed-ass.el b/tests/test-subed-ass.el
index 624881f5fe..cd8cee4571 100644
--- a/tests/test-subed-ass.el
+++ b/tests/test-subed-ass.el
@@ -1,7 +1,8 @@
 ;; -*- eval: (buttercup-minor-mode) -*-
 
-(add-to-list 'load-path "./subed")
+(load-file "./tests/undercover-init.el")
 (require 'subed)
+(require 'subed-ass)
 
 (defvar mock-ass-data
   "[Script Info]
diff --git a/tests/test-subed-common.el b/tests/test-subed-common.el
index b11a874311..a77198f58d 100644
--- a/tests/test-subed-common.el
+++ b/tests/test-subed-common.el
@@ -1,7 +1,6 @@
 ;; -*- lexical-binding: t; eval: (buttercup-minor-mode) -*-
 
-(add-to-list 'load-path "./subed")
-(require 'subed)
+(load-file "./tests/undercover-init.el")
 (require 'subed-srt)
 
 (defvar mock-srt-data
@@ -2119,11 +2118,14 @@ Baz.
       (expect 'subed-disable-sync-point-to-player :to-have-been-called))
     (it "schedules re-enabling of point-to-player syncing."
       (subed-disable-sync-point-to-player-temporarily)
-      (expect 'run-at-time :to-have-been-called-with
-              subed-point-sync-delay-after-motion nil
-              '(closure (t) nil
-                        (setq subed--point-sync-delay-after-motion-timer nil)
-                        (subed-enable-sync-point-to-player :quiet))))
+      (expect 'run-at-time :to-have-been-called)
+      ;; Does not play well with undercover and edebug
+      ;; (expect 'run-at-time :to-have-been-called-with
+      ;;         subed-point-sync-delay-after-motion nil
+      ;;         '(closure (t) nil
+      ;;                   (setq subed--point-sync-delay-after-motion-timer 
nil)
+      ;;                   (subed-enable-sync-point-to-player :quiet)))
+      )
     (it "cancels previously scheduled re-enabling of point-to-player syncing."
       (subed-disable-sync-point-to-player-temporarily)
       (expect 'cancel-timer :not :to-have-been-called-with "mock timer")
diff --git a/tests/test-subed-mpv.el b/tests/test-subed-mpv.el
index 7613a31959..3c292a28b8 100644
--- a/tests/test-subed-mpv.el
+++ b/tests/test-subed-mpv.el
@@ -1,7 +1,7 @@
 ;; -*- eval: (buttercup-minor-mode) -*-
 
-(add-to-list 'load-path "./subed")
-(require 'subed)
+(load-file "./tests/undercover-init.el")
+(require 'subed-mpv)
 
 (describe "Starting mpv"
   (it "passes arguments to make-process."
diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el
index acf1496a23..d6d44aed68 100644
--- a/tests/test-subed-srt.el
+++ b/tests/test-subed-srt.el
@@ -1,8 +1,7 @@
 ;; -*- eval: (buttercup-minor-mode) -*-
 
-(add-to-list 'load-path "./subed")
-(require 'subed)
-
+(load-file "./tests/undercover-init.el")
+(require 'subed-srt)
 (defvar mock-srt-data
   "1
 00:01:01,000 --> 00:01:05,123
diff --git a/tests/test-subed-vtt.el b/tests/test-subed-vtt.el
index 5f4eb20c1f..cedec364dc 100644
--- a/tests/test-subed-vtt.el
+++ b/tests/test-subed-vtt.el
@@ -1,7 +1,8 @@
 ;; -*- eval: (buttercup-minor-mode) -*-
 
-(add-to-list 'load-path "./subed")
+(load-file "./tests/undercover-init.el")
 (require 'subed)
+(require 'subed-vtt)
 
 (defvar mock-vtt-data
   "WEBVTT



reply via email to

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