etest.texinfo: A few details about etest-execute.el.
[ETest.git] / etest-execute.el
blobf778c929a54fececbb11b371839adc8b0071bb29
1 ;;; etest-execute.el --- Help the user run tests.
3 ;; Copyright (C) 2008 Philip Jackson
5 ;; Author: Philip Jackson <phil@shellarchive.co.uk>
7 ;; This file is not currently part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License as
11 ;; published by the Free Software Foundation; either version 2, or (at
12 ;; your option) any later version.
14 ;; This program is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program ; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;; This file will aid the execution of a test run. From any buffer
27 ;; simply run `etest-execute' and it will do its best to find a valid
28 ;; etest file and load it.
30 (make-variable-buffer-local
31 (defvar etest-file nil
32 "The path of the etest file associated with the current buffer."))
34 (defvar etest-load-path '("~/.etests")
35 "The path of the etest load path.")
37 ;; The only keybinding we make... hopefully
38 (add-hook 'emacs-lisp-mode-hook
39 (lambda ()
40 (local-set-key (kbd "C-c t") 'etest-execute)))
42 (defun etest-execute-get-test-file ()
43 "Find a test file by first checking the (buffer local) variable
44 `etest-file'. Then checking `etest-load-path' for a similarly
45 named (to the buffer) file. Then looking in `default-directory'."
46 (cond
47 ((and etest-file
48 (file-exists-p (expand-file-name etest-file)))
49 (expand-file-name etest-file))
50 ((and buffer-file-name
51 (catch 'found
52 (let ((etest-load-path (append etest-load-path
53 (list default-directory)))
54 (name (concat
55 (file-name-sans-extension
56 (file-name-nondirectory buffer-file-name)) ".etest")))
57 (mapc '(lambda (d)
58 (let ((name (expand-file-name (concat d "/" name))))
59 (when (file-exists-p name)
60 (throw 'found name))))
61 etest-load-path)
62 nil))))))
64 (defun etest-execute ()
65 "Execute a run for the current file using
66 `etest-execute-get-test-file'."
67 (interactive)
68 (let ((file (etest-execute-get-test-file)))
69 (unless file
70 (error "No matching .etest file found"))
71 (load-file file)))
73 (provide 'etest-execute)