Code Monkey home page Code Monkey logo

got's Introduction

Overview

An enjoyable golang test framework.

Features

  • Pretty output using gop and diff
  • Fluent API design that takes the full advantage of IDE
  • Handy assertion helpers
  • Handy utils for testing
  • Value snapshot assertion
  • Customizable assertion error output

Guides

Read the example project to get started.

Got uses itself as the test framework, so the source code itself is the best doc.

Install the vscode extension for snippets like: gp, gt, and gsetup.

To ensure test coverage of your project, you can run the command below:

go test -race -coverprofile=coverage.out ./...
go run github.com/ysmood/got/cmd/check-cov@latest

By default the check-cov requires 100% coverage, run it with the -h flag to see the help doc.

API reference

Link

got's People

Contributors

jeoam avatar mamaship avatar ysmood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

got's Issues

Compare gop with litter

litter doesn't support colorized output, I created this issue 3 years ago on it, still unresolved: sanity-io/litter#27

Let's use real data to compare them, below is the data to print:

val := map[string]interface{}{
	"bool":   true,
	"number": 1 + 1i,
	"bytes":  []byte{97, 98, 99},
	"lines":  "multiline string\nline two",
	"slice":  []interface{}{1, 2},
	"time":   time.Now(),
	"struct": struct{ test int32 }{
		test: 13,
	},
}
val["slice"].([]interface{})[1] = val["slice"]

litter will output:

map[string]interface {}{
  "bool": true,
  "bytes": []uint8{
    97,
    98,
    99,
  },
  "lines": "multiline string\nline two",
  "number": complex128(1+1i),
  "slice": []interface {}{ // p0
    1,
    p0,
  },
  "struct": struct { test int32 }{},
  "time": time.Time{},
}

gop will output:

map[string]interface {}/* len=7 */{
    "bool": true,
    "bytes": []byte("abc")/* len=3 */,
    "lines": "" +
        "multiline string\n" +
        "line two"/* len=25 */,
    "number": 1+1i,
    "slice": []interface {}/* len=2 cap=2 */{
        1,
        gop.Circular("slice").([]interface {}),
    },
    "struct": struct { test int32 }{
        test: int32(13),
    },
    "time": gop.Time("2022-03-23T10:25:54.424021+08:00"),
}
  • litter doesn't support colorized output
  • litter doesn't print readable []byte
  • litter is not able to print time data
  • litter's output for circular data is not compilable, because p0 is undefined, and they have to guess the meaning of p0, but with gop user can jump to the definition of gop.Cyclic to read the doc.
  • litter is not able to print the nested value of struct{ test int32 }
  • litter doesn't use the shortest form to print the complex number
  • litter doesn't split the multiline text block
  • litter doesn't print the length of long string, map, and slice, etc

Mock code generation cli tool

Such as run the command below:

go run github.com/ysmood/got/cmd/mock@latest w myWriter io.Writer

To output generated golang code to the stdout:

type myWriter struct {
	got.Mock
}

func (w *myWriter) Write(p []byte) (n int, err error) {
	return t.Proxy("Write").(func([]byte) (int, error))(p)
}

Improve the words sequence for lines

We should also consider the non-English words, such as for sentences like find a place to eat 热干面 we should split it into:

  • find
  • a
  • place
  • to
  • eat

The current way we do it is not performant:

got/lib/diff/sequence.go

Lines 33 to 36 in 2338a20

