etest-result-mode.el: Prettier alignment of metadata output.
[ETest.git] / etest-execute.el
blob138e997950bba676c5f67a4c1e7a3e5d9e81f670
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 (file-exists-p (expand-file-name etest-file)))
43 (expand-file-name etest-file))
44 ((and buffer-file-name
45 (catch 'found
46 (let ((etest-load-path (append etest-load-path
47 (list default-directory)))
48 (name (concat
49 (file-name-sans-extension
50 (file-name-nondirectory buffer-file-name)) ".etest")))
51 (mapc '(lambda (d)
52 (let ((name (expand-file-name (concat d "/" name))))
53 (when (file-exists-p name)
54 (throw 'found name))))
55 etest-load-path)
56 nil))))))
58 (defun etest-execute ()
59 "Execute a run for the current file using
60 `etest-execute-get-test-file'."
61 (interactive)
62 (let ((file (etest-execute-get-test-file)))
63 (unless file
64 (error "No matching .etest file found"))
65 (load-file file)))
67 (provide 'etest-execute)