Giter VIP home page Giter VIP logo

gotests's People

Contributors

178inaba avatar alvinmatias69 avatar buoto avatar butuzov avatar codelingobot avatar costela avatar cweill avatar fluffglitter avatar itsjamie avatar jawher avatar mekegi avatar meyskens avatar morozov-5f avatar msoap avatar naofumi-fujii avatar s-kostyaev avatar shawnps avatar shihanng avatar xjs avatar zacatac avatar zaynjarvis avatar zchee 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  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

gotests's Issues

Support for specifying an expected error in the table

It would also be really useful if you could specify a specific error value that should be returned by a test, rather than the general wantErr.

For example extending #15's example

package main

import "fmt"

type S3Bucket struct {
    Name    string
    Storage map[string][]byte
}

func (s *S3Bucket) Save(name string, body []byte) error {
    if err := validateName(name); err != nil {
        return err
    }

    if err := validateBody(body); err != nil {
        return err
    }

    s.Storage[name] = body
    return nil
}

func validateName(name string) error {
    if len(name) == 0 {
        return fmt.Errorf("name must not be empty")
    }

    return nil
}

const MAX_BODY_SIZE = 1024

func validateBody(body []byte) error {
    if len(body) > MAX_BODY_SIZE {
        return fmt.Errorf("contents are too large (>%d bytes)", MAX_BODY_SIZE)
    }

    return nil
}

would produce:

func TestS3BucketSave(t *testing.T) {
    tests := []struct {
        name    string
        fname   string
        storage map[string][]byte
        pname   string
        body    []byte
        wantErr bool
    }{
    // TODO: Add test cases.
    }
    for _, tt := range tests {
        s := &S3Bucket{
            Name:    tt.fname,
            Storage: tt.storage,
        }
        if err := s.Save(tt.pname, tt.body); (err != nil) != tt.wantErr {
            t.Errorf("%q. S3Bucket.Save() error = %v, wantErr %v", tt.name, err, tt.wantErr)
        }
    }
}

It'd be nice if I could test for the different error cases :D

Error when current directory name ends with .go

If the name of the directory ends in .go, tests cannot be generated.

$ pwd
$GOPATH/src/github.com/scottjbarr/foo.go

$ gotests -all .
Parser.Parse source file: ioutil.ReadFile: read $GOPATH/src/github.com/scottjbarr/foo.go: is a directory

I've replaced the actual $GOPATH with $GOPATH

If the name of the directory is changed from "foo.go" to "foo", then test generation works as expected.

GoTests: GOPATH is not set.

I use go version go1.10 linux/amd64 and Sublime Text 3 on Manjaro Linux.

After installing this plugin I get GoTests: GOPATH is not set. on any try of creating test from context menu.

Why I get this message, if I set GOPATH correctly (for example, for GoSublime plugin)?

Generated tests for main func have syntax err

undefined: tt in tt.name.

func Test_main(t *testing.T) {
	tests := []struct {
		name string
	}{
	// TODO: Add test cases.
	}
	for range tests {
		t.Run(tt.name, func(t *testing.T) { // <-- tt is undefined
			main()
		})
	}
}

Index out of range when generating tests

When attempting to generate tests:

gotests -all -i -w .

I get the following panic:

panic: runtime error: index out of range

goroutine 19 [running]:
go/types.(*object).Name(...)
	/usr/local/Cellar/go/1.9.2/libexec/src/go/types/type.go:146
github.com/cweill/gotests/internal/goparser.parseReceiver(0xc4201979e0, 0xc4201e02d0, 0xc4201e0300, 0x14cdd20)
	/Users/simon/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:231 +0x430
github.com/cweill/gotests/internal/goparser.parseFunc(0xc420197fb0, 0xc4201e02d0, 0xc4201e0300, 0x1)
	/Users/simon/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:178 +0x9d
github.com/cweill/gotests/internal/goparser.(*Parser).parseFunctions(0xc420073ed0, 0xc4201a8840, 0xc4201be600, 0xc4201949a8, 0x1, 0x1, 0x43e9, 0x1, 0x1)
	/Users/simon/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:105 +0x108
github.com/cweill/gotests/internal/goparser.(*Parser).Parse(0xc420073ed0, 0xc4201e80c0, 0x51, 0xc42018e8b0, 0x1, 0x1, 0x10100f7, 0xc4201ac520, 0x20)
	/Users/simon/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:58 +0x2da
github.com/cweill/gotests.generateTest(0xc4201e80c0, 0x51, 0xc42018e8b0, 0x1, 0x1, 0xc42020c300, 0x0, 0xc420029fa0, 0x1111e70)
	/Users/simon/go/src/github.com/cweill/gotests/gotests.go:102 +0xba
github.com/cweill/gotests.parallelize.func1(0xc42019c1e0, 0xc42018e8b0, 0x1, 0x1, 0xc42020c300, 0xc4201f20c0, 0xc4201e80c0, 0x51)
	/Users/simon/go/src/github.com/cweill/gotests/gotests.go:74 +0xb7
created by github.com/cweill/gotests.parallelize
	/Users/simon/go/src/github.com/cweill/gotests/gotests.go:71 +0x125

Intellij Idea Plugin

Hi, it would be neat to see a plugin for the aforementioned added. Golang Plugin for Intellij has become quite mature overtime.

Thank you for this amazing work.

Issue installing gotests on vscode

Hello everyone. I have an issue trying to install gotests on my mac machine:
Steps:
Click the 'Analysis tool missing' option in the bottom right corner of vscode.
Installation begings:

Installing 1 tools
gotests

Installing gotests FAILED

1 tools failed to install.

gotests:
Error: Command failed: /usr/local/go/bin/go get -u -v github.com/cweill/gotests/...
github.com/cweill/gotests (download)
Fetching https://golang.org/x/tools/imports?go-get=1
Parsing meta tags from https://golang.org/x/tools/imports?go-get=1 (status code 200)
get "golang.org/x/tools/imports": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/imports?go-get=1
get "golang.org/x/tools/imports": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
Fetching https://golang.org/x/tools/go/ast/astutil?go-get=1
Parsing meta tags from https://golang.org/x/tools/go/ast/astutil?go-get=1 (status code 200)
get "golang.org/x/tools/go/ast/astutil": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/go/ast/astutil?go-get=1
get "golang.org/x/tools/go/ast/astutil": verifying non-authoritative meta tag
github.com/cweill/gotests/internal/render/bindata
golang.org/x/tools/imports
github.com/cweill/gotests/internal/render
github.com/cweill/gotests/internal/output
github.com/cweill/gotests
github.com/cweill/gotests/gotests/process
github.com/cweill/gotests/gotests

github.com/cweill/gotests/gotests

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x3ea0ccbb070c pc=0xf47b]

runtime stack:
runtime.throw(0x2c4900, 0x2a)
/usr/local/go/src/runtime/panic.go:547 +0x90
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.unlock(0x3a60a0)
/usr/local/go/src/runtime/lock_sema.go:107 +0x14b
runtime.(*mheap).alloc_m(0x3a60a0, 0x1, 0xf, 0xc820000180)
/usr/local/go/src/runtime/mheap.go:492 +0x314
runtime.(*mheap).alloc.func1()
/usr/local/go/src/runtime/mheap.go:502 +0x41
runtime.systemstack(0xc82048be58)
/usr/local/go/src/runtime/asm_amd64.s:307 +0xab
runtime.(*mheap).alloc(0x3a60a0, 0x1, 0x1000000000f, 0xf11f)
/usr/local/go/src/runtime/mheap.go:503 +0x63
runtime.(*mcentral).grow(0x3a7a00, 0x0)
/usr/local/go/src/runtime/mcentral.go:209 +0x93
runtime.(*mcentral).cacheSpan(0x3a7a00, 0x55b440)
/usr/local/go/src/runtime/mcentral.go:89 +0x47d
runtime.(*mcache).refill(0x4022c0, 0xc80000000f, 0x55b440)
/usr/local/go/src/runtime/mcache.go:119 +0xcc
runtime.mallocgc.func2()
/usr/local/go/src/runtime/malloc.go:642 +0x2b
runtime.systemstack(0xc820025500)
/usr/local/go/src/runtime/asm_amd64.s:291 +0x79
runtime.mstart()
/usr/local/go/src/runtime/proc.go:1051

