summaryrefslogtreecommitdiff
path: root/tests/import
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2025-09-17 00:19:58 +0200
committerLudovic Courtès <ludo@gnu.org>2025-10-01 11:00:36 +0200
commitd950c929e907787c622afaa830abcc9d4990bd5a (patch)
tree373fd62a83ed7c9a5f9089b93a6368799062983d /tests/import
parent5cf0daa657a3f47879927cdc52c8597668e6129b (diff)
import: cpan: Move tests to tests/import/cpan.scm.
* tests/cpan.scm: Move to tests/import/cpan.scm. * gnu/packages/admin.scm (ansible): Update comment. * Makefile.am: Refresh it. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/import')
-rw-r--r--tests/import/cpan.scm132
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/import/cpan.scm b/tests/import/cpan.scm
new file mode 100644
index 00000000000..42e8c4e42c1
--- /dev/null
+++ b/tests/import/cpan.scm
@@ -0,0 +1,132 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org>
3;;; Copyright © 2016 Alex Sassmannshausen <alex@pompo.co>
4;;; Copyright © 2020, 2023 Ludovic Courtès <ludo@gnu.org>
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (test-cpan)
22 #:use-module (guix import cpan)
23 #:use-module (guix base32)
24 #:use-module (guix upstream)
25 #:use-module ((guix download) #:select (url-fetch))
26 #:use-module (gcrypt hash)
27 #:use-module (guix tests)
28 #:use-module (guix tests http)
29 #:use-module ((guix store) #:select (%graft?))
30 #:use-module (srfi srfi-64)
31 #:use-module (web client)
32 #:use-module (ice-9 match))
33
34;; Globally disable grafts because they can trigger early builds.
35(%graft? #f)
36
37(define test-json
38 "{
39 \"metadata\" : {
40 \"name\" : \"Foo-Bar\",
41 \"version\" : \"0.1\"
42 }
43 \"name\" : \"Foo-Bar-0.1\",
44 \"distribution\" : \"Foo-Bar\",
45 \"license\" : [
46 \"perl_5\"
47 ],
48 \"dependency\": [
49 { \"relationship\": \"requires\",
50 \"phase\": \"runtime\",
51 \"version\": \"1.05\",
52 \"module\": \"Test::Script\"
53 }
54 ],
55 \"abstract\" : \"Fizzle Fuzz\",
56 \"download_url\" : \"http://example.com/Foo-Bar-0.1.tar.gz\",
57 \"author\" : \"Guix\",
58 \"version\" : \"0.1\"
59}")
60
61(define test-source
62 "foobar")
63
64;; Avoid collisions with other tests.
65(%http-server-port 10400)
66
67(test-begin "cpan")
68
69(test-assert "cpan->guix-package"
70 (with-http-server `((200 ,test-json)
71 (200 ,test-source)
72 (200 "{ \"distribution\" : \"Test-Script\" }"))
73 (parameterize ((%metacpan-base-url (%local-url))
74 (current-http-proxy (%local-url)))
75 (match (cpan->guix-package "Foo::Bar")
76 (`(package
77 (name "perl-foo-bar")
78 (version "0.1")
79 (source (origin
80 (method url-fetch)
81 (uri (string-append "http://example.com/Foo-Bar-"
82 version ".tar.gz"))
83 (sha256
84 (base32 ,(? string? hash)))))
85 (build-system perl-build-system)
86 (propagated-inputs (list perl-test-script))
87 (home-page "https://metacpan.org/release/Foo-Bar")
88 (synopsis "Fizzle Fuzz")
89 (description fill-in-yourself!)
90 (license perl-license))
91 (string=? (bytevector->nix-base32-string
92 (call-with-input-string test-source port-sha256))
93 hash))
94 (x
95 (pk 'fail x #f))))))
96
97(test-equal "package-latest-release"
98 (list '("http://example.com/Foo-Bar-0.1.tar.gz")
99 #f
100 (list (upstream-input
101 (name "Test-Script")
102 (downstream-name "perl-test-script")
103 (type 'propagated))))
104 (with-http-server `((200 ,test-json)
105 (200 "{ \"distribution\" : \"Test-Script\" }")
106 (200 ,test-source))
107 (parameterize ((%metacpan-base-url (%local-url))
108 (current-http-proxy (%local-url)))
109 (define source
110 (package-latest-release
111 (dummy-package "perl-test-script"
112 (version "0.0.0")
113 (source (dummy-origin
114 (method url-fetch)
115 (uri "mirror://cpan/Foo-Bar-0.0.0.tgz"))))
116 (list %cpan-updater)))
117
118 (list (upstream-source-urls source)
119 (upstream-source-signature-urls source)
120 (upstream-source-inputs source)))))
121
122(test-equal "metacpan-url->mirror-url, http"
123 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
124 (metacpan-url->mirror-url
125 "http://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
126
127(test-equal "metacpan-url->mirror-url, https"
128 "mirror://cpan/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"
129 (metacpan-url->mirror-url
130 "https://cpan.metacpan.org/authors/id/T/TE/TEST/Foo-Bar-0.1.tar.gz"))
131
132(test-end "cpan")