File tree Expand file tree Collapse file tree 6 files changed +142
-1
lines changed
Expand file tree Collapse file tree 6 files changed +142
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ build: prepare
5151
5252.PHONY : test
5353test : prepare
54- $(GOTEST ) -race -v ./...
54+ $(GOTEST ) -race -coverprofile /tmp/try-golang-cover $( shell go list ./... | grep -v /examples/ | grep -v /cmd/)
5555
5656.PHONY : clean
5757clean : prepare
Original file line number Diff line number Diff line change 1+ package builder_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/devlights/try-golang/builder"
7+ )
8+
9+ func TestMappingIsNotZero (t * testing.T ) {
10+ cases := []struct {
11+ name string
12+ out interface {}
13+ }{
14+ {"sizeIsNotZero" , 0 },
15+ }
16+
17+ for _ , c := range cases {
18+ t .Run (c .name , func (t * testing.T ) {
19+ m := builder .BuildMappings ()
20+ if len (m ) == c .out {
21+ t .Errorf ("[want] not zero\t [got] zero" )
22+ }
23+ })
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package mapping_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/devlights/try-golang/mapping"
7+ )
8+
9+ type (
10+ onlyOneRegister struct {}
11+ )
12+
13+ func (me * onlyOneRegister ) Regist (m mapping.ExampleMapping ) {
14+ m ["this_is_a_test" ] = func () error { return nil }
15+ }
16+
17+ func TestMapping (t * testing.T ) {
18+ m := mapping .NewSampleMapping ()
19+ m .MakeMapping (& onlyOneRegister {})
20+
21+ _ , ok := m ["this_is_a_test" ]
22+ if ! ok {
23+ t .Errorf ("no key.. [want] false\t [got] true" )
24+ }
25+ }
26+
27+ func TestAllExampleNames (t * testing.T ) {
28+ m := mapping .NewSampleMapping ()
29+ m .MakeMapping (& onlyOneRegister {})
30+
31+ names := m .AllExampleNames ()
32+ if len (names ) != 1 {
33+ t .Errorf ("mismatch example count..\t [want] 1\t [got] %d" , len (names ))
34+ }
35+
36+ name := names [0 ]
37+ if name != "this_is_a_test" {
38+ t .Errorf ("mismatch example name..\t [want] this_is_a_test\t [got] %s" , name )
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ package runner_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/devlights/try-golang/mapping"
7+ "github.com/devlights/try-golang/runner"
8+ )
9+
10+ func TestExec (t * testing.T ) {
11+ r := new (runner.SilentRegister )
12+
13+ m := mapping .NewSampleMapping ()
14+ m .MakeMapping (r )
15+
16+ a := runner .NewExecArgs ("silent" , m )
17+ e := runner .NewExec (a )
18+
19+ if err := e .Run (); err != nil {
20+ t .Errorf ("should not raise error (%s)" , err )
21+ }
22+
23+ if ! r .Target .Called {
24+ t .Errorf ("never called the target example" )
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ package runner
2+
3+ import "github.com/devlights/try-golang/mapping"
4+
5+ type (
6+ SilentExample struct {
7+ Called bool
8+ }
9+ SilentRegister struct {
10+ Target * SilentExample
11+ }
12+ )
13+
14+ func (me * SilentExample ) Run () error {
15+ me .Called = true
16+ return nil
17+ }
18+
19+ func (me * SilentRegister ) Regist (m mapping.ExampleMapping ) {
20+ e := & SilentExample {false }
21+ m ["silent" ] = e .Run
22+
23+ me .Target = e
24+ }
Original file line number Diff line number Diff line change 1+ package runner_test
2+
3+ import (
4+ "testing"
5+
6+ "github.com/devlights/try-golang/mapping"
7+ "github.com/devlights/try-golang/runner"
8+ )
9+
10+ func TestOnce (t * testing.T ) {
11+ r := new (runner.SilentRegister )
12+
13+ m := mapping .NewSampleMapping ()
14+ m .MakeMapping (r )
15+
16+ a := runner .NewOnceArgs ("silent" , m )
17+ e := runner .NewOnce (a )
18+
19+ if err := e .Run (); err != nil {
20+ t .Errorf ("should not raise error (%s)" , err )
21+ }
22+
23+ if ! r .Target .Called {
24+ t .Errorf ("never called the target example" )
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments