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

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

[elpa] externals/hyperbole aeb5a31 37/50: Add defal defil tests plus som


From: Stefan Monnier
Subject: [elpa] externals/hyperbole aeb5a31 37/50: Add defal defil tests plus some extras (#49)
Date: Wed, 17 Mar 2021 18:44:20 -0400 (EDT)

branch: externals/hyperbole
commit aeb5a3121c917ef2bf3b7ef79a8f8855e3fe6d41
Author: Mats Lidell <mats.lidell@lidells.se>
Commit: GitHub <noreply@github.com>

    Add defal defil tests plus some extras (#49)
    
    * Mock man since it runs asynchronously
    
    * Add tests for defal and defil
    
    * Keep case on replacement text
    
    Co-authored-by: Mats Lidell <matsl@gnu.org>
---
 Changes                | 10 +++++++++
 hbut.el                |  2 +-
 test/demo-tests.el     | 16 ++++++--------
 test/hbut-tests.el     | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test/hibtypes-tests.el | 16 +++++---------
 5 files changed, 84 insertions(+), 20 deletions(-)

diff --git a/Changes b/Changes
index 801a325..f103344 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,13 @@
+2021-02-28  Mats Lidell  <matsl@gnu.org>
+
+* hbut.el (defil): Use FIXEDCASE is non-nil to not alter the case of the
+    replacement text.
+ 
+* test/hbut-tests.el (hbut-defal, hbut-defal-fails-on-file-missing)
+    (hbut-defil): Test for defal and defil implicit button macros.
+
+* (demo-man-appropos-test, ibtypes::man-apropos-test): Mock call to man.
+
 2021-02-21  Bob Weiner  <rsw@gnu.org>
 
 * hyperbole.el (hkey-define-key): Removed, had bug that did not use prefix
diff --git a/hbut.el b/hbut.el
index ec8662d..36c5692 100644
--- a/hbut.el
+++ b/hbut.el
@@ -1802,7 +1802,7 @@ commit changes."
                   (hact ,link-expr button-text)
                 (let ((referent (when (and button-text (stringp ,link-expr)
                                            (string-match ,text-regexp 
button-text))
-                                  (replace-match ,link-expr nil nil 
button-text))))
+                                  (replace-match ,link-expr t nil 
button-text))))
                   (ibtype:activate-link referent))))))
        (put (intern (format "ibtypes::%s" ',type))
            'function-documentation
diff --git a/test/demo-tests.el b/test/demo-tests.el
index 44f50e8..e258f4e 100644
--- a/test/demo-tests.el
+++ b/test/demo-tests.el
@@ -24,6 +24,7 @@
 (require 'hib-social)
 (require 'eww)
 (require 'compile)
+(require 'el-mock)
 
 (load (expand-file-name "hy-test-helpers"
                         (file-name-directory (or load-file-name
@@ -347,15 +348,12 @@
 
 ;; Man appropos
 (ert-deftest demo-man-appropos-test ()
-  (unwind-protect
-      (with-temp-buffer
-        (insert "rm (1)   - remove")
-        (goto-char 4)
-        (action-key)
-        (sit-for 0.2)
-        (set-buffer "*Man 1 rm*")
-        (should (looking-at "RM\(1\)")))
-    (kill-buffer "*Man 1 rm*")))
+  (with-temp-buffer
+    (insert "rm (1)   - remove")
+    (goto-char 4)
+    (with-mock
+      (mock (man "rm(1)") => t)
+      (action-key))))
 
 ;; Explicit buttons
 (ert-deftest demo-factorial-test ()
diff --git a/test/hbut-tests.el b/test/hbut-tests.el
new file mode 100644
index 0000000..766f755
--- /dev/null
+++ b/test/hbut-tests.el
@@ -0,0 +1,60 @@
+;;; hbut-tests.el --- hbut unit tests         -*- lexical-binding: t; -*-
+
+;; Author: Mats Lidell <matsl@gnu.org>
+;;
+;; Orig-Date: 28-Feb-21 at 22:52:00
+;;
+;; Copyright (C) 2021  Free Software Foundation, Inc.
+;; See the "HY-COPY" file for license information.
+;;
+;; This file is part of GNU Hyperbole.
+
+;;; Commentary:
+
+;; Runs unit tests on some of the examples given in the DEMO file.
+
+;;; Code:
+
+(require 'ert)
+(require 'hbut)
+
+(ert-deftest hbut-defal ()
+  (defal hfile "${hyperb:dir}/\\1")
+  (unwind-protect
+      (with-temp-buffer
+        (insert "<hfile DEMO>")
+        (goto-char 4)
+        (action-key)
+        (should (string= (concat hyperb:dir "DEMO") buffer-file-name))))
+    (progn
+      (kill-buffer "DEMO")
+      (fmakunbound 'ibtypes::hfile)))
+
+(ert-deftest hbut-defal-fails-on-file-missing ()
+  (defal hfile "${hyperb:dir}/\\1")
+  (unwind-protect
+      (with-temp-buffer
+        (insert "<hfile UNKNOWN-FILE>")
+        (goto-char 4)
+        (condition-case err
+            (action-key)
+          (error
+           (progn
+             (should (equal (car err) 'error))
+             (should (string-search "hpath:find" (cadr err)))))))
+    (fmakunbound 'ibtypes::hfile)))
+
+(ert-deftest hbut-defil ()
+  (defil hfile "<<<" ">>>" ".*" "${hyperb:dir}/\\&")
+  (unwind-protect
+      (with-temp-buffer
+        (insert "<<<DEMO>>>")
+        (goto-char 4)
+        (action-key)
+        (should (string= (concat hyperb:dir "DEMO") buffer-file-name)))
+    (progn
+      (kill-buffer "DEMO")
+      (fmakunbound 'ibtypes::hfile))))
+
+(provide 'hbut-tests)
+;;; hbut-tests.el ends here
diff --git a/test/hibtypes-tests.el b/test/hibtypes-tests.el
index 71041ce..b0a4cc5 100644
--- a/test/hibtypes-tests.el
+++ b/test/hibtypes-tests.el
@@ -189,16 +189,12 @@
 
 ;; man-apropos
 (ert-deftest ibtypes::man-apropos-test ()
-  (unwind-protect
-      (with-temp-buffer
-        (insert "rm (1)   - remove")
-        (goto-char 4)
-        (ibtypes::man-apropos)
-        (sit-for 0.2)
-        (set-buffer "*Man 1 rm*")
-        (should (looking-at "RM\(1\)")))
-    (kill-buffer "*Man 1 rm*")))
-
+  (with-temp-buffer
+    (insert "rm (1)   - remove")
+    (goto-char 4)
+    (with-mock
+     (mock (man "rm(1)") => t)
+     (ibtypes::man-apropos))))
 
 ;; klink
 



reply via email to

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