diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-03-06 11:25:43 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-03-12 18:32:15 +0100 |
| commit | cf2ac04f13d9266c7c8a2ebd2e85ef593231ac9d (patch) | |
| tree | 409921980504c7138e4dac8769823fb50becc516 /tests/gexp.scm | |
| parent | be78906592c761aa2a67e979074561e459efdcac (diff) | |
gexp: Add 'with-parameters'.
* guix/gexp.scm (<parameterized>): New record type.
(with-parameters): New macro.
(compile-parameterized): New gexp compiler.
* tests/gexp.scm ("with-parameters for %current-system")
("with-parameters for %current-target-system")
("with-parameters + file-append"): New tests.
* doc/guix.texi (G-Expressions): Document it.
Diffstat (limited to 'tests/gexp.scm')
| -rw-r--r-- | tests/gexp.scm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm index 9e38816c3dc..6a42d3eb57b 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm | |||
| @@ -284,6 +284,44 @@ | |||
| 284 | (((thing "out")) | 284 | (((thing "out")) |
| 285 | (eq? thing file)))))) | 285 | (eq? thing file)))))) |
| 286 | 286 | ||
| 287 | (test-assertm "with-parameters for %current-system" | ||
| 288 | (mlet* %store-monad ((system -> (match (%current-system) | ||
| 289 | ("aarch64-linux" "x86_64-linux") | ||
| 290 | (_ "aarch64-linux"))) | ||
| 291 | (drv (package->derivation coreutils system)) | ||
| 292 | (obj -> (with-parameters ((%current-system system)) | ||
| 293 | coreutils)) | ||
| 294 | (result (lower-object obj))) | ||
| 295 | (return (string=? (derivation-file-name drv) | ||
| 296 | (derivation-file-name result))))) | ||
| 297 | |||
| 298 | (test-assertm "with-parameters for %current-target-system" | ||
| 299 | (mlet* %store-monad ((target -> "riscv64-linux-gnu") | ||
| 300 | (drv (package->cross-derivation coreutils target)) | ||
| 301 | (obj -> (with-parameters | ||
| 302 | ((%current-target-system target)) | ||
| 303 | coreutils)) | ||
| 304 | (result (lower-object obj))) | ||
| 305 | (return (string=? (derivation-file-name drv) | ||
| 306 | (derivation-file-name result))))) | ||
| 307 | |||
| 308 | (test-assert "with-parameters + file-append" | ||
| 309 | (let* ((system (match (%current-system) | ||
| 310 | ("aarch64-linux" "x86_64-linux") | ||
| 311 | (_ "aarch64-linux"))) | ||
| 312 | (drv (package-derivation %store coreutils system)) | ||
| 313 | (param (make-parameter 7)) | ||
| 314 | (exp #~(here we go #$(with-parameters ((%current-system system) | ||
| 315 | (param 42)) | ||
| 316 | (if (= (param) 42) | ||
| 317 | (file-append coreutils "/bin/touch") | ||
| 318 | %bootstrap-guile))))) | ||
| 319 | (match (gexp->sexp* exp) | ||
| 320 | (('here 'we 'go (? string? result)) | ||
| 321 | (string=? result | ||
| 322 | (string-append (derivation->output-path drv) | ||
| 323 | "/bin/touch")))))) | ||
| 324 | |||
| 287 | (test-assert "ungexp + ungexp-native" | 325 | (test-assert "ungexp + ungexp-native" |
| 288 | (let* ((exp (gexp (list (ungexp-native %bootstrap-guile) | 326 | (let* ((exp (gexp (list (ungexp-native %bootstrap-guile) |
| 289 | (ungexp coreutils) | 327 | (ungexp coreutils) |