goroutine 1 [running]:
runtime.systemstack_switch()
/usr/local/go/src/runtime/asm_amd64.s:245 fp=0xc82003ca38 sp=0xc82003ca30
runtime.mallocgc(0xe0, 0x2641c0, 0x0, 0x9d3)
/usr/local/go/src/runtime/malloc.go:643 +0x869 fp=0xc82003cb10 sp=0xc82003ca38
runtime.newobject(0x2641c0, 0xc820c711c0)
/usr/local/go/src/runtime/malloc.go:781 +0x42 fp=0xc82003cb38 sp=0xc82003cb10
cmd/link/internal/ld.readsym(0xc820082240, 0xc820c711c0, 0xc820936d70, 0x6, 0xc820d77680, 0x2f)
/usr/local/go/src/cmd/link/internal/ld/objfile.go:281 +0x13ba fp=0xc82003cf80 sp=0xc82003cb38
cmd/link/internal/ld.ldobjfile(0xc820082240, 0xc820c711c0, 0xc820936d70, 0x6, 0x73025, 0xc820d77680, 0x2f)
/usr/local/go/src/cmd/link/internal/ld/objfile.go:147 +0xa62 fp=0xc82003d190 sp=0xc82003cf80
cmd/link/internal/ld.ldobj(0xc820c711c0, 0xc820936d70, 0x6, 0x7304e, 0xc820d77680, 0x2f, 0xc82077df20, 0x27, 0x1, 0x0)
/usr/local/go/src/cmd/link/internal/ld/lib.go:1351 +0x1569 fp=0xc82003d400 sp=0xc82003d190
cmd/link/internal/ld.objfile(0xc820c95dc0)
/usr/local/go/src/cmd/link/internal/ld/lib.go:847 +0x10d9 fp=0xc82003d710 sp=0xc82003d400
cmd/link/internal/ld.loadlib()
/usr/local/go/src/cmd/link/internal/ld/lib.go:513 +0x5ce fp=0xc82003d9f0 sp=0xc82003d710
cmd/link/internal/ld.Ldmain()
/usr/local/go/src/cmd/link/internal/ld/pobj.go:214 +0x1cd3 fp=0xc82003de70 sp=0xc82003d9f0
cmd/link/internal/amd64.Main()
/usr/local/go/src/cmd/link/internal/amd64/obj.go:44 +0x19 fp=0xc82003de78 sp=0xc82003de70
main.main()
/usr/local/go/src/cmd/link/main.go:27 +0x36f fp=0xc82003df50 sp=0xc82003de78
runtime.main()
/usr/local/go/src/runtime/proc.go:188 +0x2b0 fp=0xc82003dfa0 sp=0xc82003df50
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82003dfa8 sp=0xc82003dfa0
github.com/cweill/gotests (download)
Fetching https://golang.org/x/tools/imports?go-get=1
Parsing meta tags from https://golang.org/x/tools/imports?go-get=1 (status code 200)
get "golang.org/x/tools/imports": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/imports?go-get=1
get "golang.org/x/tools/imports": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
Fetching https://golang.org/x/tools/go/ast/astutil?go-get=1
Parsing meta tags from https://golang.org/x/tools/go/ast/astutil?go-get=1 (status code 200)
get "golang.org/x/tools/go/ast/astutil": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/go/ast/astutil?go-get=1
get "golang.org/x/tools/go/ast/astutil": verifying non-authoritative meta tag
github.com/cweill/gotests/internal/render/bindata
golang.org/x/tools/imports
github.com/cweill/gotests/internal/render
github.com/cweill/gotests/internal/output
github.com/cweill/gotests
github.com/cweill/gotests/gotests/process
github.com/cweill/gotests/gotests

github.com/cweill/gotests/gotests

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x3ea0ccbb070c pc=0xf47b]

runtime stack:
runtime.throw(0x2c4900, 0x2a)
/usr/local/go/src/runtime/panic.go:547 +0x90
runtime.sigpanic()
/usr/local/go/src/runtime/sigpanic_unix.go:12 +0x5a
runtime.unlock(0x3a60a0)
/usr/local/go/src/runtime/lock_sema.go:107 +0x14b
runtime.(*mheap).alloc_m(0x3a60a0, 0x1, 0xf, 0xc820000180)
/usr/local/go/src/runtime/mheap.go:492 +0x314
runtime.(*mheap).alloc.func1()
/usr/local/go/src/runtime/mheap.go:502 +0x41
runtime.systemstack(0xc82048be58)
/usr/local/go/src/runtime/asm_amd64.s:307 +0xab
runtime.(*mheap).alloc(0x3a60a0, 0x1, 0x1000000000f, 0xf11f)
/usr/local/go/src/runtime/mheap.go:503 +0x63
runtime.(*mcentral).grow(0x3a7a00, 0x0)
/usr/local/go/src/runtime/mcentral.go:209 +0x93
runtime.(*mcentral).cacheSpan(0x3a7a00, 0x55b440)
/usr/local/go/src/runtime/mcentral.go:89 +0x47d
runtime.(*mcache).refill(0x4022c0, 0xc80000000f, 0x55b440)
/usr/local/go/src/runtime/mcache.go:119 +0xcc
runtime.mallocgc.func2()
/usr/local/go/src/runtime/malloc.go:642 +0x2b
runtime.systemstack(0xc820025500)
/usr/local/go/src/runtime/asm_amd64.s:291 +0x79
runtime.mstart()
/usr/local/go/src/runtime/proc.go:1051

goroutine 1 [running]:
runtime.systemstack_switch()
/usr/local/go/src/runtime/asm_amd64.s:245 fp=0xc82003ca38 sp=0xc82003ca30
runtime.mallocgc(0xe0, 0x2641c0, 0x0, 0x9d3)
/usr/local/go/src/runtime/malloc.go:643 +0x869 fp=0xc82003cb10 sp=0xc82003ca38
runtime.newobject(0x2641c0, 0xc820c711c0)
/usr/local/go/src/runtime/malloc.go:781 +0x42 fp=0xc82003cb38 sp=0xc82003cb10
cmd/link/internal/ld.readsym(0xc820082240, 0xc820c711c0, 0xc820936d70, 0x6, 0xc820d77680, 0x2f)
/usr/local/go/src/cmd/link/internal/ld/objfile.go:281 +0x13ba fp=0xc82003cf80 sp=0xc82003cb38
cmd/link/internal/ld.ldobjfile(0xc820082240, 0xc820c711c0, 0xc820936d70, 0x6, 0x73025, 0xc820d77680, 0x2f)
/usr/local/go/src/cmd/link/internal/ld/objfile.go:147 +0xa62 fp=0xc82003d190 sp=0xc82003cf80
cmd/link/internal/ld.ldobj(0xc820c711c0, 0xc820936d70, 0x6, 0x7304e, 0xc820d77680, 0x2f, 0xc82077df20, 0x27, 0x1, 0x0)
/usr/local/go/src/cmd/link/internal/ld/lib.go:1351 +0x1569 fp=0xc82003d400 sp=0xc82003d190
cmd/link/internal/ld.objfile(0xc820c95dc0)
/usr/local/go/src/cmd/link/internal/ld/lib.go:847 +0x10d9 fp=0xc82003d710 sp=0xc82003d400
cmd/link/internal/ld.loadlib()
/usr/local/go/src/cmd/link/internal/ld/lib.go:513 +0x5ce fp=0xc82003d9f0 sp=0xc82003d710
cmd/link/internal/ld.Ldmain()
/usr/local/go/src/cmd/link/internal/ld/pobj.go:214 +0x1cd3 fp=0xc82003de70 sp=0xc82003d9f0
cmd/link/internal/amd64.Main()
/usr/local/go/src/cmd/link/internal/amd64/obj.go:44 +0x19 fp=0xc82003de78 sp=0xc82003de70
main.main()
/usr/local/go/src/cmd/link/main.go:27 +0x36f fp=0xc82003df50 sp=0xc82003de78
runtime.main()
/usr/local/go/src/runtime/proc.go:188 +0x2b0 fp=0xc82003dfa0 sp=0xc82003df50
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc82003dfa8 sp=0xc82003dfa0

gotests will removed license header & Neovim integration

Hi,
Thanks for good tools, I always use it when writing tests.

And, I am developing gotests Neovim integration on the zchee/nvim-go. Thanks again.


BTW, gotests will remove license header if already exists *_test.go file.
I thought doing pull request, but maybe reads the gotests code seemed to take a while, so I wanted to hear it first.
Do you have any idea?

