summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-04-05 23:22:47 +0200
committerLudovic Courtès <ludo@gnu.org>2025-04-06 11:23:07 +0200
commit21221710f247b755f00f851ba7acedbef9bd7def (patch)
tree46b8209e8f653232d77d407273d4e018bd2dc7cb /tests
parent649b52b0d423c6d63f9de48346b8d730ddc41c51 (diff)
gexp: ‘local-file’ expands its argument only once.
Fixes a bug whereby (local-file (in-vicinity (getcwd) "xyz")) would point to different files depending on the current working directory at the time it is lowered. * guix/gexp.scm (local-file): Expand FILE only once. * tests/gexp.scm ("local-file, capture at the right time"): New test. Change-Id: I2cc23296de3799e68f7d8b7be6061be3043e1176
Diffstat (limited to 'tests')
-rw-r--r--tests/gexp.scm16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 2376c70d1ba..00bb729e763 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -298,6 +298,22 @@
(equal? (scandir (string-append dir "/tests"))
'("." ".." "gexp.scm"))))))
+(test-assert "local-file, capture file at the right time"
+ (call-with-temporary-directory
+ (lambda (directory)
+ (call-with-output-file (in-vicinity directory "the-unique-file.txt")
+ (lambda (port)
+ (display "Hi!" port)))
+
+ (let ((file (with-directory-excursion directory
+ ;; If the argument to 'local-file' were resolved when
+ ;; 'local-file-absolute-file-name' is called, we'd get the
+ ;; wrong result.
+ (local-file (in-vicinity (getcwd)
+ "the-unique-file.txt")))))
+ (string=? (local-file-absolute-file-name file)
+ (in-vicinity directory "the-unique-file.txt"))))))
+
(test-assert "one plain file"
(let* ((file (plain-file "hi" "Hello, world!"))
(exp (gexp (display (ungexp file))))