On Tue, 19 Nov 2024 at 15:25, Chris Burkert <burkert.ch...@gmail.com> wrote:

> Hey there,
>
> I have a package "test", which is only used in tests and which contains
> one function: https://go.dev/play/p/Ne1xGXsQNmy
>
> This leads to a finding when running deadcode:
>
> $ deadcode ./...
> test/testg.go:8:6: unreachable func: SkipIfIntegration
>

To me, that seems like an issue with the deadcode linter. In particular, I
don't understand why it would ever complain about an exported function.
That is almost definitionally not "dead".


> I tried several things:
> - renaming the package to "test_test"
> - renaming the file to "test_test.go"
>
> I think https://github.com/golang/go/issues/31135 and
> https://github.com/golang/go/issues/39565 address the same topic.
>

> It seems that in *_test.go files you cannot import from other *_test.go
> files in other packages.
>
> My workaround: I run deadcode -test ./... but then I may miss unused code,
> which may have an old test.
>
> Is there a better way?
>

Maybe you can add something like `var _ = SkipIfIntegration` to your
package? i.e. trick the linter to stop it from complaining?


>
> PS: I want to follow
> https://www.konradreiche.com/blog/how-to-separate-integration-tests-in-go/
>
> thanks
> Chris
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/CALWqRZpziVRJ_9ifRXNEzhGk8negv7xbjwZod24sSbcuvt9KQQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/golang-nuts/CALWqRZpziVRJ_9ifRXNEzhGk8negv7xbjwZod24sSbcuvt9KQQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEXLv%2BXZy7wJZq%3Dg3vGFrUpm_8tC2i%2BQwbYhtPApcTMJg%40mail.gmail.com.

Reply via email to