union: Add 'relative-file-name'.

* guix/build/union.scm (%not-slash): New variable.
(relative-file-name): New procedure.
* tests/union.scm (test-relative-file-name): New macro and tests.
This commit is contained in:
Ludovic Courtès 2018-04-28 17:17:33 +02:00
parent 8584965b79
commit dac1c97d13
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 59 additions and 2 deletions

View file

@ -184,4 +184,22 @@
(file-is-directory? "bin")
(eq? 'symlink (stat:type (lstat "bin/guile"))))))))
(letrec-syntax ((test-relative-file-name
(syntax-rules (=>)
((_ (reference file => expected) rest ...)
(begin
(test-equal (string-append "relative-file-name "
reference " " file)
expected
(relative-file-name reference file))
(test-relative-file-name rest ...)))
((_)
#t))))
(test-relative-file-name
("/a/b" "/a/c/d" => "../c/d")
("/a/b" "/a/b" => "")
("/a/b" "/a" => "..")
("/a/b" "/a/b/c/d" => "c/d")
("/a/b/c" "/a/d/e/f" => "../../d/e/f")))
(test-end)