[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/assess 7a3189a587 86/95: Remove types and replace with
From: |
ELPA Syncer |
Subject: |
[elpa] externals/assess 7a3189a587 86/95: Remove types and replace with convertors |
Date: |
Tue, 19 Jul 2022 15:57:36 -0400 (EDT) |
branch: externals/assess
commit 7a3189a5870fb20d179ff3ea761707a046814966
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>
Remove types and replace with convertors
"Types" were a nice idea, but in the end were just complicating
things, for little gain. We now convert into strings where needed.
---
.travis.yml | 4 ++
Makefile | 6 +--
assess.el | 135 +++++++++++++++++++++-------------------------------
test/assess-test.el | 105 +++++++++++++++++++---------------------
4 files changed, 110 insertions(+), 140 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index c4dfc6c8c8..3571992cdf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,10 @@ env:
- EVM_EMACS=emacs-24.4-travis
- EVM_EMACS=emacs-24.5-travis
- EVM_EMACS=emacs-25.1-travis
+ - EVM_EMACS=emacs-25.2-travis
+ - EVM_EMACS=emacs-25.3-travis
+ - EVM_EMACS=emacs-26-pretest-travis
+ - EVM_EMACS=emacs-git-snapshot-travis
install:
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw >
travis.sh && source ./travis.sh
- evm install $EVM_EMACS --use --skip
diff --git a/Makefile b/Makefile
index aff2ae3970..a95e173daa 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ just-test:
$(EMACS_ENV) $(CASK) emacs --batch -q \
--directory=. \
--load assess-discover.el \
- --funcall assess-discover-run-and-exit-batch
+ --eval '(assess-discover-run-and-exit-batch t)'
.PHONY: test dist
@@ -30,8 +30,8 @@ export:
multi-test:
make EMACS=$(EMACSES)/master/src/emacs test
- make EMACS=$(EMACSES)/emacs-25/src/emacs test
- make EMACS=$(EMACSES)/emacs-25.1/src/emacs test
+ make EMACS=$(EMACSES)/emacs-26.1/src/emacs test
+ make EMACS=$(EMACSES)/emacs-25.3/src/emacs test
make EMACS=$(EMACSES)/emacs-24.5/src/emacs test
make EMACS=$(EMACSES)/emacs-24.4/src/emacs test
make EMACS=$(EMACSES)/emacs-24.3/src/emacs test
diff --git a/assess.el b/assess.el
index e084e218f4..8ef1ae5799 100644
--- a/assess.el
+++ b/assess.el
@@ -242,42 +242,31 @@ effectively, placed within an impicit `progn'."
"Insert X in a type-appropriate way into a temp buffer and eval
BODY there.
-See `assess-to-string' for the meaning of type-appropriate."
+See `assess-ensure-string' for the meaning of type-appropriate."
(declare (indent 1) (debug t))
`(with-temp-buffer
- (insert (assess-to-string ,x))
+ (insert (assess-ensure-string ,x))
,@body))
;; #+end_src
-;; ** Types
+;; ** Converters
-;; Many tests on files or buffers actually end up being string comparison.
-;; In many cases, we want to compare the *contents* of a buffer to, for
example,
-;; the *contents* of a file.
-
-;; Emacs normally uses strings to represent files (i.e. file names) and can
also
-;; use them to represent buffers (i.e. buffer names). So, here, we introduce a
-;; set of "types" where so that we can distinguish between strings, buffer
names
-;; and file names, passing them at a single parameter. This will allow us to
make
-;; later parts of the API use overloaded methods based on their type.
-
-;; "Types" are either a Emacs core type (as with buffers and strings), or an 2
-;; element list (I haven't used cons cells in case I want to add more
elements),
-;; with a keyword at the head. This allows assess to distinguish between a
-;; simple string and a file or buffer name.
+;; The majority of test functionality compares strings. We provide
+;; here some functions to convert between other Emacs types and
+;; strings.
;; #+begin_src elisp
-;; ;; Identify "~/.emacs" as a file name
+;; ;; Return a string of the contents of .emacs
;; (assess-file "~/.emacs")
-;; ;; Identify "*Messages*" as a buffer
+;; ;; Return the contents of the buffer with name *Messages*
;; (assess-buffer "*Messages*")
;; #+end_src
;; *** Implementation
;; #+begin_src emacs-lisp
-(defun assess-to-string (x)
+(defun assess-ensure-string (x)
"Turn X into a string in a type appropriate way.
If X is identified as a file, returns the file contents.
@@ -286,34 +275,22 @@ If X is a string, returns that.
See also `assess-buffer' and `assess-file' which turn a
string into something that will identified appropriately."
- (pcase x
- ((pred stringp) x)
- ((pred bufferp) (m-buffer-at-string x))
- (`(:buffer ,b) (assess-to-string (get-buffer-create b)))
- (`(:file ,f)
- (with-temp-buffer
- (insert-file-contents f)
- (buffer-string)))
- ;; error condition
- (_ (error "Type not recognised"))))
-
-(defun assess-buffer (b)
- "Add type data to the string B marking it as a buffer."
- `(:buffer ,b))
+ (cond
+ ((stringp x) x)
+ ((bufferp x) (m-buffer-at-string x))
+ (t (error "Type not recognised"))))
+
+(defalias 'assess-buffer 'get-buffer-create
+ "Create a buffer.
+
+This is now an alias for `get-buffer-create' but used to do
+ something quite different.")
(defun assess-file (f)
- "Add type data to the string F marking it as a file."
- `(:file ,f))
-
-(defun assess-to-file-name (file)
- "Return file name for FILE.
-
-FILE can be either a string, or a plist returned by
-`assess-file' or `assess-make-related-file'."
- (pcase file
- ((pred stringp) file)
- (`(:file ,f) f)
- (_ (error "Type not recognised"))))
+ "Convert a file to the string contents of that file."
+ (with-temp-buffer
+ (insert-file-contents f)
+ (buffer-string)))
;; #+end_src
;; ** Entity Comparison
@@ -482,16 +459,16 @@ contents and so on.
Text properties in strings or buffers are ignored."
(string=
- (assess-to-string a)
- (assess-to-string b)))
+ (assess-ensure-string a)
+ (assess-ensure-string b)))
(defun assess-explain= (a b)
"Compare A and B and return an explanation.
This function is called by ERT as an explainer function
automatically. See `assess=' for more information."
- (let ((a (assess-to-string a))
- (b (assess-to-string b)))
+ (let ((a (assess-ensure-string a))
+ (b (assess-ensure-string b)))
(cond
((assess= a b)
t)
@@ -565,12 +542,10 @@ the same file extension.
This is useful for making test changes to FILE without actually
altering it."
- (let* ((file (assess-to-file-name file))
- (related-file
+ (let* ((related-file
(assess--make-related-file-1 file directory)))
(copy-file file related-file t)
- (assess-file
- related-file)))
+ related-file))
(defmacro assess-with-find-file (file &rest body)
"Open FILE and evaluate BODY in resultant buffer.
@@ -583,17 +558,14 @@ unconditionally, even if the buffer has changed.
See also `assess-make-related-file'."
(declare (debug t) (indent 1))
(let ((temp-buffer (make-symbol "temp-buffer"))
- (file-has-buffer-p (make-symbol "file-has-buffer-p"))
- (file-s (make-symbol "file")))
- `(let* ((,file-s ,file)
- (,file-s (assess-to-file-name ,file-s))
- (,file-has-buffer-p
- (find-buffer-visiting ,file-s))
+ (file-has-buffer-p (make-symbol "file-has-buffer-p")))
+ `(let* ((,file-has-buffer-p
+ (find-buffer-visiting ,file))
(,temp-buffer))
(unwind-protect
(with-current-buffer
(setq ,temp-buffer
- (find-file-noselect ,file-s))
+ (find-file-noselect ,file))
,@body)
(when
;; kill the buffer unless it was already open.
@@ -773,24 +745,25 @@ for change."
;; #+begin_src emacs-lisp
(defun assess--indent-buffer (&optional column)
- (cond
- (column
- (indent-region (point-min) (point-max) column))
- ;; if indent-region-function is set, use it, and hope that it is not
- ;; noisy.
- (indent-region-function
- (funcall indent-region-function (point-min) (point-max)))
- (t
- (seq-map
- (lambda (m)
- (goto-char m)
- (indent-according-to-mode))
- (m-buffer-match-line-start (current-buffer))))))
+ (let ((inhibit-message t))
+ (cond
+ (column
+ (indent-region (point-min) (point-max) column))
+ ;; if indent-region-function is set, use it, and hope that it is not
+ ;; noisy.
+ (indent-region-function
+ (funcall indent-region-function (point-min) (point-max)))
+ (t
+ (seq-map
+ (lambda (m)
+ (goto-char m)
+ (indent-according-to-mode))
+ (m-buffer-match-line-start (current-buffer)))))))
(defun assess--indent-in-mode (mode unindented)
(with-temp-buffer
(insert
- (assess-to-string unindented))
+ (assess-ensure-string unindented))
(funcall mode)
(assess--indent-buffer)
(buffer-string)))
@@ -802,7 +775,7 @@ for change."
(defun assess-indentation= (mode unindented indented)
"Return non-nil if UNINDENTED indents in MODE to INDENTED.
Both UNINDENTED and INDENTED can be any value usable by
-`assess-to-string'. Indentation is performed using
+`assess-ensure-string'. Indentation is performed using
`indent-region', which MODE should set up appropriately.
See also `assess-file-roundtrip-indentation=' for an
@@ -838,7 +811,7 @@ alternative mechanism."
mode
(progn
(insert
- (assess-to-string indented))
+ (assess-ensure-string indented))
(assess--buffer-unindent (current-buffer))
(buffer-string))
indented)))
@@ -878,7 +851,7 @@ mechanisms of checking indentation."
(assess--buffer-unindent (current-buffer))
(assess--indent-buffer)
(buffer-string))
- file))
+ (assess-file file)))
(defun assess-file-roundtrip-indentation= (file)
"Return t if text in FILE is indented correctly.
@@ -1093,7 +1066,7 @@ the copy of FILE will be in a different directory."
(defun assess--face-at=-1 (x mode locations faces property throw-on-nil)
(with-temp-buffer
- (insert (assess-to-string x))
+ (insert (assess-ensure-string x))
(funcall mode)
(font-lock-fontify-buffer)
(assess--face-at= (current-buffer) locations faces property throw-on-nil)))
@@ -1110,7 +1083,7 @@ match data, then each the beginning and end of each match
are
tested against each face.
X can be a buffer, file name or string -- see
-`assess-to-string' for details.
+`assess-ensure-string' for details.
MODE is the major mode with which to fontify X -- actually, it
will just be a function called to initialize the buffer.
@@ -1124,7 +1097,7 @@ FACES can be one or more faces.
PROPERTY is the text property on which to check the faces.
-See also `assess-to-string' for treatment of the parameter X.
+See also `assess-ensure-string' for treatment of the parameter X.
See `assess-file-face-at=' for a similar function which
operates over files and takes the mode from that file."
diff --git a/test/assess-test.el b/test/assess-test.el
index ecd4fb2dcf..4bc06abf53 100644
--- a/test/assess-test.el
+++ b/test/assess-test.el
@@ -44,16 +44,18 @@
(ert-test-result-with-condition-condition result)))
(ert-deftest plist-extraction ()
- (should
- (equal
- (assess-test--plist-from-result
- (ert-run-test
- (make-ert-test
- :body
- (lambda ()
- (should
- (eq 1 2))))))
- '(:form (eq 1 2) :value nil))))
+ (let ((tmp
+ (assess-test--plist-from-result
+ (ert-run-test
+ (make-ert-test
+ :body
+ (lambda ()
+ (should
+ (eq 1 2))))))))
+ (should
+ (equal
+ tmp
+ '(:form (eq 1 2) :value nil)))))
(defun assess-test--explanation-from-result (result)
(plist-get
@@ -63,14 +65,15 @@
(ert-deftest explanation-extraction-from-result ()
"Test that explanation is extractable from failing test.
This also tests the advice on string=."
- (should
- (assess-test--explanation-from-result
- (ert-run-test
- (make-ert-test
- :body
- (lambda ()
- (should
- (assess= "1" "2"))))))))
+ (let ((tmp
+ (ert-run-test
+ (make-ert-test
+ :body
+ (lambda ()
+ (should
+ (assess= "1" "2")))))))
+ (should
+ (assess-test--explanation-from-result tmp))))
(defun assess-test--explanation (f)
(assess-test--explanation-from-result
@@ -88,39 +91,29 @@ This also tests the advice on string=."
(assess= "1" "2"))))))
;; #+end_src
-;; ** To-String testing
+;; ** Ensure-String testing
;; #+begin_src emacs-lisp
(defvar assess-test-hello.txt
- (assess-file
- (relative-expand-file-name "../dev-resources/hello.txt")))
+ (relative-expand-file-name "../dev-resources/hello.txt"))
-(ert-deftest to-string ()
+(ert-deftest ensure-string ()
(should
(equal "hello"
- (assess-to-string "hello")))
- (should
- (with-temp-buffer
- (equal "hello"
- (progn
- (insert "hello")
- (assess-to-string (current-buffer))))))
+ (assess-ensure-string "hello")))
(should
(with-temp-buffer
(equal "hello"
(progn
(insert "hello")
- (assess-to-string
- (list
- :buffer
- (buffer-name (current-buffer))))))))
+ (assess-ensure-string (current-buffer))))))
(should
(with-temp-buffer
(equal "hello\n"
- (assess-to-string
- assess-test-hello.txt))))
+ (assess-ensure-string
+ (assess-file assess-test-hello.txt)))))
(should-error
- (assess-to-string :hello)))
+ (assess-ensure-string :hello)))
;; #+end_src
@@ -191,18 +184,20 @@ This also tests the advice on string=."
(ert-deftest file-string= ()
(should
(assess=
- assess-test-hello.txt
+ (assess-file
+ assess-test-hello.txt)
"hello\n"))
(should-not
(assess=
- assess-test-hello.txt
+ (assess-file assess-test-hello.txt)
"goodbye"))
(should
(assess-test--explanation
(lambda ()
(should
(assess=
- assess-test-hello.txt
+ (assess-file
+ assess-test-hello.txt)
"goodbye"))))))
@@ -269,12 +264,12 @@ This also tests the advice on string=."
(ert-deftest assess-test-related-file ()
(should
(file-exists-p
- (assess-to-file-name
- (assess-make-related-file assess-test-hello.txt))))
+ (assess-make-related-file assess-test-hello.txt)))
(should
(assess=
- assess-test-hello.txt
- (assess-make-related-file assess-test-hello.txt))))
+ (assess-file assess-test-hello.txt)
+ (assess-file
+ (assess-make-related-file assess-test-hello.txt)))))
(ert-deftest assess-test-with-find-file ()
(should
@@ -384,24 +379,22 @@ This also tests the advice on string=."
(relative-expand-file-name "../dev-resources/"))
(defvar assess-dev-elisp-indented
- (assess-file
- (concat assess-dev-resources
- "elisp-indented.el")))
+ (concat assess-dev-resources
+ "elisp-indented.el"))
(defvar assess-dev-elisp-unindented
- (assess-file
- (concat assess-dev-resources
- "elisp-unindented.el")))
+ (concat assess-dev-resources
+ "elisp-unindented.el"))
(ert-deftest assess-test-roundtrip-indentation= ()
(should
(assess-roundtrip-indentation=
'emacs-lisp-mode
- assess-dev-elisp-indented))
+ (assess-file assess-dev-elisp-indented)))
(should-not
(assess-roundtrip-indentation=
'emacs-lisp-mode
- assess-dev-elisp-unindented)))
+ (assess-file assess-dev-elisp-unindented))))
(ert-deftest assess-test-roundtrip-indentation-explain= ()
(should
@@ -410,7 +403,7 @@ This also tests the advice on string=."
(should
(assess-roundtrip-indentation=
'emacs-lisp-mode
- assess-dev-elisp-unindented))))))
+ (assess-file assess-dev-elisp-unindented)))))))
(ert-deftest assess-test-file-roundtrip-indentation= ()
(should
@@ -430,9 +423,8 @@ This also tests the advice on string=."
;; ** Face Tests
(defvar assess-dev-elisp-fontified
- (assess-file
- (concat assess-dev-resources
- "elisp-fontified.el")))
+ (concat assess-dev-resources
+ "elisp-fontified.el"))
(ert-deftest assess-test-face-at-simple ()
(should
@@ -530,7 +522,8 @@ This also tests the advice on string=."
(assess-face-at= "foo bar" 'fundamental-mode
"bar" 'font-lock-type-face))
(should-not
- (assess-face-at= "def" 'python-mode "def" nil)))
+ (let ((inhibit-message t))
+ (assess-face-at= "def" 'python-mode "def" nil))))
;; https://github.com/phillord/assess/issues/5
(ert-deftest issue-5-test-example ()
- [elpa] externals/assess 38fc7829bc 42/95: Interpret nil to mean no faces., (continued)
- [elpa] externals/assess 38fc7829bc 42/95: Interpret nil to mean no faces., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 818cf77258 27/95: Merge pull request #2 from syohex/minimum, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 880d519d6b 35/95: Update readme, add infojs., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 216adb069c 47/95: Add assess-call.el, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 07bd7f8915 58/95: Doc fixes, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 739661405b 59/95: Add assess-robot.el and tests, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 9521b07480 71/95: Fix and Publish documentation statically, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 5aee8d7500 81/95: Mark some tests as failed on earlier emacs, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0a3e94477a 78/95: Support all of Emacs 24 series, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e5b0415126 85/95: Update README and release number, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 7a3189a587 86/95: Remove types and replace with convertors,
ELPA Syncer <=
- [elpa] externals/assess 5bac045b27 94/95: Update version, ELPA Syncer, 2022/07/19
- [elpa] externals/assess ac8ff1f928 39/95: Change all file names to assess., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 4bf702a08a 43/95: Re-order to put macros first., ELPA Syncer, 2022/07/19
- [elpa] externals/assess e9344a55df 45/95: Move from ert to assess-discover, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 7409b103a3 46/95: Update .gitignore, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e1b7740df5 55/95: Add unwind-protect to assess-call functions, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 2335b8bd69 63/95: Remove old call-capture variable, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 61771edab7 67/95: Move cask to melpa-stable, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e2e5f1cbbd 69/95: Merge pull request #6 from NicolasPetton/master, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 70c6d8c57d 70/95: Fix a few typos, ELPA Syncer, 2022/07/19