-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtriples-test-utils.el
65 lines (54 loc) · 2.32 KB
/
triples-test-utils.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;;; triples-test-utils.el --- Test utilities for triples.el -*- lexical-binding: t; -*-
;; Copyright (C) 2023-2025 Free Software Foundation, Inc.
;; 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 2 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Thyis file contiains utilities for testing triples.el, all with the
;; `triples-test' prefix.
;;; Code:
(defvar triples-test-db-file nil
"The database file used in a test.
This is defined so we can easily debug into it.")
(defmacro triples-test-with-temp-db (&rest body)
"Run BODY with a temporary database file."
(declare (indent 0) (debug t))
`(let ((db-file (make-temp-file "triples-test")))
(unwind-protect
(progn
(let ((db (triples-connect db-file)))
(setq triples-test-db-file db-file)
,@body
(triples-close db)))
(delete-file db-file))))
(defun triples-test-open-db ()
"Open the database file used in the current test.
This is useful when debugging a test."
(interactive)
(sqlite-mode-open-file triples-test-db-file))
(defmacro triples-deftest (name _ &rest body)
"Create a test exercising variants of `triples-sqlite-interface'.
NAME is the name of the test, and BODY is the test code."
(declare (debug t) (indent 2))
(let ((builtin-name (intern (format "%s-builtin" name)))
(emacsql-name (intern (format "%s-emacsql" name))))
`(progn
(ert-deftest ,builtin-name ()
(let ((triples-sqlite-interface 'builtin))
(skip-unless (and (fboundp 'sqlite-available-p) (sqlite-available-p)))
,@body))
(ert-deftest ,emacsql-name ()
(let ((triples-sqlite-interface 'emacsql))
(skip-unless (featurep 'emacsql))
,@body)))))
(provide 'triples-test-utils)
;;; triples-test-utils.el ends here