Merge branch 'master' into core-updates-frozen
[jackhill/guix/guix.git] / tests / egg.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
3 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (test-eggs)
21 #:use-module (guix import egg)
22 #:use-module (guix gexp)
23 #:use-module (guix base32)
24 #:use-module (gcrypt hash)
25 #:use-module (guix tests)
26 #:use-module ((guix build syscalls) #:select (mkdtemp!))
27 #:use-module ((guix build utils) #:select (delete-file-recursively mkdir-p which))
28 #:use-module ((guix utils) #:select (call-with-temporary-output-file))
29 #:use-module (srfi srfi-1)
30 #:use-module (srfi srfi-64)
31 #:use-module (web uri)
32 #:use-module (ice-9 match))
33
34 (define test-egg-1
35 '((synopsis "Example egg")
36 (license "GPL-3/MIT")
37 (version "1.0.0")
38 (test-dependencies test srfi-1)
39 (foreign-dependencies libgit2)
40 (build-dependencies begin-syntax)
41 (dependencies datatype)
42 (author "John Doe")))
43
44 (define test-egg-2
45 '((synopsis "Example egg")
46 (license "GPL-3+")
47 (version "0.3")
48 (test-dependencies test)
49 (foreign-dependencies libgit2)
50 (build-dependencies begin-syntax)
51 (dependencies datatype)
52 (author "Alice Bobson")))
53
54 (define test-egg-1-file "/tmp/guix-egg-1")
55 (define test-egg-2-file "/tmp/guix-egg-2")
56
57 (test-begin "egg")
58
59 (test-equal "guix-package->egg-name"
60 "bar"
61 (guix-package->egg-name
62 (dummy-package "dummy"
63 (name "chicken-bar"))))
64
65 ;; Copied from tests/hackage.scm
66 (define-syntax-rule (define-package-matcher name pattern)
67 (define* (name obj)
68 (match obj
69 (pattern #t)
70 (x (pk 'fail x #f)))))
71
72 (define (eval-test-with-egg-file egg-name egg-test egg-file matcher)
73 (call-with-output-file egg-file
74 (lambda (port)
75 (write egg-test port)))
76 (matcher (egg->guix-package egg-name
77 #:file egg-file
78 #:source (plain-file
79 (string-append egg-name "-egg")
80 "content"))))
81
82 (define-package-matcher match-chicken-foo
83 ('package
84 ('name "chicken-foo")
85 ('version "1.0.0")
86 ('source (? file-like? source))
87 ('build-system 'chicken-build-system)
88 ('arguments ('quasiquote ('#:egg-name "foo")))
89 ('native-inputs
90 ('list 'chicken-test 'chicken-srfi-1 'chicken-begin-syntax))
91 ('inputs ('list 'libgit2))
92 ('propagated-inputs ('list 'chicken-datatype))
93 ('home-page "https://wiki.call-cc.org/egg/foo")
94 ('synopsis "Example egg")
95 ('description #f)
96 ('license '(list license:gpl3 license:expat))))
97
98 (define-package-matcher match-chicken-bar
99 ('package
100 ('name "chicken-bar")
101 ('version "0.3")
102 ('source (? file-like? source))
103 ('build-system 'chicken-build-system)
104 ('arguments ('quasiquote ('#:egg-name "bar")))
105 ('native-inputs ('list 'chicken-test 'chicken-begin-syntax))
106 ('inputs ('list 'libgit2))
107 ('propagated-inputs ('list 'chicken-datatype))
108 ('home-page "https://wiki.call-cc.org/egg/bar")
109 ('synopsis "Example egg")
110 ('description #f)
111 ('license 'license:gpl3+)))
112
113 (test-assert "egg->guix-package local file, multiple licenses"
114 (eval-test-with-egg-file "foo" test-egg-1 test-egg-1-file match-chicken-foo))
115
116 (test-assert "egg->guix-package local file, single license"
117 (eval-test-with-egg-file "bar" test-egg-2 test-egg-2-file match-chicken-bar))
118
119 (test-end "egg")