-
Notifications
You must be signed in to change notification settings - Fork 2
Tester
kless edited this page Jul 31, 2012
·
3 revisions
If you use Gowizard: gowizard -tester
Else, use this template in "<Go project>/<name>_test.go"
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)
var EXEC string
func init() {
var err error
log.SetFlags(0)
log.SetPrefix("ERROR: ")
// The executable name will be the directory name.
if EXEC, err = os.Getwd(); err != nil {
log.Fatal(err)
}
EXEC = filepath.Base(EXEC)
if _, err = exec.LookPath(EXEC); err != nil {
if err.(*exec.Error).Err == exec.ErrNotFound {
if err = exec.Command("go", "install").Run(); err != nil {
log.Fatal(err)
}
} else {
log.Fatal(err)
}
}
}
func Example() {
out, err := exec.Command(EXEC).Output()
if err != nil {
log.Fatal(err)
}
fmt.Print(string(out))
// Output:
/*
*/
}