import ( "github.com/go-check/check" "C" ) func TestFoo(t *testing.T) { c := check.New(t) ret := C.foo() c.Assert(ret, check.Equals, C.SUCCESS, check.Commentf("foo failed")) if ret != C.SUCCESS { return errors.New("foo failed") } }
import ( "github.com/go-check/check" "C" ) func callBar() error { ret := C.bar() if ret != C.SUCCESS { return errors.New(fmt.Sprintf("bar failed with error code %d", ret)) } return nil }The gopkg.in.check.v1 package library is a popular third-party package for Go that provides support for unit testing and assertions. Its support for C error handling is an added bonus for developers who need to work with C code in their Go programs.