On Tue, 2022-01-04 at 08:29 -0800, Brieuc Jeunhomme wrote:
> Hi,
>
> I'm writing code that uses the golang.org/x/sys/windows/svc package.
> This package compiles only for windows builds, for other GOOS values,
> I get a build error.  That's fair, but I'm wondering how to unit test
> the code that calls svc functions when working on a non-windows
> environment.  So code that looks like:
>
> func myFunction() {
>     svc.Foo(make(chan svc.Bar))
> }
>
> Is there a well known way to do that, or am I missing something

You can use build constraints, for example `// +build windows` and `//
+build !windows` to selectively build the tests only on the desired
platform[1].


[1]https://pkg.go.dev/cmd/go#hdr-Build_constraints



-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/25c15063f8a6462abdd79434116a9adec1dfcd24.camel%40kortschak.io.

Reply via email to