gpgscm: Fail early if the test setup fails.
[gnupg.git] / tests / gpgme / all-tests.scm
1 ;; Copyright (C) 2016 g10 Code GmbH
2 ;;
3 ;; This file is part of GnuPG.
4 ;;
5 ;; GnuPG 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.
9 ;;
10 ;; GnuPG 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.
14 ;;
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/>.
17
18 (export all-tests
19  ;; Parse GPGME's makefiles to find all tests.
20
21  (load (in-srcdir "tests" "gpgme" "gpgme-defs.scm"))
22  (load (with-path "makefile.scm"))
23
24  (define (expander filename port key)
25    ;;(interactive-repl (current-environment))
26    (cond
27     ((string=? key "tests_unix")
28      (if *win32*
29          (parse-makefile port key)   ;; Use win32 definition.
30          (begin
31            (parse-makefile port key) ;; Skip win32 definition.
32            (parse-makefile port key))))
33     (else
34      (parse-makefile port key))))
35
36  (define (parse filename key)
37    (parse-makefile-expand filename expander key))
38
39  (define setup-c
40    (make-environment-cache
41     (test::scm
42      #f
43      (path-join "tests" "gpgme" "setup.scm" "tests" "gpg")
44      (in-srcdir "tests" "gpgme" "setup.scm")
45      "--" "tests" "gpg")))
46  (define setup-py
47    (make-environment-cache
48     (test::scm
49      #f
50      (path-join "tests" "gpgme" "setup.scm" "lang" "python" "tests")
51      (in-srcdir "tests" "gpgme" "setup.scm")
52      "--" "lang" "python" "tests")))
53
54  (define (compiled? name)
55    (not (or (string-suffix? name ".py")
56             (string-suffix? name ".test"))))
57  (define :path car)
58  (define :key cadr)
59  (define :setup caddr)
60
61  (if (have-gpgme?)
62      (apply append
63             (map (lambda (cmpnts)
64                    (define (find-test name)
65                      (apply path-join
66                             `(,(if (compiled? name)
67                                    gpgme-builddir
68                                    gpgme-srcdir) ,@(:path cmpnts) ,(qualify name))))
69                    (let ((makefile (apply path-join `(,gpgme-srcdir ,@(:path cmpnts)
70                                                                     "Makefile.am"))))
71                      (map (lambda (name)
72                             (apply test::scm
73                                    `(,(:setup cmpnts)
74                                      ,(apply path-join
75                                              `("tests" "gpgme" ,@(:path cmpnts) ,name))
76                                      ,(in-srcdir "tests" "gpgme" "wrap.scm")
77                                      --executable
78                                      ,(find-test name)
79                                      -- ,@(:path cmpnts))))
80                           (parse makefile (:key cmpnts)))))
81                  `((("tests" "gpg") "c_tests" ,setup-c)
82                    ,@(if (run-python-tests?)
83                          `((("lang" "python" "tests") "py_tests" ,setup-py))
84                          '())
85                    (("lang" "qt" "tests") "TESTS" ,setup-c))))
86      '()))