summaryrefslogtreecommitdiff
path: root/tests/gexp.scm
diff options
context:
space:
mode:
authorNigko Yerden <nigko.yerden@gmail.com>2024-09-26 12:07:56 +0500
committerFlorian Pelz <pelzflorian@pelzflorian.de>2025-10-23 12:59:08 +0200
commit930ea819a5512c9c55a41eb6eb4ce66c8d3c62d1 (patch)
treec4370b13d66d451527bb7a1ebd86d7dae3482cb2 /tests/gexp.scm
parent85a44ae63604eb72026ce17fb4b758a21887b600 (diff)
gexp: Make 'local-file' follow symlinks.
Fix <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html> via making 'current-source-directory' always follow symlinks. * guix/utils.scm (absolute-dirname, current-source-directory): Make them follow symlinks. * tests/gexp.scm ("local-file, load through symlink"): New test. Fixes: guix/guix#3523 Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59 Signed-off-by: Florian Pelz <pelzflorian@pelzflorian.de>
Diffstat (limited to 'tests/gexp.scm')
-rw-r--r--tests/gexp.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 00bb729e763..3622324a153 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -314,6 +314,37 @@
314 (string=? (local-file-absolute-file-name file) 314 (string=? (local-file-absolute-file-name file)
315 (in-vicinity directory "the-unique-file.txt")))))) 315 (in-vicinity directory "the-unique-file.txt"))))))
316 316
317(test-assert "local-file, load through symlink"
318 ;; See <https://issues.guix.gnu.org/72867>.
319 (call-with-temporary-directory
320 (lambda (tmp-dir)
321 (with-directory-excursion tmp-dir
322 ;; create content file
323 (call-with-output-file "content"
324 (lambda (port) (display "Hi!" port)))
325 ;; Create a module that calls 'local-file' with the "content" file and
326 ;; returns its absolute file name. An error is raised if the "content"
327 ;; file can't be found.
328 (call-with-output-file "test-local-file.scm"
329 (lambda (port) (display "\
330(define-module (test-local-file)
331 #:use-module (guix gexp))
332(define file (local-file \"content\" \"test-file\"))
333(local-file-absolute-file-name file)" port)))
334 (mkdir "dir")
335 (symlink "../test-local-file.scm" "dir/test-local-file.scm")
336 ;; 'local-file' in turn calls 'current-source-directory' which has an
337 ;; 'if' branching condition depending on whether 'file-name' is
338 ;; absolute or relative file name. To test both of these branches we
339 ;; execute 'test-local-file.scm' symlink first as a module (corresponds
340 ;; to relative file name):
341 (dynamic-wind
342 (lambda () (set! %load-path (cons "dir" %load-path)))
343 (lambda () (resolve-module '(test-local-file) #:ensure #f))
344 (lambda () (set! %load-path (cdr %load-path))))
345 ;; and then as a regular code (corresponds to absolute file name):
346 (load (string-append tmp-dir "/dir/test-local-file.scm"))))))
347
317(test-assert "one plain file" 348(test-assert "one plain file"
318 (let* ((file (plain-file "hi" "Hello, world!")) 349 (let* ((file (plain-file "hi" "Hello, world!"))
319 (exp (gexp (display (ungexp file)))) 350 (exp (gexp (display (ungexp file))))