summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2021-07-18 16:05:21 +0200
committerLudovic Courtès <ludo@gnu.org>2021-07-18 19:50:01 +0200
commit0e47fcced442d8e7c1b05184fdc1c14f10ed04ec (patch)
tree4ae844bc0ec3c670f8697bdc24362c122fa718ad /tests
parente4b70bc55a538569465bcedee19d1f2607308e65 (diff)
parent8b1bde7bb3936a64244824500ffe60f123704437 (diff)
Merge branch 'master' into core-updates
Diffstat (limited to 'tests')
-rw-r--r--tests/gexp.scm31
-rw-r--r--tests/go.scm132
-rw-r--r--tests/hackage.scm42
-rw-r--r--tests/lint.scm172
-rw-r--r--tests/pack.scm94
-rw-r--r--tests/services/configuration.scm12
6 files changed, 477 insertions, 6 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 64c3107ef77..709a198e1ea 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -1,5 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
3;;; 4;;;
4;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
5;;; 6;;;
@@ -89,6 +90,36 @@
89 90
90(test-begin "gexp") 91(test-begin "gexp")
91 92
93(test-equal "no references"
94 '(display "hello gexp->approximate-sexp!")
95 (gexp->approximate-sexp #~(display "hello gexp->approximate-sexp!")))
96
97(test-equal "unquoted gexp"
98 '(display "hello")
99 (let ((inside #~"hello"))
100 (gexp->approximate-sexp #~(display #$inside))))
101
102(test-equal "unquoted gexp (native)"
103 '(display "hello")
104 (let ((inside #~"hello"))
105 (gexp->approximate-sexp #~(display #+inside))))
106
107(test-equal "spliced gexp"
108 '(display '(fresh vegetables))
109 (let ((inside #~(fresh vegetables)))
110 (gexp->approximate-sexp #~(display '(#$@inside)))))
111
112(test-equal "unspliced gexp, approximated"
113 ;; (*approximate*) is really an implementation detail
114 '(display '(*approximate*))
115 (let ((inside (file-append coreutils "/bin/hello")))
116 (gexp->approximate-sexp #~(display '(#$@inside)))))
117
118(test-equal "unquoted gexp, approximated"
119 '(display '(*approximate*))
120 (let ((inside (file-append coreutils "/bin/hello")))
121 (gexp->approximate-sexp #~(display '#$inside))))
122
92(test-equal "no refs" 123(test-equal "no refs"
93 '(display "hello!") 124 '(display "hello!")
94 (let ((exp (gexp (display "hello!")))) 125 (let ((exp (gexp (display "hello!"))))
diff --git a/tests/go.scm b/tests/go.scm
index b088ab50d2b..6749f4585ff 100644
--- a/tests/go.scm
+++ b/tests/go.scm
@@ -1,5 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com> 2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
3;;; 4;;;
4;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
5;;; 6;;;
@@ -31,6 +32,9 @@
31 #:use-module (srfi srfi-64) 32 #:use-module (srfi srfi-64)
32 #:use-module (web response)) 33 #:use-module (web response))
33 34
35(define go.mod-requirements
36 (@@ (guix import go) go.mod-requirements))
37
34(define parse-go.mod 38(define parse-go.mod
35 (@@ (guix import go) parse-go.mod)) 39 (@@ (guix import go) parse-go.mod))
36 40
@@ -57,7 +61,6 @@ require (
57exclude D v1.2.3 61exclude D v1.2.3
58") 62")
59 63
60
61(define fixture-go-mod-complete 64(define fixture-go-mod-complete
62 "module M 65 "module M
63 66
@@ -96,11 +99,40 @@ replace (
96 99
97") 100")
98 101
102(define fixture-go-mod-unparseable
103 "module my/thing
104go 1.12 // avoid feature X
105require other/thing v1.0.2
106// Security issue: CVE-XXXXX
107exclude old/thing v1.2.3
108new-directive another/thing yet-another/thing
109replace (
110 bad/thing v1.4.5 => good/thing v1.4.5
111 // Unparseable
112 bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0
113)
114")
99 115
116(define fixture-go-mod-retract
117 "retract v0.9.1
100 118
101(define fixture-latest-for-go-check 119retract (
102 "{\"Version\":\"v0.0.0-20201130134442-10cb98267c6c\",\"Time\":\"2020-11-30T13:44:42Z\"}") 120 v1.9.2
121 [v1.0.0, v1.7.9]
122)
123")
103 124
125(define fixture-go-mod-strings
126 "require `example.com/\"some-repo\"` v1.9.3
127require (
128 `example.com/\"another.repo\"` v1.0.0
129 \"example.com/special!repo\" v9.3.1
130)
131replace \"example.com/\\\"some-repo\\\"\" => `launchpad.net/some-repo` v1.9.3
132replace (
133 \"example.com/\\\"another.repo\\\"\" => launchpad.net/another-repo v1.0.0
134)
135")
104 136
105(define fixtures-go-check-test 137(define fixtures-go-check-test
106 (let ((version 138 (let ((version
@@ -185,7 +217,7 @@ require github.com/kr/pretty v0.2.1
185 (string<? (car p1) (car p2))) 217 (string<? (car p1) (car p2)))
186 (test-equal name 218 (test-equal name
187 (sort expected inf?) 219 (sort expected inf?)
188 (sort ((@@ (guix import go) parse-go.mod) input) inf?))) 220 (sort (go.mod-requirements (parse-go.mod input)) inf?)))
189 221
190(testing-parse-mod "parse-go.mod-simple" 222(testing-parse-mod "parse-go.mod-simple"
191 '(("good/thing" "v1.4.5") 223 '(("good/thing" "v1.4.5")
@@ -221,6 +253,98 @@ require github.com/kr/pretty v0.2.1
221 ("github.com/go-check/check" "v0.0.0-20140225173054-eb6ee6f84d0a")) 253 ("github.com/go-check/check" "v0.0.0-20140225173054-eb6ee6f84d0a"))
222 fixture-go-mod-complete) 254 fixture-go-mod-complete)
223 255
256(test-equal "parse-go.mod: simple"
257 `((module (module-path "my/thing"))
258 (go (version "1.12"))
259 (require (module-path "other/thing") (version "v1.0.2"))
260 (require (module-path "new/thing/v2") (version "v2.3.4"))
261 (exclude (module-path "old/thing") (version "v1.2.3"))
262 (replace (original (module-path "bad/thing") (version "v1.4.5"))
263 (with (module-path "good/thing") (version "v1.4.5"))))
264 (parse-go.mod fixture-go-mod-simple))
265
266(test-equal "parse-go.mod: comments and unparseable lines"
267 `((module (module-path "my/thing"))
268 (go (version "1.12") (comment "avoid feature X"))
269 (require (module-path "other/thing") (version "v1.0.2"))
270 (comment "Security issue: CVE-XXXXX")
271 (exclude (module-path "old/thing") (version "v1.2.3"))
272 (unknown "new-directive another/thing yet-another/thing")
273 (replace (original (module-path "bad/thing") (version "v1.4.5"))
274 (with (module-path "good/thing") (version "v1.4.5")))
275 (comment "Unparseable")
276 (unknown "bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0"))
277 (parse-go.mod fixture-go-mod-unparseable))
278
279(test-equal "parse-go.mod: retract"
280 `((retract (version "v0.9.1"))
281 (retract (version "v1.9.2"))
282 (retract (range (version "v1.0.0") (version "v1.7.9"))))
283 (parse-go.mod fixture-go-mod-retract))
284
285(test-equal "parse-go.mod: raw strings and quoted strings"
286 `((require (module-path "example.com/\"some-repo\"") (version "v1.9.3"))
287 (require (module-path "example.com/\"another.repo\"") (version "v1.0.0"))
288 (require (module-path "example.com/special!repo") (version "v9.3.1"))
289 (replace (original (module-path "example.com/\"some-repo\""))
290 (with (module-path "launchpad.net/some-repo") (version "v1.9.3")))
291 (replace (original (module-path "example.com/\"another.repo\""))
292 (with (module-path "launchpad.net/another-repo") (version "v1.0.0"))))
293 (parse-go.mod fixture-go-mod-strings))
294
295(test-equal "parse-go.mod: complete"
296 `((module (module-path "M"))
297 (go (version "1.13"))
298 (replace (original (module-path "github.com/myname/myproject/myapi"))
299 (with (file-path "./api")))
300 (replace (original (module-path "github.com/mymname/myproject/thissdk"))
301 (with (file-path "../sdk")))
302 (replace (original (module-path "launchpad.net/gocheck"))
303 (with (module-path "github.com/go-check/check")
304 (version "v0.0.0-20140225173054-eb6ee6f84d0a")))
305 (require (module-path "github.com/user/project")
306 (version "v1.1.11"))
307 (require (module-path "github.com/user/project/sub/directory")
308 (version "v1.1.12"))
309 (require (module-path "bitbucket.org/user/project")
310 (version "v1.11.20"))
311 (require (module-path "bitbucket.org/user/project/sub/directory")
312 (version "v1.11.21"))
313 (require (module-path "launchpad.net/project")
314 (version "v1.1.13"))
315 (require (module-path "launchpad.net/project/series")
316 (version "v1.1.14"))
317 (require (module-path "launchpad.net/project/series/sub/directory")
318 (version "v1.1.15"))
319 (require (module-path "launchpad.net/~user/project/branch")
320 (version "v1.1.16"))
321 (require (module-path "launchpad.net/~user/project/branch/sub/directory")
322 (version "v1.1.17"))
323 (require (module-path "hub.jazz.net/git/user/project")
324 (version "v1.1.18"))
325 (require (module-path "hub.jazz.net/git/user/project/sub/directory")
326 (version "v1.1.19"))
327 (require (module-path "k8s.io/kubernetes/subproject")
328 (version "v1.1.101"))
329 (require (module-path "one.example.com/abitrary/repo")
330 (version "v1.1.111"))
331 (require (module-path "two.example.com/abitrary/repo")
332 (version "v0.0.2"))
333 (require (module-path "quoted.example.com/abitrary/repo")
334 (version "v0.0.2"))
335 (replace (original (module-path "two.example.com/abitrary/repo"))
336 (with (module-path "github.com/corp/arbitrary-repo")
337 (version "v0.0.2")))
338 (replace (original (module-path "golang.org/x/sys"))
339 (with (module-path "golang.org/x/sys")
340 (version "v0.0.0-20190813064441-fde4db37ae7a"))
341 (comment "pinned to release-branch.go1.13"))
342 (replace (original (module-path "golang.org/x/tools"))
343 (with (module-path "golang.org/x/tools")
344 (version "v0.0.0-20190821162956-65e3620a7ae7"))
345 (comment "pinned to release-branch.go1.13")))
346 (parse-go.mod fixture-go-mod-complete))
347
224;;; End-to-end tests for (guix import go) 348;;; End-to-end tests for (guix import go)
225(define (mock-http-fetch testcase) 349(define (mock-http-fetch testcase)
226 (lambda (url . rest) 350 (lambda (url . rest)
diff --git a/tests/hackage.scm b/tests/hackage.scm
index 66a13d98817..53972fc643a 100644
--- a/tests/hackage.scm
+++ b/tests/hackage.scm
@@ -388,4 +388,46 @@ executable cabal
388 #t) 388 #t)
389 (x (pk 'fail x #f)))) 389 (x (pk 'fail x #f))))
390 390
391(define test-cabal-import
392 "name: foo
393version: 1.0.0
394homepage: http://test.org
395synopsis: synopsis
396description: description
397license: BSD3
398common commons
399 build-depends:
400 HTTP >= 4000.2.5 && < 4000.3,
401 mtl >= 2.0 && < 3
402
403executable cabal
404 import: commons
405")
406
407(define-package-matcher match-ghc-foo-import
408 ('package
409 ('name "ghc-foo")
410 ('version "1.0.0")
411 ('source
412 ('origin
413 ('method 'url-fetch)
414 ('uri ('string-append
415 "https://hackage.haskell.org/package/foo/foo-"
416 'version
417 ".tar.gz"))
418 ('sha256
419 ('base32
420 (? string? hash)))))
421 ('build-system 'haskell-build-system)
422 ('inputs
423 ('quasiquote
424 (("ghc-http" ('unquote 'ghc-http)))))
425 ('home-page "http://test.org")
426 ('synopsis (? string?))
427 ('description (? string?))
428 ('license 'license:bsd-3)))
429
430(test-assert "hackage->guix-package test cabal import"
431 (eval-test-with-cabal test-cabal-import match-ghc-foo-import))
432
391(test-end "hackage") 433(test-end "hackage")
diff --git a/tests/lint.scm b/tests/lint.scm
index 0a8f1c6f54f..dfb45ef60db 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -8,7 +8,9 @@
8;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il> 8;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
9;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net> 9;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
10;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com> 10;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
11;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
11;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> 12;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
13;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
12;;; 14;;;
13;;; This file is part of GNU Guix. 15;;; This file is part of GNU Guix.
14;;; 16;;;
@@ -38,7 +40,7 @@
38 #:use-module (guix lint) 40 #:use-module (guix lint)
39 #:use-module (guix ui) 41 #:use-module (guix ui)
40 #:use-module (guix swh) 42 #:use-module (guix swh)
41 #:use-module ((guix gexp) #:select (local-file)) 43 #:use-module ((guix gexp) #:select (gexp local-file gexp?))
42 #:use-module ((guix utils) #:select (call-with-temporary-directory)) 44 #:use-module ((guix utils) #:select (call-with-temporary-directory))
43 #:use-module ((guix import hackage) #:select (%hackage-url)) 45 #:use-module ((guix import hackage) #:select (%hackage-url))
44 #:use-module ((guix import stackage) #:select (%stackage-url)) 46 #:use-module ((guix import stackage) #:select (%stackage-url))
@@ -46,6 +48,7 @@
46 #:use-module (gnu packages glib) 48 #:use-module (gnu packages glib)
47 #:use-module (gnu packages pkg-config) 49 #:use-module (gnu packages pkg-config)
48 #:use-module (gnu packages python-xyz) 50 #:use-module (gnu packages python-xyz)
51 #:use-module ((gnu packages bash) #:select (bash bash-minimal))
49 #:use-module (web uri) 52 #:use-module (web uri)
50 #:use-module (web server) 53 #:use-module (web server)
51 #:use-module (web server http) 54 #:use-module (web server http)
@@ -160,6 +163,13 @@
160 (description "This is a 'quoted' thing.")))) 163 (description "This is a 'quoted' thing."))))
161 (check-description-style pkg)))) 164 (check-description-style pkg))))
162 165
166(test-equal "description: leading whitespace"
167 "description contains leading whitespace"
168 (single-lint-warning-message
169 (let ((pkg (dummy-package "x"
170 (description " Whitespace."))))
171 (check-description-style pkg))))
172
163(test-equal "description: trailing whitespace" 173(test-equal "description: trailing whitespace"
164 "description contains trailing whitespace" 174 "description contains trailing whitespace"
165 (single-lint-warning-message 175 (single-lint-warning-message
@@ -370,6 +380,92 @@
370 ("pkgkonfig" ,pkg-config)))))) 380 ("pkgkonfig" ,pkg-config))))))
371 (check-input-labels pkg)))) 381 (check-input-labels pkg))))
372 382
383(test-equal "explicit #:sh argument to 'wrap-program' is acceptable"
384 '()
385 (let* ((phases
386 ;; Loosely based on the "catfish" package
387 `(modify-phases %standard-phases
388 (add-after 'install 'wrap
389 (lambda* (#:key inputs outputs #:allow-other-keys)
390 (define catfish (string-append (assoc-ref outputs "out")
391 "/bin/catfish"))
392 (define hsab (string-append (assoc-ref inputs "hsab")
393 "/bin/hsab"))
394 (wrap-program catfish #:sh hsab
395 `("PYTHONPATH" = (,"blabla")))))))
396 (pkg (dummy-package "x" (arguments `(#:phases ,phases)))))
397 (check-wrapper-inputs pkg)))
398
399(test-equal
400 "'check-wrapper-inputs' detects 'wrap-program' without \"bash\" in inputs"
401 "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used"
402 (let* ((phases
403 `(modify-phases %standard-phases
404 (add-after 'install 'wrap
405 (lambda _
406 (wrap-program the-binary bla-bla)))))
407 (pkg (dummy-package "x" (arguments `(#:phases ,phases)))))
408 (single-lint-warning-message (check-wrapper-inputs pkg))))
409
410(test-equal
411 "'check-wrapper-inputs' detects 'wrap-qt-program' without \"bash\" in inputs"
412 "\"bash-minimal\" should be in 'inputs' when 'wrap-qt-program' is used"
413 (let* ((phases
414 `(modify-phases %standard-phases
415 (add-after 'install 'qtwrap
416 (lambda _
417 (wrap-qt-program the-binary bla-bla)))))
418 (pkg (dummy-package "x" (arguments `(#:phases ,phases)))))
419 (single-lint-warning-message (check-wrapper-inputs pkg))))
420
421(test-equal "\"bash\" in 'inputs' satisfies 'check-wrapper-inputs'"
422 '()
423 (let* ((phases
424 `(modify-phases %standard-phases
425 (add-after 'install 'wrap
426 (lambda _
427 (wrap-program the-binary bla-bla)))))
428 (pkg (dummy-package "x" (arguments `(#:phases ,phases))
429 (inputs `(("bash" ,bash))))))
430 (check-wrapper-inputs pkg)))
431
432(test-equal "\"bash-minimal\" in 'inputs' satisfies 'check-wrapper-inputs'"
433 '()
434 (let* ((phases
435 `(modify-phases %standard-phases
436 (add-after 'install 'wrap
437 (lambda _
438 (wrap-program THE-BINARY bla-bla)))))
439 (pkg (dummy-package "x" (arguments `(#:phases ,phases))
440 (inputs `(("bash-minimal" ,bash-minimal))))))
441 (check-wrapper-inputs pkg)))
442
443(test-equal "'cut' doesn't hide bad usages of 'wrap-program'"
444 "\"bash-minimal\" should be in 'inputs' when 'wrap-program' is used"
445 (let* ((phases
446 ;; Taken from the "straw-viewer" package
447 `(modify-phases %standard-phases
448 (add-after 'install 'wrap-program
449 (lambda* (#:key outputs #:allow-other-keys)
450 (let* ((out (assoc-ref outputs "out"))
451 (bin-dir (string-append out "/bin/"))
452 (site-dir (string-append out "/lib/perl5/site_perl/"))
453 (lib-path (getenv "PERL5LIB")))
454 (for-each (cut wrap-program <>
455 `("PERL5LIB" ":" prefix
456 (,lib-path ,site-dir)))
457 (find-files bin-dir)))))))
458 (pkg (dummy-package "x" (arguments `(#:phases ,phases)))))
459 (single-lint-warning-message (check-wrapper-inputs pkg))))
460
461(test-equal "bogus phase specifications don't crash the linter"
462 "invalid phase clause"
463 (let* ((phases
464 `(modify-phases %standard-phases
465 (add-invalid)))
466 (pkg (dummy-package "x" (arguments `(#:phases ,phases)))))
467 (single-lint-warning-message (check-wrapper-inputs pkg))))
468
373(test-equal "file patches: different file name -> warning" 469(test-equal "file patches: different file name -> warning"
374 "file names of patches should start with the package name" 470 "file names of patches should start with the package name"
375 (single-lint-warning-message 471 (single-lint-warning-message
@@ -758,6 +854,80 @@
758 (sha256 %null-sha256)))))) 854 (sha256 %null-sha256))))))
759 (check-source-unstable-tarball pkg))) 855 (check-source-unstable-tarball pkg)))
760 856
857(define (package-with-phase-changes changes)
858 (dummy-package "x"
859 (arguments `(#:phases
860 ,(if (gexp? changes)
861 #~(modify-phases %standard-phases
862 #$@changes)
863 `(modify-phases %standard-phases
864 ,@changes))))))
865
866(test-equal "optional-tests: no check phase"
867 '()
868 (let ((pkg (package-with-phase-changes '())))
869 (check-optional-tests pkg)))
870
871(test-equal "optional-tests: check phase respects #:tests?"
872 '()
873 (let ((pkg (package-with-phase-changes
874 '((replace 'check
875 (lambda* (#:key tests? #:allow-other-keys?)
876 (when tests?
877 (invoke "./the-test-suite"))))))))
878 (check-optional-tests pkg)))
879
880(test-equal "optional-tests: check phase ignores #:tests?"
881 "the 'check' phase should respect #:tests?"
882 (let ((pkg (package-with-phase-changes
883 '((replace 'check
884 (lambda _
885 (invoke "./the-test-suite")))))))
886 (single-lint-warning-message
887 (check-optional-tests pkg))))
888
889(test-equal "optional-tests: do not crash when #:phases is invalid"
890 "incorrect call to ‘modify-phases’"
891 (let ((pkg (package-with-phase-changes 'this-is-not-a-list)))
892 (single-lint-warning-message
893 (check-optional-tests pkg))))
894
895(test-equal "optional-tests: allow G-exps (no warning)"
896 '()
897 (let ((pkg (package-with-phase-changes #~())))
898 (check-optional-tests pkg)))
899
900(test-equal "optional-tests: allow G-exps (warning)"
901 "the 'check' phase should respect #:tests?"
902 (let ((pkg (package-with-phase-changes
903 #~((replace 'check
904 (lambda _
905 (invoke "/the-test-suite")))))))
906 (single-lint-warning-message
907 (check-optional-tests pkg))))
908
909(test-equal "optional-tests: complicated 'check' phase"
910 "the 'check' phase should respect #:tests?"
911 (let ((pkg (package-with-phase-changes
912 '((replace 'check
913 (lambda* (#:key inputs tests? #:allow-other-keys)
914 (let ((something (stuff from inputs or native-inputs)))
915 (delete-file "dateutil/test/test_utils.py")
916 (invoke "pytest" "-vv"))))))))
917 (single-lint-warning-message
918 (check-optional-tests pkg))))
919
920(test-equal "optional-tests: 'check' phase is not first phase"
921 "the 'check' phase should respect #:tests?"
922 (let ((pkg (package-with-phase-changes
923 '((add-after 'unpack
924 (lambda _
925 (chdir "libtestcase-0.0.0")))
926 (replace 'check
927 (lambda _ (invoke "./test-suite")))))))
928 (single-lint-warning-message
929 (check-optional-tests pkg))))
930
761(test-equal "source: 200" 931(test-equal "source: 200"
762 '() 932 '()
763 (with-http-server `((200 ,%long-string)) 933 (with-http-server `((200 ,%long-string))
diff --git a/tests/pack.scm b/tests/pack.scm
index 8564939ee13..98bfedf21c9 100644
--- a/tests/pack.scm
+++ b/tests/pack.scm
@@ -1,6 +1,7 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net> 3;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
4;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
4;;; 5;;;
5;;; This file is part of GNU Guix. 6;;; This file is part of GNU Guix.
6;;; 7;;;
@@ -32,6 +33,7 @@
32 #:use-module ((gnu packages base) #:select (glibc-utf8-locales)) 33 #:use-module ((gnu packages base) #:select (glibc-utf8-locales))
33 #:use-module (gnu packages bootstrap) 34 #:use-module (gnu packages bootstrap)
34 #:use-module ((gnu packages compression) #:select (squashfs-tools)) 35 #:use-module ((gnu packages compression) #:select (squashfs-tools))
36 #:use-module ((gnu packages debian) #:select (dpkg))
35 #:use-module ((gnu packages guile) #:select (guile-sqlite3)) 37 #:use-module ((gnu packages guile) #:select (guile-sqlite3))
36 #:use-module ((gnu packages gnupg) #:select (guile-gcrypt)) 38 #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
37 #:use-module (srfi srfi-64)) 39 #:use-module (srfi srfi-64))
@@ -51,11 +53,13 @@
51(define %gzip-compressor 53(define %gzip-compressor
52 ;; Compressor that uses the bootstrap 'gzip'. 54 ;; Compressor that uses the bootstrap 'gzip'.
53 ((@ (guix scripts pack) compressor) "gzip" 55 ((@ (guix scripts pack) compressor) "gzip"
54 "gz" 56 ".gz"
55 #~(list #+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n"))) 57 #~(list #+(file-append %bootstrap-coreutils&co "/bin/gzip") "-6n")))
56 58
57(define %tar-bootstrap %bootstrap-coreutils&co) 59(define %tar-bootstrap %bootstrap-coreutils&co)
58 60
61(define %ar-bootstrap %bootstrap-binutils)
62
59 63
60(test-begin "pack") 64(test-begin "pack")
61 65
@@ -270,6 +274,94 @@
270 1) 274 1)
271 (pk 'guilelink (readlink "bin")))) 275 (pk 'guilelink (readlink "bin"))))
272 (mkdir #$output)))))))) 276 (mkdir #$output))))))))
277 (built-derivations (list check))))
278
279 (unless store (test-skip 1))
280 (test-assertm "deb archive with symlinks and control files" store
281 (mlet* %store-monad
282 ((guile (set-guile-for-build (default-guile)))
283 (profile (profile-derivation (packages->manifest
284 (list %bootstrap-guile))
285 #:hooks '()
286 #:locales? #f))
287 (deb (debian-archive
288 "deb-pack" profile
289 #:compressor %gzip-compressor
290 #:symlinks '(("/opt/gnu/bin" -> "bin"))
291 #:archiver %tar-bootstrap
292 #:extra-options
293 (list #:triggers-file
294 (plain-file "triggers"
295 "activate-noawait /usr/share/icons/hicolor\n")
296 #:postinst-file
297 (plain-file "postinst"
298 "echo running configure script\n"))))
299 (check
300 (gexp->derivation "check-deb-pack"
301 (with-imported-modules '((guix build utils))
302 #~(begin
303 (use-modules (guix build utils)
304 (ice-9 match)
305 (ice-9 popen)
306 (ice-9 rdelim)
307 (ice-9 textual-ports)
308 (rnrs base))
309
310 (setenv "PATH" (string-join
311 (list (string-append #+%tar-bootstrap "/bin")
312 (string-append #+dpkg "/bin")
313 (string-append #+%ar-bootstrap "/bin"))
314 ":"))
315
316 ;; Validate the output of 'dpkg --info'.
317 (let* ((port (open-pipe* OPEN_READ "dpkg" "--info" #$deb))
318 (info (get-string-all port))
319 (exit-val (status:exit-val (close-pipe port))))
320 (assert (zero? exit-val))
321
322 (assert (string-contains
323 info
324 (string-append "Package: "
325 #+(package-name %bootstrap-guile))))
326
327 (assert (string-contains
328 info
329 (string-append "Version: "
330 #+(package-version %bootstrap-guile)))))
331
332 ;; Sanity check .deb contents.
333 (invoke "ar" "-xv" #$deb)
334 (assert (file-exists? "debian-binary"))
335 (assert (file-exists? "data.tar.gz"))
336 (assert (file-exists? "control.tar.gz"))
337
338 ;; Verify there are no hard links in data.tar.gz, as hard
339 ;; links would cause dpkg to fail unpacking the archive.
340 (define hard-links
341 (let ((port (open-pipe* OPEN_READ "tar" "-tvf" "data.tar.gz")))
342 (let loop ((hard-links '()))
343 (match (read-line port)
344 ((? eof-object?)
345 (assert (zero? (status:exit-val (close-pipe port))))
346 hard-links)
347 (line
348 (if (string-prefix? "u" line)
349 (loop (cons line hard-links))
350 (loop hard-links)))))))
351
352 (unless (null? hard-links)
353 (error "hard links found in data.tar.gz" hard-links))
354
355 ;; Verify the presence of the control files.
356 (invoke "tar" "-xf" "control.tar.gz")
357 (assert (file-exists? "control"))
358 (assert (and (file-exists? "postinst")
359 (= #o111 ;script is executable
360 (logand #o111 (stat:perms
361 (stat "postinst"))))))
362 (assert (file-exists? "triggers"))
363
364 (mkdir #$output))))))
273 (built-derivations (list check))))) 365 (built-derivations (list check)))))
274 366
275(test-end) 367(test-end)
diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm
index 85badd2da65..86a36a388d3 100644
--- a/tests/services/configuration.scm
+++ b/tests/services/configuration.scm
@@ -1,5 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> 2;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
3;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
3;;; 4;;;
4;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
5;;; 6;;;
@@ -82,6 +83,17 @@
82 (let ((config (serializable-configuration))) 83 (let ((config (serializable-configuration)))
83 (serialize-configuration config serializable-configuration-fields))))) 84 (serialize-configuration config serializable-configuration-fields)))))
84 85
86(define (custom-prefix-serialize-integer field-name name) name)
87
88(define-configuration configuration-with-prefix
89 (port (integer 10) "The port number.")
90 (prefix custom-prefix-))
91
92(test-assert "serialize-configuration with prefix"
93 (gexp?
94 (let ((config (configuration-with-prefix)))
95 (serialize-configuration config configuration-with-prefix-fields))))
96
85 97
86;;; 98;;;
87;;; define-maybe macro. 99;;; define-maybe macro.