like,

before code:

  • foo.go
// Copyright 2016 Koichi Shiraishi. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package foo

import "fmt"

func Foo(bar string) string {
	return fmt.Sprint(bar)
}
  • foo_test.go
// Copyright 2016 Koichi Shiraishi. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package foo

import "testing"

func TestFoo(t *testing.T) {
	type args struct {
		bar string
	}
	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "foo test",
			args: args{bar: "barbar"},
			want: "barbar",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := Foo(tt.args.bar); got != tt.want {
				t.Errorf("Foo() = %v, want %v", got, tt.want)
			}
		})
	}
}

After that, adding Baz function to foo.go.

after code:

  • foo.go
// Copyright 2016 Koichi Shiraishi. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package foo

import "fmt"

func Foo(bar string) string {
	return fmt.Sprint(bar)
}

func Baz(i int) string {
	return strconv.Atoi(i)
}

run the gotests -all -w foo.go.
generated and auto-inserted foo_test.go code will removed license header.

  • foo_test.go
package foo

import "testing"

func TestFoo(t *testing.T) {
	type args struct {
		bar string
	}
	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "foo test",
			args: args{bar: "barbar"},
			want: "barbar",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := Foo(tt.args.bar); got != tt.want {
				t.Errorf("Foo() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestBaz(t *testing.T) {
	type args struct {
		i int
	}
	tests := []struct {
		name string
		args args
		want string
	}{
	// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := Baz(tt.args.i); got != tt.want {
				t.Errorf("Baz() = %v, want %v", got, tt.want)
			}
		})
	}
}

Imports from tests files bunched incorrectly

This only happens when a test file already exists and has several non-stdlib imports. When gotests outputs new tests to the file, the imports get bunched together incorrectly.

gotests version

Please implement gotests -version or th short -v to see the version of gotests package

tks
joao

generate tests failing after upgraded to go1.7

Hi,
I'm getting the below error while generating tests after upgraded to go1.7. If anything is missing, please help..

panic: inconsistent import:
func errors.New(text string) error
previously imported as:
func errors.New(text string) error
[recovered]
panic: inconsistent import:
func errors.New(text string) error
previously imported as:
func errors.New(text string) error

goroutine 34 [running]:
panic(0x28f460, 0xc4204c94c0)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
go/types.(_Checker).handleBailout(0xc4202861c0, 0xc4202f5a18)
/usr/local/go/src/go/types/check.go:213 +0xae
panic(0x28f460, 0xc4204c94c0)
/usr/local/go/src/runtime/panic.go:458 +0x243
go/internal/gcimporter.(_importer).declare(0xc42036f380, 0x49aba0, 0xc4204fdf90)
/usr/local/go/src/go/internal/gcimporter/bimport.go:175 +0x17c
go/internal/gcimporter.(_importer).obj(0xc42036f380, 0xfffffffffffffffb)
/usr/local/go/src/go/internal/gcimporter/bimport.go:203 +0x4a2
go/internal/gcimporter.BImportData(0xc420268690, 0xc4204a9000, 0xb51, 0xe00, 0xc4202ec999, 0x6, 0x0, 0x6, 0xc42005c820, 0xc42005c8f0)
/usr/local/go/src/go/internal/gcimporter/bimport.go:88 +0x390
go/internal/gcimporter.Import(0xc420268690, 0xc4202ec999, 0x6, 0xc420288180, 0x3f, 0xc420146a00, 0x0, 0x0)
/usr/local/go/src/go/internal/gcimporter/gcimporter.go:166 +0x551
go/importer.gcimports.ImportFrom(0xc420268690, 0xc4202ec999, 0x6, 0xc420288180, 0x3f, 0x0, 0x1, 0x2, 0x0)
/usr/local/go/src/go/importer/importer.go:70 +0x67
go/types.(_Checker).collectObjects(0xc4202861c0)
/usr/local/go/src/go/types/resolver.go:191 +0x826
go/types.(_Checker).checkFiles(0xc4202861c0, 0xc4204b6300, 0x16, 0x20, 0x0, 0x0)
/usr/local/go/src/go/types/check.go:225 +0xaa
go/types.(_Checker).Files(0xc4202861c0, 0xc4204b6300, 0x16, 0x20, 0xc4204d0b70, 0xc4202f5a90)
/usr/local/go/src/go/types/check.go:218 +0x49
go/types.(_Config).Check(0xc4204cdac0, 0x0, 0x0, 0xc42007f040, 0xc4204b6300, 0x16, 0x20, 0xc4204d4320, 0x0, 0x3, ...)
/usr/local/go/src/go/types/api.go:344 +0x1a3
github.com/cweill/gotests/internal/goparser.(_Parser).parseTypes(0xc4202f5eb8, 0xc42007f040, 0xc4204b6300, 0x16, 0x20, 0xc4204a1e00, 0x8)
/Users/cfs426/workspace/src/github.com/cweill/gotests/internal/goparser/goparser.go:119 +0x18c
github.com/cweill/gotests/internal/goparser.(_Parser).parseFunctions(0xc4202f5eb8, 0xc42007f040, 0xc4200b1080, 0xc4204b6300, 0x16, 0x20, 0x1e98, 0x16, 0x20)
/Users/cfs426/workspace/src/github.com/cweill/gotests/internal/goparser/goparser.go:96 +0x74
github.com/cweill/gotests/internal/goparser.(_Parser).Parse(0xc4202f5eb8, 0xc4202880c0, 0x5b, 0xc42025a600, 0x16, 0x20, 0xc420070d80, 0x20, 0x18)
/Users/cfs426/workspace/src/github.com/cweill/gotests/internal/goparser/goparser.go:56 +0x2b9
github.com/cweill/gotests.generateTest(0xc4202880c0, 0x5b, 0xc42025a600, 0x16, 0x20, 0xc420230880, 0x0, 0x0, 0x0)
/Users/cfs426/workspace/src/github.com/cweill/gotests/gotests.go:100 +0xc3
github.com/cweill/gotests.parallelize.func1(0xc42022a730, 0xc42025a600, 0x16, 0x20, 0xc420230880, 0xc4202896e0, 0xc4202880c0, 0x5b)
/Users/cfs426/workspace/src/github.com/cweill/gotests/gotests.go:72 +0xd0
created by github.com/cweill/gotests.parallelize
/Users/cfs426/workspace/src/github.com/cweill/gotests/gotests.go:74 +0x140

Go 1.6 not working on Travis CI

Something to do with package context: unrecognized import path "context" (import path does not begin with hostname).
Log:

