diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2021-02-16 20:54:27 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2021-02-23 15:24:48 +0100 |
| commit | fc6d6aee6659acb293eb33f498fdac3b47a19a48 (patch) | |
| tree | 8097662f5364fc15f9c60ec1d81fb35d593ae3bb /tests | |
| parent | bde7929bd06196ed84f96d08676ee43da4685975 (diff) | |
gexp: 'gexp-inputs' returns a list of <gexp-input> records.
This slightly reduces memory allocation.
* guix/gexp.scm (lower-inputs): Expect a list of <gexp-input> rather
than a list of tuples.
(lower-reference-graphs)[tuple->gexp-input]: New procedure.
Use it.
(gexp-inputs): Return a list of <gexp-input> rather than a list of
tuples.
* tests/gexp.scm (gexp-input->tuple): New procedure.
("one input package")
("one input package, dotted list")
("one input origin")
("one local file")
("one local file, symlink")
("one plain file")
("two input packages, one derivation, one file")
("file-append")
("file-append, output")
("file-append, nested")
("let-system")
("let-system, nested")
("ungexp + ungexp-native")
("ungexp + ungexp-native, nested")
("ungexp + ungexp-native, nested, special mixture")
("input list")
("input list + ungexp-native")
("input list splicing")
("input list splicing + ungexp-native-splicing")
("gexp list splicing + ungexp-splicing"): Adjust accordingly.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gexp.scm | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm index 6e92f0e4b39..f742c5db763 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 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 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -63,6 +63,9 @@ | |||
| 63 | #:target target) | 63 | #:target target) |
| 64 | #:guile-for-build (%guile-for-build))) | 64 | #:guile-for-build (%guile-for-build))) |
| 65 | 65 | ||
| 66 | (define (gexp-input->tuple input) | ||
| 67 | (list (gexp-input-thing input) (gexp-input-output input))) | ||
| 68 | |||
| 66 | (define %extension-package | 69 | (define %extension-package |
| 67 | ;; Example of a package to use when testing 'with-extensions'. | 70 | ;; Example of a package to use when testing 'with-extensions'. |
| 68 | (dummy-package "extension" | 71 | (dummy-package "extension" |
| @@ -106,8 +109,8 @@ | |||
| 106 | (let ((exp (gexp (display (ungexp coreutils))))) | 109 | (let ((exp (gexp (display (ungexp coreutils))))) |
| 107 | (and (gexp? exp) | 110 | (and (gexp? exp) |
| 108 | (match (gexp-inputs exp) | 111 | (match (gexp-inputs exp) |
| 109 | (((p "out")) | 112 | ((input) |
| 110 | (eq? p coreutils))) | 113 | (eq? (gexp-input-thing input) coreutils))) |
| 111 | (equal? `(display ,(derivation->output-path | 114 | (equal? `(display ,(derivation->output-path |
| 112 | (package-derivation %store coreutils))) | 115 | (package-derivation %store coreutils))) |
| 113 | (gexp->sexp* exp))))) | 116 | (gexp->sexp* exp))))) |
| @@ -116,8 +119,8 @@ | |||
| 116 | (let ((exp (gexp (coreutils . (ungexp coreutils))))) | 119 | (let ((exp (gexp (coreutils . (ungexp coreutils))))) |
| 117 | (and (gexp? exp) | 120 | (and (gexp? exp) |
| 118 | (match (gexp-inputs exp) | 121 | (match (gexp-inputs exp) |
| 119 | (((p "out")) | 122 | ((input) |
| 120 | (eq? p coreutils))) | 123 | (eq? (gexp-input-thing input) coreutils))) |
| 121 | (equal? `(coreutils . ,(derivation->output-path | 124 | (equal? `(coreutils . ,(derivation->output-path |
| 122 | (package-derivation %store coreutils))) | 125 | (package-derivation %store coreutils))) |
| 123 | (gexp->sexp* exp))))) | 126 | (gexp->sexp* exp))))) |
| @@ -126,8 +129,9 @@ | |||
| 126 | (let ((exp (gexp (display (ungexp (package-source coreutils)))))) | 129 | (let ((exp (gexp (display (ungexp (package-source coreutils)))))) |
| 127 | (and (gexp? exp) | 130 | (and (gexp? exp) |
| 128 | (match (gexp-inputs exp) | 131 | (match (gexp-inputs exp) |
| 129 | (((o "out")) | 132 | ((input) |
| 130 | (eq? o (package-source coreutils)))) | 133 | (and (eq? (gexp-input-thing input) (package-source coreutils)) |
| 134 | (string=? (gexp-input-output input) "out")))) | ||
| 131 | (equal? `(display ,(derivation->output-path | 135 | (equal? `(display ,(derivation->output-path |
| 132 | (package-source-derivation | 136 | (package-source-derivation |
| 133 | %store (package-source coreutils)))) | 137 | %store (package-source coreutils)))) |
| @@ -141,8 +145,9 @@ | |||
| 141 | "sha256" file))) | 145 | "sha256" file))) |
| 142 | (and (gexp? exp) | 146 | (and (gexp? exp) |
| 143 | (match (gexp-inputs exp) | 147 | (match (gexp-inputs exp) |
| 144 | (((x "out")) | 148 | ((input) |
| 145 | (eq? x local))) | 149 | (and (eq? (gexp-input-thing input) local) |
| 150 | (string=? (gexp-input-output input) "out")))) | ||
| 146 | (equal? `(display ,intd) (gexp->sexp* exp))))) | 151 | (equal? `(display ,intd) (gexp->sexp* exp))))) |
| 147 | 152 | ||
| 148 | (test-assert "one local file, symlink" | 153 | (test-assert "one local file, symlink" |
| @@ -158,8 +163,9 @@ | |||
| 158 | "sha256" file))) | 163 | "sha256" file))) |
| 159 | (and (gexp? exp) | 164 | (and (gexp? exp) |
| 160 | (match (gexp-inputs exp) | 165 | (match (gexp-inputs exp) |
| 161 | (((x "out")) | 166 | ((input) |
| 162 | (eq? x local))) | 167 | (and (eq? (gexp-input-thing input) local) |
| 168 | (string=? (gexp-input-output input) "out")))) | ||
| 163 | (equal? `(display ,intd) (gexp->sexp* exp))))) | 169 | (equal? `(display ,intd) (gexp->sexp* exp))))) |
| 164 | (lambda () | 170 | (lambda () |
| 165 | (false-if-exception (delete-file link)))))) | 171 | (false-if-exception (delete-file link)))))) |
| @@ -201,8 +207,9 @@ | |||
| 201 | (expected (add-text-to-store %store "hi" "Hello, world!"))) | 207 | (expected (add-text-to-store %store "hi" "Hello, world!"))) |
| 202 | (and (gexp? exp) | 208 | (and (gexp? exp) |
| 203 | (match (gexp-inputs exp) | 209 | (match (gexp-inputs exp) |
| 204 | (((x "out")) | 210 | ((input) |
| 205 | (eq? x file))) | 211 | (and (eq? (gexp-input-thing input) file) |
| 212 | (string=? (gexp-input-output input) "out")))) | ||
| 206 | (equal? `(display ,expected) (gexp->sexp* exp))))) | 213 | (equal? `(display ,expected) (gexp->sexp* exp))))) |
| 207 | 214 | ||
| 208 | (test-assert "same input twice" | 215 | (test-assert "same input twice" |
| @@ -211,8 +218,9 @@ | |||
| 211 | (display (ungexp coreutils)))))) | 218 | (display (ungexp coreutils)))))) |
| 212 | (and (gexp? exp) | 219 | (and (gexp? exp) |
| 213 | (match (gexp-inputs exp) | 220 | (match (gexp-inputs exp) |
| 214 | (((p "out")) | 221 | ((input) |
| 215 | (eq? p coreutils))) | 222 | (and (eq? (gexp-input-thing input) coreutils) |
| 223 | (string=? (gexp-input-output input) "out")))) | ||
| 216 | (let ((e `(display ,(derivation->output-path | 224 | (let ((e `(display ,(derivation->output-path |
| 217 | (package-derivation %store coreutils))))) | 225 | (package-derivation %store coreutils))))) |
| 218 | (equal? `(begin ,e ,e) (gexp->sexp* exp)))))) | 226 | (equal? `(begin ,e ,e) (gexp->sexp* exp)))))) |
| @@ -228,9 +236,8 @@ | |||
| 228 | (display (ungexp drv)) | 236 | (display (ungexp drv)) |
| 229 | (display (ungexp txt)))))) | 237 | (display (ungexp txt)))))) |
| 230 | (define (match-input thing) | 238 | (define (match-input thing) |
| 231 | (match-lambda | 239 | (lambda (input) |
| 232 | ((drv-or-pkg _ ...) | 240 | (eq? (gexp-input-thing input) thing))) |
| 233 | (eq? thing drv-or-pkg)))) | ||
| 234 | 241 | ||
| 235 | (and (gexp? exp) | 242 | (and (gexp? exp) |
| 236 | (= 4 (length (gexp-inputs exp))) | 243 | (= 4 (length (gexp-inputs exp))) |
| @@ -255,8 +262,9 @@ | |||
| 255 | (string-append (derivation->output-path drv) | 262 | (string-append (derivation->output-path drv) |
| 256 | "/bin/guile")))) | 263 | "/bin/guile")))) |
| 257 | (match (gexp-inputs exp) | 264 | (match (gexp-inputs exp) |
| 258 | (((thing "out")) | 265 | ((input) |
| 259 | (eq? thing fa)))))) | 266 | (and (eq? (gexp-input-thing input) fa) |
| 267 | (string=? (gexp-input-output input) "out"))))))) | ||
| 260 | 268 | ||
| 261 | (test-assert "file-append, output" | 269 | (test-assert "file-append, output" |
| 262 | (let* ((drv (package-derivation %store glibc)) | 270 | (let* ((drv (package-derivation %store glibc)) |
| @@ -268,8 +276,9 @@ | |||
| 268 | (string-append (derivation->output-path drv "debug") | 276 | (string-append (derivation->output-path drv "debug") |
| 269 | "/lib/debug")))) | 277 | "/lib/debug")))) |
| 270 | (match (gexp-inputs exp) | 278 | (match (gexp-inputs exp) |
| 271 | (((thing "debug")) | 279 | ((input) |
| 272 | (eq? thing fa)))))) | 280 | (and (eq? (gexp-input-thing input) fa) |
| 281 | (string=? (gexp-input-output input) "debug"))))))) | ||
| 273 | 282 | ||
| 274 | (test-assert "file-append, nested" | 283 | (test-assert "file-append, nested" |
| 275 | (let* ((drv (package-derivation %store glibc)) | 284 | (let* ((drv (package-derivation %store glibc)) |
| @@ -283,8 +292,8 @@ | |||
| 283 | (string-append (derivation->output-path drv) | 292 | (string-append (derivation->output-path drv) |
| 284 | "/bin/getent")))) | 293 | "/bin/getent")))) |
| 285 | (match (gexp-inputs exp) | 294 | (match (gexp-inputs exp) |
| 286 | (((thing "out")) | 295 | ((input) |
| 287 | (eq? thing file)))))) | 296 | (eq? (gexp-input-thing input) file)))))) |
| 288 | 297 | ||
| 289 | (test-assert "file-append, raw store item" | 298 | (test-assert "file-append, raw store item" |
| 290 | (let* ((obj (plain-file "example.txt" "Hello!")) | 299 | (let* ((obj (plain-file "example.txt" "Hello!")) |
| @@ -346,8 +355,11 @@ | |||
| 346 | (low (run-with-store %store (lower-gexp exp)))) | 355 | (low (run-with-store %store (lower-gexp exp)))) |
| 347 | (list (lowered-gexp-sexp low) | 356 | (list (lowered-gexp-sexp low) |
| 348 | (match (gexp-inputs exp) | 357 | (match (gexp-inputs exp) |
| 349 | (((($ (@@ (guix gexp) <system-binding>)) "out")) | 358 | ((input) |
| 350 | '(system-binding)) | 359 | (and (eq? (struct-vtable (gexp-input-thing input)) |
| 360 | (@@ (guix gexp) <system-binding>)) | ||
| 361 | (string=? (gexp-input-output input) "out") | ||
| 362 | '(system-binding))) | ||
| 351 | (x x)) | 363 | (x x)) |
| 352 | (gexp-native-inputs exp) | 364 | (gexp-native-inputs exp) |
| 353 | 'low | 365 | 'low |
| @@ -388,8 +400,11 @@ | |||
| 388 | (x x)) | 400 | (x x)) |
| 389 | (gexp-inputs exp) | 401 | (gexp-inputs exp) |
| 390 | (match (gexp-native-inputs exp) | 402 | (match (gexp-native-inputs exp) |
| 391 | (((($ (@@ (guix gexp) <system-binding>)) "out")) | 403 | ((input) |
| 392 | '(system-binding)) | 404 | (and (eq? (struct-vtable (gexp-input-thing input)) |
| 405 | (@@ (guix gexp) <system-binding>)) | ||
| 406 | (string=? (gexp-input-output input) "out") | ||
| 407 | '(system-binding))) | ||
| 393 | (x x))))) | 408 | (x x))))) |
| 394 | 409 | ||
| 395 | (test-assert "ungexp + ungexp-native" | 410 | (test-assert "ungexp + ungexp-native" |
| @@ -408,10 +423,10 @@ | |||
| 408 | (package-cross-derivation %store binutils target)))) | 423 | (package-cross-derivation %store binutils target)))) |
| 409 | (and (lset= equal? | 424 | (and (lset= equal? |
| 410 | `((,%bootstrap-guile "out") (,glibc "out")) | 425 | `((,%bootstrap-guile "out") (,glibc "out")) |
| 411 | (gexp-native-inputs exp)) | 426 | (map gexp-input->tuple (gexp-native-inputs exp))) |
| 412 | (lset= equal? | 427 | (lset= equal? |
| 413 | `((,coreutils "out") (,binutils "out")) | 428 | `((,coreutils "out") (,binutils "out")) |
| 414 | (gexp-inputs exp)) | 429 | (map gexp-input->tuple (gexp-inputs exp))) |
| 415 | (equal? `(list ,guile ,cu ,libc ,bu) | 430 | (equal? `(list ,guile ,cu ,libc ,bu) |
| 416 | (gexp->sexp* exp target))))) | 431 | (gexp->sexp* exp target))))) |
| 417 | 432 | ||
| @@ -419,7 +434,9 @@ | |||
| 419 | (list `((,%bootstrap-guile "out")) '<> `((,coreutils "out"))) | 434 | (list `((,%bootstrap-guile "out")) '<> `((,coreutils "out"))) |
| 420 | (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils))) | 435 | (let* ((exp (gexp (list (ungexp-native (gexp (ungexp coreutils))) |
| 421 | (ungexp %bootstrap-guile))))) | 436 | (ungexp %bootstrap-guile))))) |
| 422 | (list (gexp-inputs exp) '<> (gexp-native-inputs exp)))) | 437 | (list (map gexp-input->tuple (gexp-inputs exp)) |
| 438 | '<> | ||
| 439 | (map gexp-input->tuple (gexp-native-inputs exp))))) | ||
| 423 | 440 | ||
| 424 | (test-equal "ungexp + ungexp-native, nested, special mixture" | 441 | (test-equal "ungexp + ungexp-native, nested, special mixture" |
| 425 | `(() <> ((,coreutils "out"))) | 442 | `(() <> ((,coreutils "out"))) |
| @@ -427,7 +444,9 @@ | |||
| 427 | ;; (gexp-native-inputs exp) used to return '(), wrongfully. | 444 | ;; (gexp-native-inputs exp) used to return '(), wrongfully. |
| 428 | (let* ((foo (gexp (foo (ungexp-native coreutils)))) | 445 | (let* ((foo (gexp (foo (ungexp-native coreutils)))) |
| 429 | (exp (gexp (bar (ungexp foo))))) | 446 | (exp (gexp (bar (ungexp foo))))) |
| 430 | (list (gexp-inputs exp) '<> (gexp-native-inputs exp)))) | 447 | (list (map gexp-input->tuple (gexp-inputs exp)) |
| 448 | '<> | ||
| 449 | (map gexp-input->tuple (gexp-native-inputs exp))))) | ||
| 431 | 450 | ||
| 432 | (test-assert "input list" | 451 | (test-assert "input list" |
| 433 | (let ((exp (gexp (display | 452 | (let ((exp (gexp (display |
| @@ -438,7 +457,7 @@ | |||
| 438 | (package-derivation %store coreutils)))) | 457 | (package-derivation %store coreutils)))) |
| 439 | (and (lset= equal? | 458 | (and (lset= equal? |
| 440 | `((,%bootstrap-guile "out") (,coreutils "out")) | 459 | `((,%bootstrap-guile "out") (,coreutils "out")) |
| 441 | (gexp-inputs exp)) | 460 | (map gexp-input->tuple (gexp-inputs exp))) |
| 442 | (equal? `(display '(,guile ,cu)) | 461 | (equal? `(display '(,guile ,cu)) |
| 443 | (gexp->sexp* exp))))) | 462 | (gexp->sexp* exp))))) |
| 444 | 463 | ||
| @@ -457,10 +476,10 @@ | |||
| 457 | (package-cross-derivation %store binutils target)))) | 476 | (package-cross-derivation %store binutils target)))) |
| 458 | (and (lset= equal? | 477 | (and (lset= equal? |
| 459 | `((,%bootstrap-guile "out") (,coreutils "out")) | 478 | `((,%bootstrap-guile "out") (,coreutils "out")) |
| 460 | (gexp-native-inputs exp)) | 479 | (map gexp-input->tuple (gexp-native-inputs exp))) |
| 461 | (lset= equal? | 480 | (lset= equal? |
| 462 | `((,glibc "out") (,binutils "out")) | 481 | `((,glibc "out") (,binutils "out")) |
| 463 | (gexp-inputs exp)) | 482 | (map gexp-input->tuple (gexp-inputs exp))) |
| 464 | (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu))) | 483 | (equal? `(display (cons '(,guile ,cu) '(,xlibc ,xbu))) |
| 465 | (gexp->sexp* exp target))))) | 484 | (gexp->sexp* exp target))))) |
| 466 | 485 | ||
| @@ -474,7 +493,7 @@ | |||
| 474 | (exp (gexp (list (ungexp-splicing (cons (+ 2 3) inputs)))))) | 493 | (exp (gexp (list (ungexp-splicing (cons (+ 2 3) inputs)))))) |
| 475 | (and (lset= equal? | 494 | (and (lset= equal? |
| 476 | `((,glibc "debug") (,%bootstrap-guile "out")) | 495 | `((,glibc "debug") (,%bootstrap-guile "out")) |
| 477 | (gexp-inputs exp)) | 496 | (map gexp-input->tuple (gexp-inputs exp))) |
| 478 | (equal? (gexp->sexp* exp) | 497 | (equal? (gexp->sexp* exp) |
| 479 | `(list ,@(cons 5 outputs)))))) | 498 | `(list ,@(cons 5 outputs)))))) |
| 480 | 499 | ||
| @@ -484,7 +503,7 @@ | |||
| 484 | (exp (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs)))))) | 503 | (exp (gexp (list (ungexp-native-splicing (cons (+ 2 3) inputs)))))) |
| 485 | (and (lset= equal? | 504 | (and (lset= equal? |
| 486 | `((,glibc "debug") (,%bootstrap-guile "out")) | 505 | `((,glibc "debug") (,%bootstrap-guile "out")) |
| 487 | (gexp-native-inputs exp)) | 506 | (map gexp-input->tuple (gexp-native-inputs exp))) |
| 488 | (null? (gexp-inputs exp)) | 507 | (null? (gexp-inputs exp)) |
| 489 | (equal? (gexp->sexp* exp) ;native | 508 | (equal? (gexp->sexp* exp) ;native |
| 490 | (gexp->sexp* exp "mips64el-linux"))))) | 509 | (gexp->sexp* exp "mips64el-linux"))))) |
| @@ -492,7 +511,8 @@ | |||
| 492 | (test-assert "gexp list splicing + ungexp-splicing" | 511 | (test-assert "gexp list splicing + ungexp-splicing" |
| 493 | (let* ((inner (gexp (ungexp-native glibc))) | 512 | (let* ((inner (gexp (ungexp-native glibc))) |
| 494 | (exp (gexp (list (ungexp-splicing (list inner)))))) | 513 | (exp (gexp (list (ungexp-splicing (list inner)))))) |
| 495 | (and (equal? `((,glibc "out")) (gexp-native-inputs exp)) | 514 | (and (equal? `((,glibc "out")) |
| 515 | (map gexp-input->tuple (gexp-native-inputs exp))) | ||
| 496 | (null? (gexp-inputs exp)) | 516 | (null? (gexp-inputs exp)) |
| 497 | (equal? (gexp->sexp* exp) ;native | 517 | (equal? (gexp->sexp* exp) ;native |
| 498 | (gexp->sexp* exp "mips64el-linux"))))) | 518 | (gexp->sexp* exp "mips64el-linux"))))) |
