Skip to content
This repository has been archived by the owner on Feb 3, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' into sm-channels
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer authored Apr 3, 2017
2 parents 8f20ffd + 1c36f26 commit 56923fc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 69 deletions.
2 changes: 1 addition & 1 deletion _testdata/cmd/echosleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func main() {

for i := 0; i < *n; i++ {
fmt.Println("foo")
time.Sleep(time.Duration(i) * 100 * time.Millisecond)
time.Sleep(time.Duration(i) * 250 * time.Millisecond)
}
}
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test:
cd $RD && \
echo 'mode: atomic' > coverage.txt && \
go list ./... | grep -v "/vendor/" | \
xargs -n1 -I% sh -c 'set -e; go test -covermode=atomic -coverprofile=coverage.out -v % ; tail -n +2 coverage.out >> coverage.txt' && \
xargs -n1 -I% sh -c 'set -e; go test -covermode=atomic -coverprofile=coverage.out % ; tail -n +2 coverage.out >> coverage.txt' && \
rm coverage.out
- cd $RD && go build example.go
- cd $RD && bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func mkTestCmd(iterations int) *monitoredCmd {
return newMonitoredCmd(
exec.Command("./echosleep", "-n", fmt.Sprint(iterations)),
200*time.Millisecond,
500*time.Millisecond,
)
}

Expand Down
5 changes: 2 additions & 3 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ func (m *metrics) dump(l *log.Logger) {
fmt.Fprintf(w, "\t%s:\t%v\t\n", nd.n, nd.d)
}
fmt.Fprintf(w, "\n\tTOTAL:\t%v\t\n", tot)

l.Println("\nSolver wall times by segment:")
w.Flush()
fmt.Println((&buf).String())

l.Println("\nSolver wall times by segment:")
l.Println((&buf).String())
}

type ndpair struct {
Expand Down
39 changes: 27 additions & 12 deletions solve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"io/ioutil"
"log"
"math/rand"
"os"
"reflect"
"sort"
"strconv"
"strings"
"testing"
"unicode"

"github.com/sdboyer/gps/internal"
"github.com/sdboyer/gps/pkgtree"
Expand Down Expand Up @@ -52,13 +52,31 @@ func overrideIsStdLib() {
}
}

var stderrlog = log.New(os.Stderr, "", 0)
type testlogger struct {
*testing.T
}

func (t testlogger) Write(b []byte) (n int, err error) {
str := string(b)
if len(str) == 0 {
return 0, nil
}

func fixSolve(params SolveParameters, sm SourceManager) (Solution, error) {
if testing.Verbose() {
params.Trace = true
params.TraceLogger = stderrlog
for _, part := range strings.Split(str, "\n") {
str := strings.TrimRightFunc(part, unicode.IsSpace)
if len(str) != 0 {
t.T.Log(str)
}
}
return len(b), err
}

func fixSolve(params SolveParameters, sm SourceManager, t *testing.T) (Solution, error) {
// Trace unconditionally; by passing the trace through t.Log(), the testing
// system will decide whether or not to actually show the output (based on
// -v, or selectively on test failure).
params.Trace = true
params.TraceLogger = log.New(testlogger{T: t}, "", 0)

s, err := Prepare(params, sm)
if err != nil {
Expand Down Expand Up @@ -111,7 +129,7 @@ func solveBasicsAndCheck(fix basicFixture, t *testing.T) (res Solution, err erro
params.Lock = fix.l
}

res, err = fixSolve(params, sm)
res, err = fixSolve(params, sm, t)

return fixtureSolveSimpleChecks(fix, res, err, t)
}
Expand Down Expand Up @@ -142,9 +160,6 @@ func TestBimodalSolves(t *testing.T) {
}

func solveBimodalAndCheck(fix bimodalFixture, t *testing.T) (res Solution, err error) {
if testing.Verbose() {
stderrlog.Printf("[[fixture %q]]", fix.n)
}
sm := newbmSM(fix)

params := SolveParameters{
Expand All @@ -161,7 +176,7 @@ func solveBimodalAndCheck(fix bimodalFixture, t *testing.T) (res Solution, err e
params.Lock = fix.l
}

res, err = fixSolve(params, sm)
res, err = fixSolve(params, sm, t)

return fixtureSolveSimpleChecks(fix, res, err, t)
}
Expand Down Expand Up @@ -289,7 +304,7 @@ func TestRootLockNoVersionPairMatching(t *testing.T) {
ProjectAnalyzer: naiveAnalyzer{},
}

res, err := fixSolve(params, sm)
res, err := fixSolve(params, sm, t)

fixtureSolveSimpleChecks(fix, res, err, t)
}
Expand Down
Loading

0 comments on commit 56923fc

Please sign in to comment.