Hi,

I can't say that I'm an expert in Golang :-), but I've got some experience in
building and deploying Glang daily for some time.

First things first the default behaviour of `go test ./...` is like this:

--8<---------------cut here---------------start------------->8---
find * -type f -name *_test.go | <golang-internal-assertion>
--8<---------------cut here---------------start------------->8---

Internally Golang tries to find any files with _test.go suffix in
provided module's
location and evaluate defined tests in them. If the directory of the module does
not have test files it's just ignored.

Now in actions.

If we investigate which test files we have for `go-github-com-stretchr-testify`
we'll see that for the current version packed in Guix there are some:

--8<---------------cut here---------------start------------->8---
guix describe
Generation 503  Jan 16 2024 13:15:09    (current)
  guix 8520f00
    repository URL: https://git.savannah.gnu.org/git/guix.git
    branch: master
    commit: 8520f00d6989ff5ab22755a97dfcfd0375f6b5ca

guix time-machine --commit=8520f00d6989ff5ab22755a97dfcfd0375f6b5ca -- \
shell findutils -- \
find $(guix build go-github-com-stretchr-testify  --no-substitutes)
-type f -name "*_test.go"
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/suite/suite_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/suite/stats_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/mock/mock_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/package_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/require/requirements_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/require/forward_requirements_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/assert/http_assertions_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/assert/forward_assertions_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/assert/assertion_order_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/assert/assertion_compare_test.go
/gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/assert/assertions_test.go
--8<---------------cut here---------------start------------->8---

Checking current implementation of the go-build-system.scm I realized that it
only runs test available in `import-path` and does not scan any farther like
the `./...` option does. In our case it is just one file, rest are ignored.

> /gnu/store/jpizwxbhr93wmday0raz0vk0ny5s5jiv-go-github-com-stretchr-testify-1.7.0/src/github.com/stretchr/testify/package_test.go

> guix/guix/build/go-build-system.scm
--8<---------------cut here---------------start------------->8---
;; Can this also install commands???
(define* (check #:key tests? import-path #:allow-other-keys)
  "Run the tests for the package named by IMPORT-PATH."
  (when tests?
    (invoke "go" "test" import-path))
  #t)
--8<---------------cut here---------------start------------->8---

With small adjustment of the invok line, I could manage to trigger all tests to
be run, but it brings other issue of some not packed modules required for the
check phase.

--8<---------------cut here---------------start------------->8---
@@ -275,7 +275,7 @@ (define* (build #:key import-path build-flags
#:allow-other-keys)
 (define* (check #:key tests? import-path #:allow-other-keys)
   "Run the tests for the package named by IMPORT-PATH."
   (when tests?
-    (invoke "go" "test" import-path))
+    (invoke "go" "test" (string-append import-path "/...")))
   #t)

 (define* (install #:key install-source? outputs import-path
unpack-path #:allow-other-keys)
--8<---------------cut here---------------start------------->8---

As a quick ad-hoc to run all tests for some new package you may add a custom
check phase with the snippet you provided.

I'm currently in review and split some packages from (gnu packages golang) into
(gnu packages golang-crypto) to simplify the maintenance. I try to play with
that option and see which packages are missed to satisfy passing all tests.

Thanks,
Oleg

On Wed, 17 Jan 2024 at 20:25, Simon Tournier <zimon.touto...@gmail.com> wrote:
>
> Hi,
>
> CC:
>     $ ./etc/teams.scm list-members go
>     Katherine Cox-Buday <cox.katherine.e+g...@gmail.com>
>     Sharlatan Hellseher <sharlata...@gmail.com>
>
>
> On Sun, 14 Jan 2024 at 22:12, Troy Figiel <t...@troyfigiel.com> wrote:
>
> > --8<---------------cut here---------------start------------->8---
> > (define* (check #:key tests? import-path #:allow-other-keys)
> >   "Run the tests for the package named by IMPORT-PATH."
> >   (when tests?
> >     (invoke "go" "test" (string-append import-path "/...")))
> >   #t)
> > --8<---------------cut here---------------end--------------->8---
> >
> > For example, if the -v flag is added (which might be a better default?)
> > to the check phase of go-github-stretchr-testify, it can be seen that
> > only `TestImports' runs, none of the tests in assert, http, etc.
> > However, the source code in these subdirectories is still recursively
> > copied to out during the install phase.
> >
> > Is this desired behaviour? I assumed it isn't, because it looks like we
> > are skipping a lot of tests during the check phase. However, I might
> > also simply be overlooking something here as I am new to packaging
> > Golang with Guix.
>
> From your description, it seems a good idea.  What do Go “experts“
> think?
>
> Cheers,
> simon



-- 
VCS: https://github.incerto.xyz/; https://git.sr.ht/~hellseher/
GPG: 9847 81DE 689C 21C2 6418 0867 76D7 27BF F62C D2B5

… наш разум - превосходная объяснительная машина которая способна
найти смысл почти в чем угодно, истолковать любой феномен, но
совершенно не в состоянии принять мысль о непредсказуемости.

Reply via email to