Commits

Anonymous committed a4095ec

a more complete example with tests ^_^

  • Participants
  • Parent commits 2295735

Comments (0)

Files changed (4)

-c:\go\bin\go build -o %BuildFolder%\hello.exe %SrcFolder%\hello.go
+cd %SrcFolder%
+c:\go\bin\go test -v ./...

cmd/hello/main.go

+package main
+
+import (
+	"fmt"
+
+	"bitbucket.org/appveyor/test-go/pkg/greet"
+)
+
+func main() {
+	g := greet.NewGreeter("AppVeyor")
+	fmt.Println(g)
+}

pkg/greet/greet.go

+package greet
+
+import (
+	"fmt"
+)
+
+type Greet struct {
+	who string
+}
+
+func NewGreeter(who string) *Greet {
+	return &Greet{who: who}
+}
+
+func (g *Greet) String() string {
+	return fmt.Sprintf("Hello %s", g.who)
+}

pkg/greet/greet_test.go

+package greet_test
+
+import (
+	"testing"
+
+	"bitbucket.org/appveyor/test-go/pkg/greet"
+)
+
+func TestGreeting(t *testing.T) {
+	expected := "Hello AppVeyor"
+	g := greet.NewGreeter("AppVeyor")
+
+	if g.String() != expected {
+		t.Errorf("Expected %s, got %s", expected, g)
+	}
+}