package main
import (
)
type testReport struct {
Events []testEvent
Stderr []byte
Failed bool
Decode error
Buffer []byte
}
type testEvent struct {
Time time.Time
Action string
Package string
Test string
Elapsed float64
Output *string
}
func ( *flags, *workspace) (*testReport, error) {
if .runTests == runTestsNone {
return nil, nil
}
var testReport
:= []string{"test", "-json", "-short"}
if !.testShort {
= [:len()-1]
}
var []string
if .runTests == runTestsWork {
= make([]string, len(.Paths)+len())
_ = copy(, )
for , := range .Paths {
[+len()] = filepath.Join(, "...")
}
} else {
= make([]string, len()+1)
_ = copy(, )
[len()-1] = "all"
}
log("running tests")
var , bytes.Buffer
:= exec.Command("go", ...)
.Dir = .Root()
.Stdout = &
.Stderr = &
var *exec.ExitError
switch := .Run(); {
case errors.As(, &):
.Failed = true
case != nil:
return nil,
}
.Stderr = .Bytes()
:= json.NewDecoder(&)
for {
var testEvent
:= .Decode(&)
if == io.EOF {
break
}
if != nil {
.Decode =
.Buffer, _ = io.ReadAll(io.MultiReader(.Buffered(), &))
break
}
.Events = append(.Events, )
}
return &, nil
}