all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sharlatan Hellseher <sharlatanus@gmail.com>
To: 74668@debbugs.gnu.org
Cc: Sharlatan Hellseher <sharlatanus@gmail.com>,
	Katherine Cox-Buday <cox.katherine.e+guix@gmail.com>,
	Sharlatan Hellseher <sharlatanus@gmail.com>
Subject: [bug#74668] [PATCH 2/2] build-system/go: Add test-subdirs option key.
Date: Tue,  3 Dec 2024 11:45:34 +0000	[thread overview]
Message-ID: <3abe629c9ce6355ac9e163bcc9345e856d3f2434.1733224617.git.sharlatanus@gmail.com> (raw)
In-Reply-To: <cover.1733224617.git.sharlatanus@gmail.com>

Golang projects may contain subdirectories with test files, which can't
be reached by providing just IMPORT-PATH to the test runner.  This
change implements a TEST-SUBDIRS key parameter which is by default set
to "import-path/..." to run all available tests in the project, and may
be limited to particular subdirs list.

* guix/build-system/go.scm (go-build, go-cross-build): Add "test-subdirs"
key parameter.
* guix/build/go-build-system.scm (check): Add "test-subdirs" key
parameter and adjust test invokation accordingly.

Change-Id: Ibc107deea060f0d71e6f4e1e37c81d3b7c9992f5
---
 guix/build-system/go.scm       |  4 ++++
 guix/build/go-build-system.scm | 18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
index 97581a14c6..66cb5e8b05 100644
--- a/guix/build-system/go.scm
+++ b/guix/build-system/go.scm
@@ -205,6 +205,7 @@ (define* (go-build name inputs
                    (build-flags ''())
                    (tests? #t)
                    (test-flags ''())
+                   (test-subdirs ''("..."))
                    (parallel-build? #t)
                    (parallel-tests? #t)
                    (allow-go-reference? #f)
@@ -239,6 +240,7 @@ (define* (go-build name inputs
                     #:build-flags #$build-flags
                     #:tests? #$tests?
                     #:test-flags #$test-flags
+                    #:test-subdirs #$test-subdirs
                     #:parallel-build? #$parallel-build?
                     #:parallel-tests? #$parallel-tests?
                     #:allow-go-reference? #$allow-go-reference?
@@ -264,6 +266,7 @@ (define* (go-cross-build name
                          (build-flags ''())
                          (tests? #f)              ; nothing can be done
                          (test-flags ''())
+                         (test-subdirs ''("..."))
                          (allow-go-reference? #f)
                          (system (%current-system))
                          (goarch (first (go-target target)))
@@ -316,6 +319,7 @@ (define* (go-cross-build name
                     #:build-flags #$build-flags
                     #:tests? #$tests?
                     #:test-flags #$test-flags
+                    #:test-subdirs #$test-subdirs
                     #:make-dynamic-linker-cache? #f ;cross-compiling
                     #:allow-go-reference? #$allow-go-reference?
                     #:inputs %build-inputs))))
diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index a463189011..7d702d7f1f 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -98,6 +98,10 @@ (define-module (guix build go-build-system)
 ;; * Remove module packages, only offering the full Git repos? This is
 ;; more idiomatic, I think, because Go downloads Git repos, not modules.
 ;; What are the trade-offs?
+;; * Figurie out how to passthrough --verbosity option to "build" and "check"
+;; procedures.
+;; * Implement test-backend option, which would be similar to pyproject's
+;; one, allowing to provide custom test runner.
 ;;
 ;; [0] `go build`:
 ;; https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies
@@ -325,13 +329,23 @@ (define* (build #:key
                               "Here are the results of `go env`:\n"))
       (invoke "go" "env"))))
 
-(define* (check #:key tests? import-path test-flags (parallel-tests? #t)
+(define* (check #:key
+                tests?
+                import-path
+                test-flags
+                test-subdirs
+                (parallel-tests? #t)
                 #:allow-other-keys)
   "Run the tests for the package named by IMPORT-PATH."
   (when tests?
     (let* ((njobs (if parallel-tests? (parallel-job-count) 1)))
       (setenv "GOMAXPROCS" (number->string njobs)))
-    (apply invoke "go" "test" `(,import-path ,@test-flags)))
+    (apply invoke "go" "test"
+           `(,@(map (lambda (dir)
+                      (format #f "~a~:[/~;~]~a"
+                              import-path (string-null? dir) dir))
+                    test-subdirs)
+             ,@test-flags)))
   #t)
 
 (define* (install #:key install-source? outputs import-path unpack-path #:allow-other-keys)
-- 
2.46.0





      parent reply	other threads:[~2024-12-03 11:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-03 11:44 [bug#74668] [PATCH 0/2] Golang build-system adjustments Sharlatan Hellseher
2024-12-03 11:45 ` [bug#74668] [PATCH 1/2] build: go-build-system: Relax build verbosity Sharlatan Hellseher
2024-12-03 11:45 ` Sharlatan Hellseher [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3abe629c9ce6355ac9e163bcc9345e856d3f2434.1733224617.git.sharlatanus@gmail.com \
    --to=sharlatanus@gmail.com \
    --cc=74668@debbugs.gnu.org \
    --cc=cox.katherine.e+guix@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.