diff mbox series

[bug#67947,2/3] guix: build-system: cargo: Add cargo-test-targets.

Message ID 413c758092a856dae0c8e8b2e02a36dd1649e4cb.1703135457.git.jaeme@runbox.com
State New
Headers show
Series guix: cargo-build-system: Add test keys. | expand

Commit Message

Jaeme Sifat Dec. 21, 2023, 5:28 a.m. UTC
In addition to adding a key for skipping tests, there ought be a key for
specifying which test target(s) should be ran without having to edit
the #:cargo-test-flags key directly.

* guix/build-system/cargo.scm (cargo-build): Add cargo-test-targets.
* guix/build-system/cargo.scm (builder): Add cargo-test-targets.
* guix/build-system/cargo.scm (cargo-cross-build): Add cargo-test-targets.
* guix/build/cargo-build-system.scm (check): Add cargo-test-targets.

Change-Id: Ibdf3cffd2b0f3fdbfe269189975c739192c14f64
---
 guix/build-system/cargo.scm       |  4 ++++
 guix/build/cargo-build-system.scm | 25 +++++++++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
index d2a45f0609..7878a3bd6d 100644
--- a/guix/build-system/cargo.scm
+++ b/guix/build-system/cargo.scm
@@ -86,6 +86,7 @@  (define* (cargo-build name inputs
                       (vendor-dir "guix-vendor")
                       (cargo-build-flags ''("--release"))
                       (cargo-test-flags ''("--release"))
+                      (cargo-test-targets ''())
                       (cargo-skip-tests ''())
                       (cargo-package-flags ''("--no-metadata" "--no-verify"))
                       (features ''())
@@ -113,6 +114,7 @@  (define* (cargo-build name inputs
                        #:vendor-dir #$vendor-dir
                        #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
                        #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+                       #:cargo-test-targets #$(sexp->gexp cargo-test-targets)
                        #:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
                        #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
                        #:features #$(sexp->gexp features)
@@ -143,6 +145,7 @@  (define* (cargo-cross-build name
                             (vendor-dir "guix-vendor")
                             (cargo-build-flags ''("--release"))
                             (cargo-test-flags ''("--release"))
+                            (cargo-test-targets ''())
                             (cargo-skip-tests ''())
                             (cargo-package-flags ''("--no-metadata" "--no-verify"))
                             (features ''())
@@ -172,6 +175,7 @@  (define* (cargo-cross-build name
                        #:vendor-dir #$vendor-dir
                        #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
                        #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
+                       #:cargo-test-targets #$(sexp->gexp cargo-test-targets)
                        #:cargo-skip-tests #$(sexp->gexp cargo-skip-tests)
                        #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
                        #:features #$(sexp->gexp features)
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index 7cdb2a72d3..5abedfc726 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -258,19 +258,28 @@  (define* (build #:key
 
 (define* (check #:key
                 tests?
+                cargo-test-targets
                 cargo-skip-tests
                 (cargo-test-flags '("--release"))
                 #:allow-other-keys)
   "Run tests for a given Cargo package."
   (if tests?
-      (if cargo-skip-tests
-          (let ((test-lst (map (lambda (test)
-                              (string-append "--skip=" test))
-                            cargo-skip-tests)))
-            (apply invoke "cargo" "test" (append
-                                          cargo-test-flags
-                                          (cons* "--" test-lst))))
-          (apply invoke "cargo" "test" cargo-test-flags))
+      (let* ((cargo-test-targets-flags
+              (when cargo-test-targets
+                (map (lambda (section)
+                       (string-append "--" section))
+                     cargo-test-targets)))
+             (cargo-skip-tests-flags
+              (when cargo-skip-tests
+                (map (lambda (test)
+                       (string-append "--skip=" test))
+                     cargo-skip-tests)))
+             (cargo-test-flags
+              (append cargo-test-flags
+                      cargo-test-targets-flags
+                      '("--")
+                      cargo-skip-tests-flags)))
+        (apply invoke "cargo" "test" cargo-test-flags))
       #t))
 
 (define* (package #:key