Skip to content

bayashi/actually

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actually

actually report card Go Reference

A testing library focused on turning failure into success, actually.

  • Builder interface to make test code obvious
  • Consistent method name to reduce things you have to remember
  • Specific fail report to save your time
  • There are helpers to see details of a failure

Usage

package main // https://go.dev/play/p/d57qXq3q6dl

import (
    "testing"
    a "github.com/bayashi/actually"
)

func Test(t *testing.T) {
    love, err := getLove()

    // Assert 1 object
    a.Got(err).NoError(t)
    a.Got(love).True(t)

    // Assert 2 objects
    heart := &love
    body  := heart
    a.Got(heart).Expect(body).SamePointer(t)
}

func getLove() (bool, error) {
    return true, nil
}

Assertions

  • True, False, Nil, NotNil, NoError
  • Same, SameConvertibleNumber, SamePointer, SameType
  • Cmp, CmpAllowUnexported, (CmpOpt)
  • NotSame, NotSameConvertibleNumber, NotSamePointer, NotSameType
  • Panic, PanicMessage, NoPanic
  • Match, NotMatch
  • Len

Here is a Wiki of full API documentation.


Fail reports

actually will help you with evident fail report:

builder_test.go:133:
            Test name:      TestTree
            Trace:          /path/to/src/github.com/bayashi/goverview/builder_test.go:133
            Fail reason:    Not same
            Expected:       Dump: "\n┌ 001/\n├── .gitignore\n├── LICENSE: License MIT\n├── go.mod: go 1.18\n└───+ main.go: main\n      Func: X\n      const: X\n"
            Actually got:   Dump: "\n┌ 001/\n├── .gitignore\n├── LICENSE: License MIT\n├── go.mod: go 1.19\n└──* main.go: main\n      Func: X\n      Const: X\n"
            Diff Details:   --- Expected
                            +++ Actually got
                            @@ -4,6 +4,6 @@
                             ├── LICENSE: License MIT
                            -├── go.mod: go 1.18
                            -└───+ main.go: main
                            +├── go.mod: go 1.19
                            +└──* main.go: main
                                   Func: X
                            -      const: X
                            +      Const: X
            Raw Expect:     ---
                            ┌ 001/
                            ├── .gitignore
                            ├── LICENSE: License MIT
                            ├── go.mod: go 1.18
                            └───+ main.go: main
                                  Func: X
                                  const: X
                            ---
            Raw Got:        ---
                            ┌ 001/
                            ├── .gitignore
                            ├── LICENSE: License MIT
                            ├── go.mod: go 1.19
                            └──* main.go: main
                                  Func: X
                                  Const: X

actually has the Debug("label", any_variable) method to show additional data only in fail report.

Like below, src variable will be dumped nicely only on fail.

res := someFunc(src)
actually.Got(res).Debug("src", src).True(t)

See more helper functions.


Installation

go get github.com/bayashi/actually

License

MIT License

Author

Dai Okabayashi: https://github.com/bayashi

See Also

Special Thanks

Inspired by: