Shell script to automate go lang pkg test coverage

#!/bin/sh PACKAGE=mypkg # set mode go test -coverprofile=coverage.out $PACKAGE go tool cover -func=coverage.out go tool cover -html=coverage.out # count mode go test -covermode=count -coverprofile=count.out $PACKAGE go tool cover -func=count.out go tool cover -html=count.out # more info: http://blog.golang.org/cover

go-lang (3) testing (2)

go log function

func log(s ...interface{}) { f, err := os.OpenFile("info.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { fmt.Printf("error opening log file: %v", err) os.Exit(1) } defer f.Close() log.SetOutput(f) ss := "" for _, p := range s { switch p.(type) { case bool: ss += fmt.Sprintf("%t ", p.(bool)) case int: ss += fmt.Sprintf("%d ", p.(int)) case float64: ss += fmt.Sprintf("%.2f ", p.(float64)) case string: ss += fmt.Sprintf("%s ", p.(string)) } } log.Println(ss) }

go-lang (3)