summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2025-09-16 15:46:13 +0200
committerLudovic Courtès <ludo@gnu.org>2025-10-24 16:42:53 +0200
commit6aaed933bf63d6bc1f404124906cdd20ac67d3ba (patch)
treeb3883411068173f74cf0636b0f7ae8f6d1eaffb5 /tests
parent438a003051115b62f853e9db6c098be3d8c9c45e (diff)
import: utils: Add generate-git-source procedure.
This procedure tries to generate a <origin> sexp from a single url and version. * guix/import/utils.scm (generate-git-source): Add procedure. * tests/import/utils.scm: Add tests for generate-git-source. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/import/utils.scm42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/import/utils.scm b/tests/import/utils.scm
index 72f8e059a28..b631ba23268 100644
--- a/tests/import/utils.scm
+++ b/tests/import/utils.scm
@@ -26,8 +26,10 @@
26 #:use-module ((guix licenses) #:prefix license:) 26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (guix packages) 27 #:use-module (guix packages)
28 #:use-module (guix build-system) 28 #:use-module (guix build-system)
29 #:use-module (guix tests git)
29 #:use-module (gnu packages) 30 #:use-module (gnu packages)
30 #:use-module (srfi srfi-64) 31 #:use-module (srfi srfi-64)
32 #:use-module (srfi srfi-71)
31 #:use-module (ice-9 match)) 33 #:use-module (ice-9 match))
32 34
33(test-begin "import-utils") 35(test-begin "import-utils")
@@ -302,4 +304,44 @@ Differences are hard to spot, e.g. in CLOS vs. GOOPS."))
302 (let ((home-page "https://github.com/user/repo")) 304 (let ((home-page "https://github.com/user/repo"))
303 ((default-git-error home-page) '(some-other-error "message")))) 305 ((default-git-error home-page) '(some-other-error "message"))))
304 306
307;;;
308;;; generate-git-source
309;;;
310
311(define (test-generate-git-source git-version version)
312 "Helper to test generate-git-source. Creates a temporary git repository with
313GIT-VERSION tag, attempts to generate source for VERSION, and returns two
314values: the git-source commit S-expression, and a boolean indicating if the
315error procedure has been called."
316 (with-temporary-git-repository directory
317 `((add "README" "Initial commit")
318 (commit "First commit")
319 (tag ,git-version ,version))
320 (mock ((guix import utils) git-repository-url? (const #t))
321 (let* ((error-called? #f)
322 (error-proc (lambda args
323 (set! error-called? #t)
324 #f)))
325 (match (generate-git-source directory version error-proc)
326 (`(origin
327 (method git-fetch)
328 (uri (git-reference (url ,url)
329 (commit ,commit-sexp)))
330 . ,rest)
331 (values commit-sexp error-called?))
332 (_
333 (values #f error-called?)))))))
334
335(test-equal "generate-git-source: version with 'v' prefix tag"
336 '(string-append "v" version)
337 (test-generate-git-source "v1.0.0" "1.0.0"))
338
339(test-equal "generate-git-source: version without 'v' prefix tag"
340 'version
341 (test-generate-git-source "1.0.0" "1.0.0"))
342
343(test-assert "generate-git-source: calls error-procedure when tag not found"
344 (let ((sexp error-called? (test-generate-git-source "1.0.0" "2.0.0")))
345 error-called?))
346
305(test-end "import-utils") 347(test-end "import-utils")