travis_fold:start:worker_info
�[0K�[33;1mWorker information�[0m
hostname: 1ebbd0fe-5dd2-4319-a0d2-6d0e8f72bd9b@1.i-026a53a-production-2-worker-org-ec2.travisci.net
version: v3.6.0 https://github.com/travis-ci/worker/tree/170b2a0bb43234479fd1911ba9e4dbcc36dadfad
instance: d27b0d6 travisci/ci-garnet:packer-1512502276-986baf0 (via amqp)
startup: 594.251218ms
travis_fold:end:worker_info
�[0Ktravis_fold:start:system_info
�[0K�[33;1mBuild system information�[0m
Build language: go
Build group: stable
Build dist: trusty
Build id: 381349461
Job id: 381349462
Runtime kernel version: 4.14.12-041412-generic
travis-build version: 4957953b8
�[34m�[1mBuild image provisioning date and time�[0m
Tue Dec  5 20:11:19 UTC 2017
�[34m�[1mOperating System Details�[0m
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.5 LTS
Release:	14.04
Codename:	trusty
�[34m�[1mCookbooks Version�[0m
7c2c6a6 https://github.com/travis-ci/travis-cookbooks/tree/7c2c6a6
�[34m�[1mgit version�[0m
git version 2.15.1
�[34m�[1mbash version�[0m
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
�[34m�[1mgcc version�[0m
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

�[34m�[1mdocker version�[0m
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:39:28 2017
 OS/Arch:      linux/amd64
�[34m�[1mclang version�[0m
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-5.0.0/bin
�[34m�[1mjq version�[0m
jq-1.5
�[34m�[1mbats version�[0m
Bats 0.4.0
�[34m�[1mshellcheck version�[0m
0.4.6
�[34m�[1mshfmt version�[0m
v2.0.0
�[34m�[1mccache version�[0m
ccache version 3.1.9

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2011 Joel Rosdahl

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.
�[34m�[1mcmake version�[0m
cmake version 3.9.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
�[34m�[1mheroku version�[0m
heroku-cli/6.14.39-addc925 (linux-x64) node-v9.2.0
�[34m�[1mimagemagick version�[0m
Version: ImageMagick 6.7.7-10 2017-07-31 Q16 http://www.imagemagick.org
�[34m�[1mmd5deep version�[0m
4.2
�[34m�[1mmercurial version�[0m
Mercurial Distributed SCM (version 4.2.2)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2017 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
�[34m�[1mmysql version�[0m
mysql  Ver 14.14 Distrib 5.6.33, for debian-linux-gnu (x86_64) using  EditLine wrapper
�[34m�[1mopenssl version�[0m
OpenSSL 1.0.1f 6 Jan 2014
�[34m�[1mpacker version�[0m
Packer v1.0.2

Your version of Packer is out of date! The latest version
is 1.1.2. You can update by downloading from www.packer.io
�[34m�[1mpostgresql client version�[0m
psql (PostgreSQL) 9.6.6
�[34m�[1mragel version�[0m
Ragel State Machine Compiler version 6.8 Feb 2013
Copyright (c) 2001-2009 by Adrian Thurston
�[34m�[1msubversion version�[0m
svn, version 1.8.8 (r1568071)
   compiled Aug 10 2017, 17:20:39 on x86_64-pc-linux-gnu

Copyright (C) 2013 The Apache Software Foundation.
This software consists of contributions made by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository access (RA) modules are available:

* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - using serf 1.3.3
  - handles 'http' scheme
  - handles 'https' scheme

�[34m�[1msudo version�[0m
Sudo version 1.8.9p5
Configure options: --prefix=/usr -v --with-all-insults --with-pam --with-fqdn --with-logging=syslog --with-logfac=authpriv --with-env-editor --with-editor=/usr/bin/editor --with-timeout=15 --with-password-timeout=0 --with-passprompt=[sudo] password for %p:  --without-lecture --with-tty-tickets --disable-root-mailer --enable-admin-flag --with-sendmail=/usr/sbin/sendmail --with-timedir=/var/lib/sudo --mandir=/usr/share/man --libexecdir=/usr/lib/sudo --with-sssd --with-sssd-lib=/usr/lib/x86_64-linux-gnu --with-selinux
Sudoers policy plugin version 1.8.9p5
Sudoers file grammar version 43

Sudoers path: /etc/sudoers
Authentication methods: 'pam'
Syslog facility if syslog is being used for logging: authpriv
Syslog priority to use when user authenticates successfully: notice
Syslog priority to use when user authenticates unsuccessfully: alert
Send mail if the user is not in sudoers
Use a separate timestamp for each user/tty combo
Lecture user the first time they run sudo
Root may run sudo
Allow some information gathering to give useful error messages
Require fully-qualified hostnames in the sudoers file
Visudo will honor the EDITOR environment variable
Set the LOGNAME and USER environment variables
Length at which to wrap log file lines (0 for no wrap): 80
Authentication timestamp timeout: 15.0 minutes
Password prompt timeout: 0.0 minutes
Number of tries to enter a password: 3
Umask to use or 0777 to use user's: 022
Path to mail program: /usr/sbin/sendmail
Flags for mail program: -t
Address to send mail to: root
Subject line for mail messages: *** SECURITY information for %h ***
Incorrect password message: Sorry, try again.
Path to authentication timestamp dir: /var/lib/sudo
Default password prompt: [sudo] password for %p: 
Default user to run commands as: root
Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
Path to the editor for use by visudo: /usr/bin/editor
When to require a password for 'list' pseudocommand: any
When to require a password for 'verify' pseudocommand: all
File descriptors >= 3 will be closed before executing a command
Environment variables to check for sanity:
	TZ
	TERM
	LINGUAS
	LC_*
	LANGUAGE
	LANG
	COLORTERM
Environment variables to remove:
	RUBYOPT
	RUBYLIB
	PYTHONUSERBASE
	PYTHONINSPECT
	PYTHONPATH
	PYTHONHOME
	TMPPREFIX
	ZDOTDIR
	READNULLCMD
	NULLCMD
	FPATH
	PERL5DB
	PERL5OPT
	PERL5LIB
	PERLLIB
	PERLIO_DEBUG 
	JAVA_TOOL_OPTIONS
	SHELLOPTS
	GLOBIGNORE
	PS4
	BASH_ENV
	ENV
	TERMCAP
	TERMPATH
	TERMINFO_DIRS
	TERMINFO
	_RLD*
	LD_*
	PATH_LOCALE
	NLSPATH
	HOSTALIASES
	RES_OPTIONS
	LOCALDOMAIN
	CDPATH
	IFS
Environment variables to preserve:
	JAVA_HOME
	TRAVIS
	CI
	DEBIAN_FRONTEND
	XAUTHORIZATION
	XAUTHORITY
	PS2
	PS1
	PATH
	LS_COLORS
	KRB5CCNAME
	HOSTNAME
	HOME
	DISPLAY
	COLORS
Locale to use while parsing sudoers: C
Directory in which to store input/output logs: /var/log/sudo-io
File in which to store the input/output log: %{seq}
Add an entry to the utmp/utmpx file when allocating a pty
PAM service name to use
PAM service name to use for login shells
Create a new PAM session for the command to run in
Maximum I/O log sequence number: 0

Local IP address and netmask pairs:
	172.17.0.2/255.255.0.0

Sudoers I/O plugin version 1.8.9p5
�[34m�[1mgzip version�[0m
gzip 1.6
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.
�[34m�[1mzip version�[0m
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.
Currently maintained by E. Gordon.  Please send bug reports to
the authors using the web page at www.info-zip.org; see README for details.

Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,
as of above date; see http://www.info-zip.org/ for other sites.

Compiled with gcc 4.8.2 for Unix (Linux ELF) on Oct 21 2013.

Zip special compilation options:
	USE_EF_UT_TIME       (store Universal Time)
	BZIP2_SUPPORT        (bzip2 library version 1.0.6, 6-Sept-2010)
	    bzip2 code and library copyright (c) Julian R Seward
	    (See the bzip2 license for terms of use)
	SYMLINK_SUPPORT      (symbolic links supported)
	LARGE_FILE_SUPPORT   (can read and write large files on file system)
	ZIP64_SUPPORT        (use Zip64 to store large files in archives)
	UNICODE_SUPPORT      (store and read UTF-8 Unicode paths)
	STORE_UNIX_UIDs_GIDs (store UID/GID sizes/values using new extra field)
	UIDGID_NOT_16BIT     (old Unix 16-bit UID/GID extra field not used)
	[encryption, version 2.91 of 05 Jan 2007] (modified for Zip 3)

Encryption notice:
	The encryption code of this program is not copyrighted and is
	put in the public domain.  It was originally written in Europe
	and, to the best of our knowledge, can be freely distributed
	in both source and object forms from any country, including
	the USA under License Exception TSU of the U.S. Export
	Administration Regulations (section 740.13(e)) of 6 June 2002.

Zip environment options:
             ZIP:  [none]
          ZIPOPT:  [none]
�[34m�[1mvim version�[0m
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2016 16:43:18)
Included patches: 1-52
Extra patches: 8.0.0056
Modified by [email protected]
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions      
�[34m�[1miptables version�[0m
iptables v1.4.21
�[34m�[1mcurl version�[0m
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
�[34m�[1mwget version�[0m
GNU Wget 1.15 built on linux-gnu.
�[34m�[1mrsync version�[0m
rsync  version 3.1.0  protocol version 31
�[34m�[1mgimme version�[0m
v1.2.0
�[34m�[1mnvm version�[0m
0.33.6
�[34m�[1mperlbrew version�[0m
/home/travis/perl5/perlbrew/bin/perlbrew  - App::perlbrew/0.80
�[34m�[1mphpenv version�[0m
rbenv 1.1.1-25-g6aa70b6
�[34m�[1mrvm version�[0m
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
�[34m�[1mdefault ruby version�[0m
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
�[34m�[1mCouchDB version�[0m
couchdb 1.6.1
�[34m�[1mElasticSearch version�[0m
5.5.0
�[34m�[1mInstalled Firefox version�[0m
firefox 56.0.2
�[34m�[1mMongoDB version�[0m
MongoDB 3.4.10
�[34m�[1mPhantomJS version�[0m
2.1.1
�[34m�[1mPre-installed PostgreSQL versions�[0m
9.2.24
9.3.20
9.4.15
9.5.10
9.6.6
�[34m�[1mRabbitMQ Version�[0m
3.6.14
�[34m�[1mRedis version�[0m
redis-server 4.0.6
�[34m�[1mriak version�[0m
2.2.3
�[34m�[1mPre-installed Go versions�[0m
1.7.4
�[34m�[1mant version�[0m
Apache Ant(TM) version 1.9.3 compiled on April 8 2014
�[34m�[1mmvn version�[0m
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)
Maven home: /usr/local/maven-3.5.2
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-101-generic", arch: "amd64", family: "unix"
�[34m�[1mgradle version�[0m

------------------------------------------------------------
Gradle 4.0.1
------------------------------------------------------------

Build time:   2017-07-07 14:02:41 UTC
Revision:     38e5dc0f772daecca1d2681885d3d85414eb6826

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_151 (Oracle Corporation 25.151-b12)
OS:           Linux 4.4.0-101-generic amd64

�[34m�[1mlein version�[0m
Leiningen 2.8.1 on Java 1.8.0_151 Java HotSpot(TM) 64-Bit Server VM
�[34m�[1mPre-installed Node.js versions�[0m
v4.8.6
v6.12.0
v6.12.1
v8.9
v8.9.1
�[34m�[1mphpenv versions�[0m
  system
  5.6
* 5.6.32 (set by /home/travis/.phpenv/version)
  7.0
  7.0.25
  7.1
  7.1.11
  hhvm
  hhvm-stable
�[34m�[1mcomposer --version�[0m
Composer version 1.5.2 2017-09-11 16:59:25
�[34m�[1mPre-installed Ruby versions�[0m
ruby-2.2.7
ruby-2.3.4
ruby-2.4.1
travis_fold:end:system_info
�[0K
�[32;1mNetwork availability confirmed.�[0m

�[33;1mRunning apt-get update by default has been disabled.�[0m
You can opt into running apt-get update by setting this in your .travis.yml file:

  addons:
    apt:
      update: true

travis_fold:start:git.checkout
�[0Ktravis_time:start:07b3fdf8
�[0K$ git clone --depth=50 --branch=master https://github.com/cweill/gotests.git cweill/gotests
Cloning into 'cweill/gotests'...
remote: Counting objects: 695, done.�[K
remote: Compressing objects:   0% (1/278)   �[K
remote: Compressing objects:   1% (3/278)   �[K
remote: Compressing objects:   2% (6/278)   �[K
remote: Compressing objects:   3% (9/278)   �[K
remote: Compressing objects:   4% (12/278)   �[K
remote: Compressing objects:   5% (14/278)   �[K
remote: Compressing objects:   6% (17/278)   �[K
remote: Compressing objects:   7% (20/278)   �[K
remote: Compressing objects:   8% (23/278)   �[K
remote: Compressing objects:   9% (26/278)   �[K
remote: Compressing objects:  10% (28/278)   �[K
remote: Compressing objects:  11% (31/278)   �[K
remote: Compressing objects:  12% (34/278)   �[K
remote: Compressing objects:  13% (37/278)   �[K
remote: Compressing objects:  14% (39/278)   �[K
remote: Compressing objects:  15% (42/278)   �[K
remote: Compressing objects:  16% (45/278)   �[K
remote: Compressing objects:  17% (48/278)   �[K
remote: Compressing objects:  18% (51/278)   �[K
remote: Compressing objects:  19% (53/278)   �[K
remote: Compressing objects:  20% (56/278)   �[K
remote: Compressing objects:  21% (59/278)   �[K
remote: Compressing objects:  22% (62/278)   �[K
remote: Compressing objects:  23% (64/278)   �[K
remote: Compressing objects:  24% (67/278)   �[K
remote: Compressing objects:  25% (70/278)   �[K
remote: Compressing objects:  26% (73/278)   �[K
remote: Compressing objects:  27% (76/278)   �[K
remote: Compressing objects:  28% (78/278)   �[K
remote: Compressing objects:  29% (81/278)   �[K
remote: Compressing objects:  30% (84/278)   �[K
remote: Compressing objects:  31% (87/278)   �[K
remote: Compressing objects:  32% (89/278)   �[K
remote: Compressing objects:  33% (92/278)   �[K
remote: Compressing objects:  34% (95/278)   �[K
remote: Compressing objects:  35% (98/278)   �[K
remote: Compressing objects:  36% (101/278)   �[K
remote: Compressing objects:  37% (103/278)   �[K
remote: Compressing objects:  38% (106/278)   �[K
remote: Compressing objects:  39% (109/278)   �[K
remote: Compressing objects:  40% (112/278)   �[K
remote: Compressing objects:  41% (114/278)   �[K
remote: Compressing objects:  42% (117/278)   �[K
remote: Compressing objects:  43% (120/278)   �[K
remote: Compressing objects:  44% (123/278)   �[K
remote: Compressing objects:  45% (126/278)   �[K
remote: Compressing objects:  46% (128/278)   �[K
remote: Compressing objects:  47% (131/278)   �[K
remote: Compressing objects:  48% (134/278)   �[K
remote: Compressing objects:  49% (137/278)   �[K
remote: Compressing objects:  50% (139/278)   �[K
remote: Compressing objects:  51% (142/278)   �[K
remote: Compressing objects:  52% (145/278)   �[K
remote: Compressing objects:  53% (148/278)   �[K
remote: Compressing objects:  54% (151/278)   �[K
remote: Compressing objects:  55% (153/278)   �[K
remote: Compressing objects:  56% (156/278)   �[K
remote: Compressing objects:  57% (159/278)   �[K
remote: Compressing objects:  58% (162/278)   �[K
remote: Compressing objects:  59% (165/278)   �[K
remote: Compressing objects:  60% (167/278)   �[K
remote: Compressing objects:  61% (170/278)   �[K
remote: Compressing objects:  62% (173/278)   �[K
remote: Compressing objects:  63% (176/278)   �[K
remote: Compressing objects:  64% (178/278)   �[K
remote: Compressing objects:  65% (181/278)   �[K
remote: Compressing objects:  66% (184/278)   �[K
remote: Compressing objects:  67% (187/278)   �[K
remote: Compressing objects:  68% (190/278)   �[K
remote: Compressing objects:  69% (192/278)   �[K
remote: Compressing objects:  70% (195/278)   �[K
remote: Compressing objects:  71% (198/278)   �[K
remote: Compressing objects:  72% (201/278)   �[K
remote: Compressing objects:  73% (203/278)   �[K
remote: Compressing objects:  74% (206/278)   �[K
remote: Compressing objects:  75% (209/278)   �[K
remote: Compressing objects:  76% (212/278)   �[K
remote: Compressing objects:  77% (215/278)   �[K
remote: Compressing objects:  78% (217/278)   �[K
remote: Compressing objects:  79% (220/278)   �[K
remote: Compressing objects:  80% (223/278)   �[K
remote: Compressing objects:  81% (226/278)   �[K
remote: Compressing objects:  82% (228/278)   �[K
remote: Compressing objects:  83% (231/278)   �[K
remote: Compressing objects:  84% (234/278)   �[K
remote: Compressing objects:  85% (237/278)   �[K
remote: Compressing objects:  86% (240/278)   �[K
remote: Compressing objects:  87% (242/278)   �[K
remote: Compressing objects:  88% (245/278)   �[K
remote: Compressing objects:  89% (248/278)   �[K
remote: Compressing objects:  90% (251/278)   �[K
remote: Compressing objects:  91% (253/278)   �[K
remote: Compressing objects:  92% (256/278)   �[K
remote: Compressing objects:  93% (259/278)   �[K
remote: Compressing objects:  94% (262/278)   �[K
remote: Compressing objects:  95% (265/278)   �[K
remote: Compressing objects:  96% (267/278)   �[K
remote: Compressing objects:  97% (270/278)   �[K
remote: Compressing objects:  98% (273/278)   �[K
remote: Compressing objects:  99% (276/278)   �[K
remote: Compressing objects: 100% (278/278)   �[K
remote: Compressing objects: 100% (278/278), done.�[K
Receiving objects:   0% (1/695)   
Receiving objects:   1% (7/695)   
Receiving objects:   2% (14/695)   
Receiving objects:   3% (21/695)   
Receiving objects:   4% (28/695)   
Receiving objects:   5% (35/695)   
Receiving objects:   6% (42/695)   
Receiving objects:   7% (49/695)   
Receiving objects:   8% (56/695)   
Receiving objects:   9% (63/695)   
Receiving objects:  10% (70/695)   
Receiving objects:  11% (77/695)   
Receiving objects:  12% (84/695)   
Receiving objects:  13% (91/695)   
Receiving objects:  14% (98/695)   
Receiving objects:  15% (105/695)   
Receiving objects:  16% (112/695)   
Receiving objects:  17% (119/695)   
Receiving objects:  18% (126/695)   
Receiving objects:  19% (133/695)   
Receiving objects:  20% (139/695)   
Receiving objects:  21% (146/695)   
Receiving objects:  22% (153/695)   
Receiving objects:  23% (160/695)   
Receiving objects:  24% (167/695)   
Receiving objects:  25% (174/695)   
Receiving objects:  26% (181/695)   
Receiving objects:  27% (188/695)   
Receiving objects:  28% (195/695)   
Receiving objects:  29% (202/695)   
Receiving objects:  30% (209/695)   
Receiving objects:  31% (216/695)   
Receiving objects:  32% (223/695)   
Receiving objects:  33% (230/695)   
Receiving objects:  34% (237/695)   
Receiving objects:  35% (244/695)   
Receiving objects:  36% (251/695)   
Receiving objects:  37% (258/695)   
Receiving objects:  38% (265/695)   
Receiving objects:  39% (272/695)   
Receiving objects:  40% (278/695)   
Receiving objects:  41% (285/695)   
Receiving objects:  42% (292/695)   
Receiving objects:  43% (299/695)   
Receiving objects:  44% (306/695)   
Receiving objects:  45% (313/695)   
Receiving objects:  46% (320/695)   
Receiving objects:  47% (327/695)   
Receiving objects:  48% (334/695)   
Receiving objects:  49% (341/695)   
Receiving objects:  50% (348/695)   
Receiving objects:  51% (355/695)   
Receiving objects:  52% (362/695)   
Receiving objects:  53% (369/695)   
Receiving objects:  54% (376/695)   
Receiving objects:  55% (383/695)   
Receiving objects:  56% (390/695)   
Receiving objects:  57% (397/695)   
Receiving objects:  58% (404/695)   
Receiving objects:  59% (411/695)   
Receiving objects:  60% (417/695)   
Receiving objects:  61% (424/695)   
Receiving objects:  62% (431/695)   
Receiving objects:  63% (438/695)   
Receiving objects:  64% (445/695)   
Receiving objects:  65% (452/695)   
Receiving objects:  66% (459/695)   
Receiving objects:  67% (466/695)   
Receiving objects:  68% (473/695)   
remote: Total 695 (delta 391), reused 660 (delta 375), pack-reused 0�[K
Receiving objects:  69% (480/695)   
Receiving objects:  70% (487/695)   
Receiving objects:  71% (494/695)   
Receiving objects:  72% (501/695)   
Receiving objects:  73% (508/695)   
Receiving objects:  74% (515/695)   
Receiving objects:  75% (522/695)   
Receiving objects:  76% (529/695)   
Receiving objects:  77% (536/695)   
Receiving objects:  78% (543/695)   
Receiving objects:  79% (550/695)   
Receiving objects:  80% (556/695)   
Receiving objects:  81% (563/695)   
Receiving objects:  82% (570/695)   
Receiving objects:  83% (577/695)   
Receiving objects:  84% (584/695)   
Receiving objects:  85% (591/695)   
Receiving objects:  86% (598/695)   
Receiving objects:  87% (605/695)   
Receiving objects:  88% (612/695)   
Receiving objects:  89% (619/695)   
Receiving objects:  90% (626/695)   
Receiving objects:  91% (633/695)   
Receiving objects:  92% (640/695)   
Receiving objects:  93% (647/695)   
Receiving objects:  94% (654/695)   
Receiving objects:  95% (661/695)   
Receiving objects:  96% (668/695)   
Receiving objects:  97% (675/695)   
Receiving objects:  98% (682/695)   
Receiving objects:  99% (689/695)   
Receiving objects: 100% (695/695)   
Receiving objects: 100% (695/695), 156.47 KiB | 17.38 MiB/s, done.
Resolving deltas:   0% (0/391)   
Resolving deltas:   1% (4/391)   
Resolving deltas:   2% (8/391)   
Resolving deltas:   6% (25/391)   
Resolving deltas:   7% (28/391)   
Resolving deltas:  11% (45/391)   
Resolving deltas:  12% (47/391)   
Resolving deltas:  13% (51/391)   
Resolving deltas:  14% (55/391)   
Resolving deltas:  15% (60/391)   
Resolving deltas:  16% (65/391)   
Resolving deltas:  20% (80/391)   
Resolving deltas:  21% (84/391)   
Resolving deltas:  25% (98/391)   
Resolving deltas:  29% (114/391)   
Resolving deltas:  31% (123/391)   
Resolving deltas:  32% (129/391)   
Resolving deltas:  33% (130/391)   
Resolving deltas:  34% (136/391)   
Resolving deltas:  35% (137/391)   
Resolving deltas:  39% (155/391)   
Resolving deltas:  40% (160/391)   
Resolving deltas:  42% (166/391)   
Resolving deltas:  43% (170/391)   
Resolving deltas:  44% (173/391)   
Resolving deltas:  47% (186/391)   
Resolving deltas:  48% (191/391)   
Resolving deltas:  49% (193/391)   
Resolving deltas:  50% (198/391)   
Resolving deltas:  51% (200/391)   
Resolving deltas:  53% (211/391)   
Resolving deltas:  55% (217/391)   
Resolving deltas:  58% (228/391)   
Resolving deltas:  59% (231/391)   
Resolving deltas:  62% (245/391)   
Resolving deltas:  64% (251/391)   
Resolving deltas:  68% (267/391)   
Resolving deltas:  69% (272/391)   
Resolving deltas:  70% (274/391)   
Resolving deltas:  71% (281/391)   
Resolving deltas:  72% (282/391)   
Resolving deltas:  73% (288/391)   
Resolving deltas:  76% (298/391)   
Resolving deltas:  78% (306/391)   
Resolving deltas:  80% (315/391)   
Resolving deltas:  82% (321/391)   
Resolving deltas:  84% (329/391)   
Resolving deltas:  86% (339/391)   
Resolving deltas:  87% (342/391)   
Resolving deltas:  88% (347/391)   
Resolving deltas:  89% (350/391)   
Resolving deltas:  90% (352/391)   
Resolving deltas:  92% (363/391)   
Resolving deltas:  93% (367/391)   
Resolving deltas:  94% (368/391)   
Resolving deltas:  95% (372/391)   
Resolving deltas:  96% (377/391)   
Resolving deltas:  97% (381/391)   
Resolving deltas:  98% (385/391)   
Resolving deltas: 100% (391/391)   
Resolving deltas: 100% (391/391), done.

travis_time:end:07b3fdf8:start=1526830952431775006,finish=1526830952793910436,duration=362135430
�[0K$ cd cweill/gotests
$ git checkout -qf 609a90ace9dda3f618dc6e6b5f2c50233e0109e6
travis_fold:end:git.checkout
�[0K�[33;1mUpdating gimme�[0m
travis_time:start:2be4534f
�[0K$ GIMME_OUTPUT="$(gimme 1.6.4 | tee -a $HOME/.bashrc)" && eval "$GIMME_OUTPUT"
go version go1.6.4 linux/amd64

travis_time:end:2be4534f:start=1526830964533009069,finish=1526830968278255160,duration=3745246091
�[0K$ export GOPATH=$HOME/gopath
$ export PATH=$HOME/gopath/bin:$PATH
$ mkdir -p $HOME/gopath/src/github.com/cweill/gotests
$ rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/cweill/gotests/
$ export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/cweill/gotests
$ cd $HOME/gopath/src/github.com/cweill/gotests
travis_time:start:10fbaa3e
�[0K
travis_time:end:10fbaa3e:start=1526830968404755887,finish=1526830968413747256,duration=8991369
�[0K$ gimme version
v1.3.0
$ go version
go version go1.6.4 linux/amd64
travis_fold:start:go.env
�[0K$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/travis/gopath"
GORACE=""
GOROOT="/home/travis/.gimme/versions/go1.6.4.linux.amd64"
GOTOOLDIR="/home/travis/.gimme/versions/go1.6.4.linux.amd64/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
travis_fold:end:go.env
�[0Ktravis_fold:start:before_install.1
�[0Ktravis_time:start:3261ca53
�[0K$ go get github.com/mattn/goveralls

travis_time:end:3261ca53:start=1526830968451927107,finish=1526830972029609695,duration=3577682588
�[0Ktravis_fold:end:before_install.1
�[0Ktravis_fold:start:before_install.2
�[0Ktravis_time:start:00ca2058
�[0K$ if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
package github.com/golang/tools/cmd/cover: code in directory /home/travis/gopath/src/github.com/golang/tools/cmd/cover expects import "golang.org/x/tools/cmd/cover"

travis_time:end:00ca2058:start=1526830972034949415,finish=1526830974417023076,duration=2382073661
�[0Ktravis_fold:end:before_install.2
�[0KUsing Go 1.5 Vendoring, not checking for Godeps
travis_fold:start:install
�[0Ktravis_time:start:0036d8f0
�[0K$ go get -t -v ./...
package context: unrecognized import path "context" (import path does not begin with hostname)

�[31;1mThe command "eval go get -t -v ./... " failed. Retrying, 2 of 3.�[0m

package context: unrecognized import path "context" (import path does not begin with hostname)

�[31;1mThe command "eval go get -t -v ./... " failed. Retrying, 3 of 3.�[0m

package context: unrecognized import path "context" (import path does not begin with hostname)

�[31;1mThe command "eval go get -t -v ./... " failed 3 times.�[0m


travis_time:end:0036d8f0:start=1526830974422325869,finish=1526830977670532424,duration=3248206555
�[0K
�[31;1mThe command "go get -t -v ./..." failed and exited with 1 during .�[0m

Your build has been stopped.

Option to not have name for test and only print parameters

There should be a way to label tests with small parameter inputs such as small strings, integers, and structs. Then the inputs should be listed in any error message, such as:

t.Errorf("Add(%q, %q) = %v, want %v", tt.name, tt.in0, tt.in1, got, tt.want)

Gotests strips comments

Hi,

I'm a long time user, and have only noticed this issue now. It seams that gotests strips comment from the test files, this includes the copyright and license header block which is prepended to file. Is this expected behaviour, or would you accept a change?

Support method type in "-only" regular expression option

Currently with the option “-only” it is not possible to provide the “struct type” in the regular expression.

example:

type structA struct {
   name string
}

type structB struct {}

func (s structA) PrintName() string {
   returnstructA+ s.name
}

func (s structB) PrintName() string {
   returnstructB”
}

func (s *structA) SetName(n string) string {
    s.name = n
}

if we run gotests -only PrintName it will generate the unit-tests for both functions

it could be interesting to support also the struct type in the regular expression like this: gotests -only structA.PrintName or gotests -only (structA).SetName

or create a new option: “-exact”: gotests -exact (structA).PrintName or gotests -exact structA.PrintName

Test document creation error output.Process:imports.Process:...

Everything was working fine till yesterday but today I'm getting this error whenever I try to create a test for the function in vscode 1.19.1 windows x64
output.Process: imports.Process: C:\Users\Johan\AppData\Local\Temp\gotests_174054079:18:1: expected declaration, found ')'

In the temp folder I only see empty 0 bytes gotests_xxx files

No idea what is the problem

No need for "type args struct" if function takes a single-argument

e.g.

func Test_clonePod(t *testing.T) {
	type args struct {
		pod *corev1.Pod
	}
	tests := []struct {
		name    string
		args    args
		want    *corev1.Pod
		wantErr bool
	}{
	    // TODO: Add test cases.
	}
	...
}

In the code above, instead of generating type args struct { ...}, it's sufficient to just specify args field in anonymous struct as *corev1.Pod and not generate an additional type. This should help create simpler and more readable tests.

Do not overwrite "import groups" in the generate output

Currently if we when gotests generates tests on an existing test file, it rewrite completely the imports with a default ordering.

example:

package client

import (
   "fmt"
   "errors"

   "k8s.io/pkg/api"
)

// code here...

gotests output:

package client

import (
    "k8s.io/pkg/api"
    "fmt"
    "errors"
)

// code here...

it will be nice if "gotests" works like "goimport" and so the "import groups" are not remove.

Vim plugin

We have EMacs support, but it would be nice to have a Vim plugin too for all our home-row-key friends out there.

Support for generating test cases

Hi,

I've been thinking of modifying gotests to support using the testing/quick package to generate test cases
and optimize them for code coverage.

Have you thought about something similar before and is this something you would accept as a feature in the project, or is it better to fork it?

My high-level idea is to:

  • Use gotests to generate tests
  • Use testing/quick to generate test inputs
  • Measure the code coverage while running each test inputs
  • Shrink the test inputs to a minimal set that provides high coverage

Not sure how complex generating test cases for complex/nested structs will be, but it should be fairly simple for basic types.

Add option to put struct receiver fields in method's test-struct

This would mean less code needed in tests, since the receiver is often under test and its fields may frequently change, or not be required. The fewer characters needed per test case, the better. Perhaps a -fields boolean flag.

e.g.

// foo.go
type Foo struct {
   Gender  string
   Age     int
}

func (f *Foo) Bar() string {}

Default:

// foo_test.go
func TestFooBar(t *testing.T) {
  // Before:
  tests := []struct {
    f    *Foo
    want string
  } {}
  for _, tt := range tests {
    got := tt.f.Bar()
  // ....

With -fields flag:

// foo_test.go
func TestFooBar(t *testing.T) {
  tests := []struct {
    gender  string
    age     int
    want    string
  } {}
  for _, tt := range tests {
    f := &Foo{Gender: tt.gender, Age: tt.Age}
    got := f.Bar()
    // ...
  }
}

Include receiver type in test method names

If two structs implement a method with the same name, they will cause gotests to generate two tests with the same name.

Instead tests should prefix the type of the receiver to the test name.

gotests add "robpike.io/ivy/config" to my test file.

$ go test -run TestApi_UpdateStack -v ./src/api/*.go                                    
# command-line-arguments
src/api/stack.go:12: imported and not used: "github.com/Dataman-Cloud/crane/src/utils/config"
src/api/stack_test.go:29: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
src/api/stack_test.go:53: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
src/api/stack_test.go:77: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
src/api/stack_test.go:101: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
src/api/stack_test.go:125: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
src/api/stack_test.go:149: cannot use tt.fields.Config (type *"robpike.io/ivy/config".Config) as type *"github.com/Dataman-Cloud/crane/src/utils/config".Config in field value
FAIL    command-line-arguments [build failed]

When use global variable get panic error.

When i set global variable value in test i'm get panic: assignment to entry in nil map
In main file i'm have var authheader string
According golang init() in *_test.go run after non-test files

My test is:


package main

import "testing"

func init() {
	authheader = "asdaaa"
}

func Test_sendToDB(t *testing.T) {

	type args struct {
		result []byte
		path   string
	}
	tests := []struct {
		name    string
		args    args
		wantErr bool
	}{
		{"sendToDB wrong result",
			args{[]byte("Hello "), "tutututu"},
			true,
		},

		{"sendToDB nil result",
			args{nil, "tutututu"},
			true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if err := sendToDB(tt.args.result, tt.args.path); (err != nil) != tt.wantErr {
				t.Errorf("sendToDB() error = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}

Go 1.7 install failed

go get -u -v github.com/cweill/gotests/...
github.com/cweill/gotests (download)

cd /Users/Project/go/src/github.com/cweill/gotests; git pull --ff-only

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> master

package github.com/cweill/gotests/...: exit status 1

panic: interface conversion: ast.Expr is nil, not *ast.StructType

The following minimal code (which correctly builds) reliably leads to a panic:

package main

import "net/url"

type something url.URL

func (smtg *something) UnmarshalJSON(bytes []byte) error {
	x := &url.URL{}
	smtg = (*something)(x)
	return nil
}

func main() {}

Generates the following panic:

$ gotests -w -all gotestspanic.go
panic: interface conversion: ast.Expr is nil, not *ast.StructType

goroutine 20 [running]:
github.com/cweill/gotests/internal/goparser.parseReceiver(0xc420073fb0, 0xc420231290, 0xc4202312c0, 0x8c59c0)
	/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:220 +0x430
github.com/cweill/gotests/internal/goparser.parseFunc(0xc4202300f0, 0xc420231290, 0xc4202312c0, 0x1)
	/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:173 +0x9d
github.com/cweill/gotests/internal/goparser.(*Parser).parseFunctions(0xc42006bee8, 0xc42000eac0, 0xc4201ba500, 0xc42000c1b8, 0x1, 0x1, 0x29a, 0x1, 0x1)
	/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:105 +0x108
github.com/cweill/gotests/internal/goparser.(*Parser).Parse(0xc42006bee8, 0x7ffd49b286e2, 0x30, 0xc42008ca90, 0x1, 0x1, 0x20, 0x18, 0x6b6a00)
	/go/src/github.com/cweill/gotests/internal/goparser/goparser.go:58 +0x2da
github.com/cweill/gotests.generateTest(0x7ffd49b286e2, 0x30, 0xc42008ca90, 0x1, 0x1, 0xc42008a900, 0x0, 0xc4200297a0, 0x5141f0)
	/go/src/github.com/cweill/gotests/gotests.go:101 +0xb7
github.com/cweill/gotests.parallelize.func1(0xc4200a4420, 0xc42008ca90, 0x1, 0x1, 0xc42008a900, 0xc42008e540, 0x7ffd49b286e2, 0x30)
	/go/src/github.com/cweill/gotests/gotests.go:73 +0xb7
created by github.com/cweill/gotests.parallelize
	/go/src/github.com/cweill/gotests/gotests.go:70 +0x125

	at ChildProcess.exithandler (child_process.js:217:12)
	at emitTwo (events.js:106:13)
	at ChildProcess.emit (events.js:194:7)
	at maybeClose (internal/child_process.js:899:16)
	at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

Miss leading error message when no flag is provided.

davidf@davidf-pc:~/go/src/gerrit.lan/tps.git/pkg/startup$ gotests recovery.go
Please specify either the -only, -excl, -export, or -all flag
davidf@davidf-pc:~/go/src/gerrit.lan/tps.git/pkg/startup$ gotests -export recovery.go
flag provided but not defined: -export
Usage of gotests:
  -all
        generate tests for all functions and methods
  -excl string
        regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all
  -exported
        generate tests for exported functions and methods. Takes precedence over -only and -all
  -i    print test inputs in error messages
  -nosubtests
        disable generating tests using the Go 1.7 subtests feature
  -only string
        regexp. generate tests for functions and methods that match only. Takes precedence over -all
  -w    write output to (test) files instead of stdout

The message "Please specify either the -only, -excl, -export, or -all flag" should be "Please specify either the -only, -excl, -exported, or -all flag"

continue is not in a loop

Env:

go version go1.7.1 darwin/amd64
Sublime Text 3 using the plugin https://github.com/cweill/GoTests-Sublime

What Happens:

There shouldn't be a continue inside t.Run .

Now work around by adding the '-nosubtests' options in the sublime text 3 plugin.

Generateded code:

func Test_getEtcdAuth(t *testing.T) {
	type args struct {
		url string
	}
	tests := []struct {
		name    string
		args    args
		want    *EtcdAuth
		wantErr bool
	}{
	// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := getEtcdAuth(tt.args.url)
			if (err != nil) != tt.wantErr {
				t.Errorf("getEtcdAuth() error = %v, wantErr %v", err, tt.wantErr)
				continue
			}
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("getEtcdAuth() = %v, want %v", got, tt.want)
			}
		})
	}
}

Support custom templates with external formatters

Sometimes outputting got and want isn't enough. There are many useful OSS packages for generating pretty diffs of strings, structs, slices etc, but it would be unreasonable for this binary to require them as dependencies in the generated test files.

Instead, if the repository already has the dependency, the template will use it by automatically. This would allow users to created their own custom templates using their in-house tools.

These custom templates could be specified in a json/yaml file that define the template for a result of a given types:

For example if "github.com/tonnerre/golang-pretty" is available:

types:  
 - struct
 - map
 - slice
deps: 
 - github.com/tonnerre/golang-pretty
template: >
 if {{.Got}} := {{Func}}({{.Args}}); !reflect.DeepEqual({{.Got}}, tt.{{.Want}}) {
   t.Errorf("%v. {{Func}}() returned diff (want -> got)\n %v", tt.name, pretty.Compare(tt.{{.Want}}), {{.Got}}))
 }

This will require a significant (and much needed) refactor of the render package.

Namespacing in the test table

Hey :D

Thanks a bunch this has been really useful in the past few days. Have you thought about trying to namespace the different arguments in the table. For example a sample s3 mock:

package main

import "fmt"

type S3Bucket struct {
    Name    string
    Storage map[string][]byte
}

func (s *S3Bucket) Save(name string, body []byte) error {
    if err := validateName(name); err != nil {
        return err
    }

    s.Storage[name] = body
    return nil
}

func validateName(name string) error {
    if len(name) == 0 {
        return fmt.Errorf("name must not be empty")
    }

    return nil
}

will produce this test:

func TestS3BucketSave(t *testing.T) {
    tests := []struct {
        name    string
        fname   string
        storage map[string][]byte
        pname   string
        body    []byte
        wantErr bool
    }{
    // TODO: Add test cases.
    }
    for _, tt := range tests {
        s := &S3Bucket{
            Name:    tt.fname,
            Storage: tt.storage,
        }
        if err := s.Save(tt.pname, tt.body); (err != nil) != tt.wantErr {
            t.Errorf("%q. S3Bucket.Save() error = %v, wantErr %v", tt.name, err, tt.wantErr)
        }
    }
}

but since the tests struct includes both the fields and arguments it can get a bit confusing trying mentally keep track of where things going. Would you consider doing something like this instead?

func TestS3BucketSave(t *testing.T) {
    tests := []struct {
        fields struct {
            name string
            body []byte
        }
        args struct {
            name    string
            storage map[string][]byte
        }
        name    string
        wantErr bool
    }{
    // TODO: Add test cases.
    }
    for _, tt := range tests {
        s := &S3Bucket{
            Name:    tt.fields.name,
            Storage: tt.fields.storage,
        }
        if err := s.Save(tt.args.pname, tt.args.body); (err != nil) != tt.wantErr {
            t.Errorf("%q. S3Bucket.Save() error = %v, wantErr %v", tt.name, err, tt.wantErr)
        }
    }
}

Tests not generated when two methods/functions have same name

When two methods have the same name, but one is exported and the other isn't, tests don't get generated.

e.g.

func SameName() error {
    return nil
}

func sameName() error {
    return nil
}

func (t *SameTypeName) SameName() error {
    return nil
}

func (t *SameTypeName) sameName() error {
    return nil
}

func (t *sameTypeName) SameName() error {
    return nil
}

func (t *sameTypeName) sameName() error {
    return nil
}

This is easy to fix, but it means changing generate test function names. We can use the same convention as the one used for examples at: https://golang.org/pkg/testing/#pkg-overview

func Example() { ... }
func ExampleF() { ... }
func ExampleT() { ... }
func ExampleT_M() { ... }

Except the difference with examples is that not all functions or receivers are exported. Unexported functions and receivers will be prefixed with an underscore:

func TestF(t *testing.T) { ... }
func TestT(t *testing.T) { ... }
func TestT_M(t *testing.T) { ... }
func TestT_m(t *testing.T) { ... }
func Test_f(t *testing.T) { ... }
func Test_t(t *testing.T) { ... }
func Test_t_M(t *testing.T) { ... }
func Test_t_m(t *testing.T) { ... }

Allow to optionally use testify

Open to coding this one if there is support to merge...
I'm a huge fan of the testing package testify for printing errors during testing:
github.com/stretchr/testify/assert

It would be cool to have a flag which allowed for use of this package instead of the standard error print which is currently being used... here is an example of how this change would look:

old:

	if err := tx.ValidateBasic(); (err != nil) != tt.wantErr {
		t.Errorf("TxModComm.ValidateBasic() error = %v, wantErr %v", err, tt.wantErr)
	}

with testify:

	assert.Equal(t, tt.wantErr, tx.ValidateBasic() != nil, tt.name)

Obviously, this is for a simple error function, but assert does provide a variety of different comparisons as well. Let me know any thoughts! I'll probably end up making a branch which uses assert anyways, but I'll make it optional with a flag if there is an opportunity to merge this back in.

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.