diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2026-02-27 17:28:44 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2026-05-10 17:01:08 +0200 |
| commit | 2d4f290e17c5dbe4b97ece9320eef0a4ad3d821e (patch) | |
| tree | ff321ed4e31ce3db3ca707deb49d14cb0766fa95 /tests | |
| parent | 882f46bdd7b9d32e62af8c23e77b3992460e3b38 (diff) | |
ui: ‘load*’ accepts a file name or a port.
* guix/ui.scm (load/isolated): Change ‘file’ parameter to ‘port’ and adjust
accordingly.
(load*): Change ‘file’ to ‘file-or-port’ and adjust accordingly.
* tests/ui.scm ("load/isolated, reading exceeds limits")
("load/isolated, attempt to import module")
("load/isolated, attempt to allocate with 'cons'")
("load/isolated, attempt to allocate with 'make-vector'")
("load/isolated, use of allowed bindings"): New tests.
Change-Id: I0ec8fa2717c02041d409f6dc59b753d4501107f9
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui.scm | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/tests/ui.scm b/tests/ui.scm index 438acae5252..048f8500722 100644 --- a/tests/ui.scm +++ b/tests/ui.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2013-2017, 2019-2020, 2022 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2013-2017, 2019-2020, 2022, 2026 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info> | 3 | ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| @@ -26,11 +26,19 @@ | |||
| 26 | #:use-module ((gnu packages) #:select (specification->package)) | 26 | #:use-module ((gnu packages) #:select (specification->package)) |
| 27 | #:use-module (guix tests) | 27 | #:use-module (guix tests) |
| 28 | #:use-module (guix utils) | 28 | #:use-module (guix utils) |
| 29 | #:use-module ((guix channels) | ||
| 30 | #:select (channel->code | ||
| 31 | %default-guix-channel | ||
| 32 | guix-channel? | ||
| 33 | channel-introduction)) | ||
| 29 | #:use-module (srfi srfi-1) | 34 | #:use-module (srfi srfi-1) |
| 30 | #:use-module (srfi srfi-11) | 35 | #:use-module (srfi srfi-11) |
| 31 | #:use-module (srfi srfi-19) | 36 | #:use-module (srfi srfi-19) |
| 32 | #:use-module (srfi srfi-26) | 37 | #:use-module (srfi srfi-26) |
| 33 | #:use-module (srfi srfi-64) | 38 | #:use-module (srfi srfi-64) |
| 39 | #:use-module (rnrs bytevectors) | ||
| 40 | #:use-module (ice-9 binary-ports) | ||
| 41 | #:use-module (ice-9 match) | ||
| 34 | #:use-module (ice-9 regex)) | 42 | #:use-module (ice-9 regex)) |
| 35 | 43 | ||
| 36 | ;; Test the (guix ui) module. | 44 | ;; Test the (guix ui) module. |
| @@ -369,4 +377,84 @@ Second line" 24)) | |||
| 369 | ("PAGER" #false)) | 377 | ("PAGER" #false)) |
| 370 | (assert-equals-find-available-pager ""))))) | 378 | (assert-equals-find-available-pager ""))))) |
| 371 | 379 | ||
| 380 | (test-equal "load/isolated, reading exceeds limits" | ||
| 381 | 'quit ;'limit-exceeded is raised, caught, and then 'quit is raised | ||
| 382 | (let ((port (make-custom-binary-input-port | ||
| 383 | "infinite-paren-stream" | ||
| 384 | (lambda (bv start count) | ||
| 385 | (bytevector-u8-set! bv start (char->integer #\()) | ||
| 386 | 1) | ||
| 387 | #f #f #f))) | ||
| 388 | (catch #t | ||
| 389 | (lambda () | ||
| 390 | (load* port '() #:isolated? #t) | ||
| 391 | #f) | ||
| 392 | (lambda (key . args) | ||
| 393 | key)))) | ||
| 394 | |||
| 395 | (test-equal "load/isolated, attempt to import module" | ||
| 396 | 'quit | ||
| 397 | (call-with-input-string (object->string | ||
| 398 | '(begin | ||
| 399 | (use-modules (system foreign)) | ||
| 400 | (dereference-pointer (make-pointer 123)))) | ||
| 401 | (lambda (port) | ||
| 402 | (catch #t | ||
| 403 | (lambda () | ||
| 404 | (load* port '() #:isolated? #t) | ||
| 405 | #f) | ||
| 406 | (lambda (key . args) | ||
| 407 | key))))) | ||
| 408 | |||
| 409 | (test-equal "load/isolated, attempt to allocate with 'cons'" | ||
| 410 | 'quit | ||
| 411 | ;; 'make-list' is not available in the environment so try to allocate memory | ||
| 412 | ;; via macro expansion or repeated calls to 'cons'. | ||
| 413 | (call-with-input-string | ||
| 414 | (object->string | ||
| 415 | '(letrec-syntax ((make-list | ||
| 416 | (lambda (s) | ||
| 417 | (syntax-case s () | ||
| 418 | ((_ 0) #''()) | ||
| 419 | ((_ n) | ||
| 420 | #`(cons #f | ||
| 421 | (make-list | ||
| 422 | #,(- (syntax->datum #'n) 1)))))))) | ||
| 423 | (make-list 100000))) | ||
| 424 | (lambda (port) | ||
| 425 | (catch #t | ||
| 426 | (lambda () | ||
| 427 | (load* port '() #:isolated? #t) | ||
| 428 | #f) | ||
| 429 | (lambda (key . args) | ||
| 430 | key))))) | ||
| 431 | |||
| 432 | (test-equal "load/isolated, attempt to allocate with 'make-vector'" | ||
| 433 | 'quit | ||
| 434 | ;; 'make-vector' is not available in the environment. | ||
| 435 | (call-with-input-string (object->string '(make-vector 123123123)) | ||
| 436 | (lambda (port) | ||
| 437 | (catch #t | ||
| 438 | (lambda () | ||
| 439 | (load* port '() #:isolated? #t) | ||
| 440 | #f) | ||
| 441 | (lambda (key . args) | ||
| 442 | key))))) | ||
| 443 | |||
| 444 | (test-assert "load/isolated, use of allowed bindings" | ||
| 445 | (call-with-input-string | ||
| 446 | (object->string | ||
| 447 | `(list ,(channel->code %default-guix-channel))) | ||
| 448 | (lambda (port) | ||
| 449 | (match (load* port | ||
| 450 | '(((guix channels) | ||
| 451 | channel make-channel-introduction openpgp-fingerprint)) | ||
| 452 | #:isolated? #t) | ||
| 453 | ((channel) | ||
| 454 | ;; The channels have a different 'location' field value hence this | ||
| 455 | ;; limited comparison. | ||
| 456 | (and (guix-channel? channel) | ||
| 457 | (equal? (channel-introduction channel) | ||
| 458 | (channel-introduction %default-guix-channel)))))))) | ||
| 459 | |||
| 372 | (test-end "ui") | 460 | (test-end "ui") |