// NewString from string
func NewString(s string) Comparables {
cs := make([]Comparable, len(s))
for i, c := range s {

A case of gop crash

package main

import (
	"log"

	"github.com/imroc/req/v3"
	"github.com/ysmood/got/lib/gop"
)

func main() {
	resp, err := req.C().R().Get("https://www.qq.com")
	if err != nil {
		log.Panic(err)
	}
	if err := gop.P(resp); err != nil {
		log.Panic(err)
	}
}

output:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc02f701420 stack=[0xc02f700000, 0xc04f700000]
fatal error: stack overflow

我已经是第四次找不到gop这个库了

并且是第四次在 v2ex 上搜索 gop 才找回来的

我收藏了。一开始就。

请问能否把 gop utils 独立出去? 或者至少在首页的 README 上给一个相关的 example, 否则实在是很难看到

You'd better specify the minimum version it depends on

You'd better specify the minimum version it depends on.

E:\goPath\pkg\mod\github.com\ysmood\[email protected]\lib\utils\utils.go:22:10: xVal.CanConvert undefined (type reflect.Value has no field or method CanConvert)
E:\goPath\pkg\mod\github.com\ysmood\[email protected]\lib\utils\utils.go:22:42: yVal.CanConvert undefined (type reflect.Value has no field or method CanConvert)

func (Value) CanConvert added in go1.17

tokenize panics when comparing array with Gt()

This used to work in v0.15.1 but after upgrade to v0.31.3 the following line causes a panic at tokenize. I don't know if this is an expected outcome or not, but wanted to mention it.

t.Gt(j.Get("merchants").Arr(), 0)

panic:

         each.go:110: [panic] runtime error: index out of range [7] with length 7
            goroutine 77 [running]:
            runtime/debug.Stack()
                /home/rusty/go/src/runtime/debug/stack.go:24 +0x65
            github.com/ysmood/got.callMethod.func1()
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/each.go:110 +0x58
            panic({0xbbedc0, 0xc0006abf98})
                /home/rusty/go/src/runtime/panic.go:838 +0x207
            github.com/ysmood/got/lib/gop.path.has(...)
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:121
            github.com/ysmood/got/lib/gop.seen.circular(0xaf05c0?, {0xc000230700, 0x7, 0x8}, {0xaf05c0?, 0xc00086d788?, 0x10?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:138 +0x5f9
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000230700, 0x7, 0x8}, {0xaf05c0?, 0xc00086d788?, 0xc0007f0570?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:155 +0xc5
            github.com/ysmood/got/lib/gop.tokenize(0xb324c0?, {0xc000230700, 0x7, 0x8}, {0xb1d080?, 0xc000b18e30?, 0xc000168998?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xb324c0?, {0xc000230700, 0x6, 0x8}, {0xb324c0?, 0xc0006bd4d0?, 0x10?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:267 +0x196d
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000230700, 0x6, 0x8}, {0xb324c0?, 0xc0006bd4d0?, 0xc0007f0b08?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenize(0xb324c0?, {0xc000230700, 0x6, 0x8}, {0xb1d080?, 0xc000b18dd0?, 0xc000af7ee8?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xb324c0?, {0xc000230700, 0x5, 0x8}, {0xb324c0?, 0xc0006bd2f0?, 0x10?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:267 +0x196d
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000230700, 0x5, 0x8}, {0xb324c0?, 0xc0006bd2f0?, 0xc0007f10a0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenize(0xb324c0?, {0xc000230700, 0x5, 0x8}, {0xb1d080?, 0xc00015fb90?, 0x80?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xb324c0?, {0xc000c95040, 0x4, 0x4}, {0xb324c0?, 0xc0006bd260?, 0x42ea5b?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:267 +0x196d
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000c95040, 0x4, 0x4}, {0xb324c0?, 0xc0006bd260?, 0x100c000af7718?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenize(0xaf05c0?, {0xc000c95040, 0x4, 0x4}, {0xb1d080?, 0xc0006c0f50?, 0xc000af77e8?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xaf05c0?, {0xc000c95040, 0x3, 0x4}, {0xaf05c0?, 0xc00086d800?, 0x8?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:247 +0x12b5
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000c95040, 0x3, 0x4}, {0xaf05c0?, 0xc00086d800?, 0xc0007f1bd0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenize(0xb324c0?, {0xc000c95040, 0x3, 0x4}, {0xb1d080?, 0xc00015f460?, 0x20?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xb324c0?, {0xc000592de0, 0x2, 0x2}, {0xb324c0?, 0xc0006bd230?, 0xc0007f1f98?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:267 +0x196d
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000592de0, 0x2, 0x2}, {0xb324c0?, 0xc0006bd230?, 0x200?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenize(0xae47a0?, {0xc000592de0, 0x2, 0x2}, {0xb1d080?, 0xc0006c1230?, 0xc0007f22b0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:163 +0x554
            github.com/ysmood/got/lib/gop.tokenizePtr(0xae47a0?, {0xc000592de0, 0x2, 0x2}, {0xae47a0?, 0xc00015f3c8?, 0x40f3e5?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:441 +0x487
            github.com/ysmood/got/lib/gop.tokenize(0xb1d080?, {0xc000592de0, 0x2, 0x2}, {0xae47a0?, 0xc00015f3c8?, 0x0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:193 +0xc85
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xbe3ca0?, {0xc00015f290, 0x1, 0x1}, {0xbe3ca0?, 0xc0005c02e0?, 0x7f6a8a6dc200?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:287 +0xe1f
            github.com/ysmood/got/lib/gop.tokenize(0xaee5c0?, {0xc00015f290, 0x1, 0x1}, {0xbe3ca0?, 0xc0005c02e0?, 0xafdbe0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.tokenizeCollection(0xaee5c0?, {0x125dab8, 0x0, 0x0}, {0xaee5c0?, 0xc00086d9e0?, 0x7f6a8a6a2200?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:247 +0x12b5
            github.com/ysmood/got/lib/gop.tokenize(0x0?, {0x125dab8, 0x0, 0x0}, {0xaee5c0?, 0xc00086d9e0?, 0xc0006a2f18?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:206 +0xcde
            github.com/ysmood/got/lib/gop.Tokenize({0xaee5c0?, 0xc00086d9e0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/token.go:102 +0x12e
            github.com/ysmood/got/lib/gop.Plain({0xaee5c0?, 0xc00086d9e0?})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/gop/format.go:75 +0x25
            github.com/ysmood/got/lib/utils.Compare({0xaee5c0?, 0xc00086d9e0?}, {0xafd260, 0xd2e848})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/utils/utils.go:39 +0x31
            github.com/ysmood/got/lib/utils.SmartCompare({0xaee5c0?, 0xc00086d9e0}, {0xafd260?, 0xd2e848})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/lib/utils/utils.go:34 +0x43f
            github.com/ysmood/got.Assertions.Gt({{0xd3a1c0, 0xc000642d00}, {0xd30d00, 0xc0005b6030}, 0x0, {0x0, 0x0}}, {0xaee5c0?, 0xc00086d9e0}, {0xafd260, ...})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/assertions.go:78 +0x97
            github.com/zeals-co-ltd/dx-reservation/pkg/admin_test.T.ManageConfigViaUserAccount({{{0xd3a1c0, 0xc000642d00}, {{0xd3a1c0, 0xc000642d00}, {0xd30d00, 0xc0005b6030}, 0x0, {0x0, 0x0}}, {{0xd3a1c0, ...}}}, ...})
                /home/rusty/Documents/repo/dx-reservation/pkg/admin/basic_test.go:56 +0x51f
            reflect.Value.call({0xc0008b9860?, 0xc000010e28?, 0x7f6ab1194108?}, {0xc0a7d6, 0x4}, {0xc000bb8b10, 0x1, 0x0?})
                /home/rusty/go/src/reflect/value.go:556 +0x845
            reflect.Value.Call({0xc0008b9860?, 0xc000010e28?, 0x0?}, {0xc000bb8b10, 0x1, 0x1})
                /home/rusty/go/src/reflect/value.go:339 +0xbf
            github.com/ysmood/got.callMethod({0xd3a1c0, 0xc000642d00}, {{0xac4be9, 0x1a}, {0x0, 0x0}, {0xd3c5e0, 0xc0008b9860}, {0xc0008b9860, 0xc000010e28, ...}, ...}, ...)
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/each.go:115 +0x211
            github.com/ysmood/got.Each.func1({0xc000bb8108, 0x1, 0x1})
                /home/rusty/go/pkg/mod/github.com/ysmood/[email protected]/each.go:48 +0x18e
            testing.tRunner(0xc000642d00, 0xc0001467e0)
                /home/rusty/go/src/testing/testing.go:1439 +0x102
            created by testing.(*T).Run
                /home/rusty/go/src/testing/testing.go:1486 +0x35f

workaround:

t.Gt(len(j.Get("merchants").Arr()), 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.