1 ;;; f90-tests.el --- Tests for f90-interface-browser
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program If not, see <http://www.gnu.org/licenses/>.
20 (defvar *test-name* nil)
22 (defvar *test-tests* (make-hash-table :test 'eq))
24 (defvar *test-running-tests* nil)
25 (defmacro deftest (name parameters &rest body)
26 "Define a test function. Within a test function we can call
27 other test functions or use 'check' to run individual test
30 (setf (gethash ',name *test-tests*)
32 (let ((*test-name* (append *test-name* (list ',name))))
35 (defmacro test-check (&rest forms)
36 "Run each expression in 'forms' as a test case."
37 `(test-combine-results
38 ,@(loop for (expr res) in forms
39 collect `(test-report-result (equal (condition-case err
41 (error (gensym))) ',res)
44 (defmacro test-combine-results (&rest forms)
45 "Combine the results (as booleans) of evaluating 'forms' in order."
46 (let ((result (make-symbol "result")))
48 ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
51 (defun test-report-result (result res req)
52 "Report the results of a single test case. Called by 'check'."
54 (insert (format "%s ... %S: %S\n"
56 'face '(:weight bold :foreground "green"))
58 (insert (format "%s ... %S: %S is not %S\n"
60 'face '(:weight bold :foreground "red"))
65 (defun test-run-test (name)
66 (with-current-buffer (get-buffer-create "*test-results*")
67 (unless *test-running-tests*
69 (let ((*test-running-tests* t))
70 (funcall (gethash name *test-tests*)))
71 (pop-to-buffer (current-buffer))))
73 (deftest type-modifiers ()
75 ((f90-split-declaration "integer") ("integer"))
76 ((f90-split-declaration "integer, pointer") ("integer" "pointer"))
77 ((f90-split-declaration "integer (kind = c_int(8) )") ("integer"))
78 ((f90-split-declaration "character(len=*)") ("character"))
79 ((f90-split-declaration "integer, dimension(:)")
80 ("integer" ("dimension" . 1)))))
82 (deftest parse-declaration ()
83 (flet ((fun (str) (with-temp-buffer
85 (goto-char (point-min))
86 (f90-parse-single-type-declaration))))
88 ((fun "integer :: name") (("name" "integer")))
89 ((fun "integer :: name1, name2") (("name1" "integer")
91 ((fun "integer, dimension(:) :: name1, name2(:, :)") (("name1" "integer"
95 ((fun "integer, pointer :: name(:, :)") (("name" "integer" "pointer"
97 ((fun "integer, pointer :: NAmE => null()") (("name" "integer" "pointer"))))))
102 ((f90-count-commas ",") 1)
103 ((f90-count-commas "(,)") 0)
104 ((f90-count-commas "a, b, size(c, d)") 2)
105 ((f90-count-commas "a, b, size(c, d)" 1) 3)
106 ((f90-split-arglist "a,B") ("a" "b"))
107 ((f90-split-arglist "foo, dimension(1, size(a, b))")
108 ("foo" "dimension(1, size(a, b))"))
109 ((f90-parse-names-list "a=1, B=>null()") ("a" "b"))))
112 (test-combine-results
113 (test-run-test 'type-modifiers)
114 (test-run-test 'parse-declaration)
115 (test-run-test 'splits)))