Skip to content

shu-go/gotwant

Repository files navigation

Package gotwant provides "got: , want: " style test functions.

Go Report Card MIT License

Usage

Test

package hoge_test

import "github.com/shu-go/gotwant"

func TestWithGotwant(t *testing.T) {
    v := 1 + 2
    gotwant.Test(t, v, 3) // pass
    gotwant.Test(t, v, "12") // error
    // hoge_test.go:8:
    //     got:  3
    //     want: 12

    v = somefunc()
    gotwant.TestExpr(t, v, v == nil)
    // hoge_test.go:14:
    //     got:  100

    _, e = openFile("hoge_test.go")
    gotwant.Error(t, e, "perm") // pass
    gotwant.Error(t, e, "not found")
    // hoge_test.go:20:
    //     got error:  "permission denied"
    //     want error: "not found"
}

Colorise test output

go install github.com/shu-go/gotwant/cmd/gotwant@latest
go test | gotwant

The want part is colored-diff, showing how the got part should be changed. (red should be deleted, green should be inserted)

The got part is as-is.

About

Package gotwant provides "got: , want: " style test functions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages