etest-execute.el: docs.
[ETest.git] / etest-execute.el
blob8a0ffecfca333f43761cd0a47373974ef80f5641
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 (defun etest-execute-get-test-file ()
38 "Find a test file by first checking the (buffer local) variable
39 `etest-file'. Then checking `etest-load-path' for a similarly
40 named (to the buffer) file. Then looking in `default-directory'."
41 (cond
42 ((and etest-file
43 (file-exists-p (expand-file-name etest-file)))
44 (expand-file-name etest-file))
45 ((and buffer-file-name
46 (catch 'found
47 (let ((etest-load-path (append etest-load-path
48 (list default-directory)))
49 (name (concat
50 (file-name-sans-extension
51 (file-name-nondirectory buffer-file-name)) ".etest")))
52 (mapc '(lambda (d)
53 (let ((name (expand-file-name (concat d "/" name))))
54 (when (file-exists-p name)
55 (throw 'found name))))
56 etest-load-path)
57 nil))))))
59 (defun etest-execute ()
60 "Execute a run for the current file using
61 `etest-execute-get-test-file'."
62 (interactive)
63 (let ((file (etest-execute-get-test-file)))
64 (unless file
65 (error "No matching .etest file found"))
66 (load-file file)))
68 (provide 'etest-execute)