Add (guix scripts).
[jackhill/guix/guix.git] / tests / scripts.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19
20 (define-module (test-scripts)
21 #:use-module (guix scripts)
22 #:use-module ((guix scripts build)
23 #:select (%standard-build-options))
24 #:use-module (srfi srfi-64))
25
26 ;; Test the (guix scripts) module.
27
28 (define-syntax-rule (with-environment-variable variable value body ...)
29 "Run BODY with VARIABLE set to VALUE."
30 (let ((orig (getenv variable)))
31 (dynamic-wind
32 (lambda ()
33 (setenv variable value))
34 (lambda ()
35 body ...)
36 (lambda ()
37 (if orig
38 (setenv variable orig)
39 (unsetenv variable))))))
40
41 \f
42 (test-begin "scripts")
43
44 (test-equal "parse-command-line"
45 '((argument . "bar") (argument . "foo")
46 (cores . 10) ;takes precedence
47 (substitutes? . #f) (keep-failed? . #t)
48 (max-jobs . 77) (cores . 42))
49
50 (with-environment-variable "GUIX_BUILD_OPTIONS" "-c 42 -M 77"
51 (parse-command-line '("--keep-failed" "--no-substitutes"
52 "--cores=10" "foo" "bar")
53 %standard-build-options
54 (list '()))))
55
56 (test-equal "parse-command-line and --no options"
57 '((argument . "foo")
58 (substitutes? . #f)) ;takes precedence
59
60 (with-environment-variable "GUIX_BUILD_OPTIONS" "--no-substitutes"
61 (parse-command-line '("foo")
62 %standard-build-options
63 (list '((substitutes? . #t))))))
64
65 (test-end "scripts")
66
67 \f
68 (exit (= (test-runner-fail-count (test-runner-current)) 0))
69
70 ;;; Local Variables:
71 ;;; eval: (put 'with-environment-variable 'scheme-indent-function 2)
72 ;;; End: