summaryrefslogtreecommitdiff
path: root/bog-tests.el
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2020-06-25 15:06:51 +0100
committerBasil L. Contovounesios <contovob@tcd.ie>2020-06-25 15:07:15 +0100
commit6184e74ca8256d322276b50b0a4ea2ab072bb83a (patch)
tree74135975fdce8bc5dcb48a9014a167725b7645c4 /bog-tests.el
parentfbaa4793b183cb0fdac6404125e9024fc2cd4670 (diff)
downloadbog-6184e74ca8256d322276b50b0a4ea2ab072bb83a.tar.gz
Use lexical-binding and byte-compile tests
* Makefile (test, clean): Byte-compile test suite to catch more errors. * bog-tests.el: Use lexical-binding. Remove the need for cl-lib by replacing single cl-gensym with make-symbol. Declare 'citekey' as a special variable. Add footer line. (bog-tests-with-temp-dir): Replace cl-gensym with make-symbol. (bog-tests-with-temp-text): Allow instrumenting for debugging. Evaluate arguments only once. Don't assume 'citekey' is bound. Pass non-nil FIXEDCASE and LITERAL arguments to replace-match. Simplify with buffer rather than string manipulation. (bog-file-citekeys/multiple-variants): Fix typo caught by byte-compilation. * bog.el: Use lexical-binding. Quote function symbols as such. (bog--with-citekey-cache): Allow instrumenting for debugging. Replace cl-gensym with make-symbol. (bog-selection-method): Simplify and reindent. (bog--agenda-map): New keymap. (bog--with-search-lprops): Use it instead of generating it on the fly. Allow instrumenting for debugging. Don't use org-let which calls eval without lexical-binding. Bind uninterned symbol around body. Use unwind-protect to ensure org-lprops are restored. (bog-search-notes, bog-agenda-redo): Unquote body passed to bog--with-search-lprops now that it no longer uses org-let. (bog-command-map): Make docstring consistent with that of other keymaps.
Diffstat (limited to 'bog-tests.el')
-rw-r--r--bog-tests.el41
1 files changed, 21 insertions, 20 deletions
diff --git a/bog-tests.el b/bog-tests.el
index b1b2ea1..3a1539c 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -1,4 +1,4 @@
-;;; bog-tests.el --- Tests for Bog
+;;; bog-tests.el --- Tests for Bog -*- lexical-binding: t -*-
;; Copyright (C) 2013-2016 Kyle Meyer <kyle@kyleam.com>
@@ -19,15 +19,17 @@
;;; Code:
+(require 'bog)
(require 'ert)
(require 'org)
-(require 'cl-lib)
-(require 'bog)
+
+(with-no-warnings ;; Silence "lacks a prefix" warning.
+ (defvar citekey))
;; Modified from magit-tests.el.
(defmacro bog-tests-with-temp-dir (&rest body)
(declare (indent 0) (debug t))
- (let ((dir (cl-gensym)))
+ (let ((dir (make-symbol "dir")))
`(let ((,dir (file-name-as-directory (make-temp-file "dir" t))))
(unwind-protect
(let ((default-directory ,dir)) ,@body)
@@ -44,21 +46,18 @@ value of the variable `citekey'.
If the string \"<point>\" appears in TEXT then remove it and
place the point there before running BODY, otherwise place the
point at the beginning of the inserted text."
- (declare (indent 1))
- `(let* ((inside-text (if (stringp ,text) ,text (eval ,text)))
- (is-citekey (string-match "<citekey>" inside-text)))
- (when (and is-citekey citekey)
- (setq inside-text (replace-match citekey nil nil inside-text)))
- (with-temp-buffer
- (org-mode)
- (let ((point (string-match "<point>" inside-text)))
- (if point
- (progn
- (insert (replace-match "" nil nil inside-text))
- (goto-char (1+ (match-beginning 0))))
- (insert inside-text)
- (goto-char (point-min))))
- ,@body)))
+ (declare (indent 1) (debug t))
+ `(with-temp-buffer
+ (org-mode)
+ (insert ,text)
+ (goto-char (point-min))
+ (when (and (bound-and-true-p citekey)
+ (search-forward "<citekey>" nil t))
+ (replace-match citekey t t))
+ (goto-char (point-min))
+ (when (search-forward "<point>" nil t)
+ (replace-match "" t t))
+ ,@body))
;;; Citekey functions
@@ -410,7 +409,7 @@ some text"
(concat citekey ".txt")
(concat citekey "_0.pdf")
(concat citekey "-supplement.pdf")))
- found-files)
+ files-found)
(make-directory bog-file-directory)
(dolist (var variants)
(write-region "" nil (expand-file-name var bog-file-directory)))
@@ -582,3 +581,5 @@ some text"
(sort (bog--find-duplicates
(list "a" "b" "c" "b" "a"))
#'string-lessp))))
+
+;;; bog-tests.el ends here