Skip to content

Commit

Permalink
testscript: remove errgo dependency (#155)
Browse files Browse the repository at this point in the history
There's no need to use it and every dependency lost is good.
  • Loading branch information
rogpeppe committed Mar 9, 2022
1 parent f3cb5c2 commit b66946f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
5 changes: 1 addition & 4 deletions go.mod
Expand Up @@ -2,7 +2,4 @@ module github.com/rogpeppe/go-internal

go 1.16

require (
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
gopkg.in/errgo.v2 v2.1.0
)
require github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
9 changes: 0 additions & 9 deletions go.sum
@@ -1,11 +1,2 @@
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
27 changes: 13 additions & 14 deletions testscript/cover.go
Expand Up @@ -6,6 +6,7 @@ package testscript

import (
"bufio"
"errors"
"fmt"
"io"
"os"
Expand All @@ -15,8 +16,6 @@ import (
"strings"
"sync/atomic"
"testing"

"gopkg.in/errgo.v2/fmt/errors"
)

// mergeCoverProfile merges the coverage information in f into
Expand All @@ -30,10 +29,10 @@ func mergeCoverProfile(cover *testing.Cover, path string) error {
defer f.Close()
scanner, err := newProfileScanner(f)
if err != nil {
return errors.Wrap(err)
return err
}
if scanner.Mode() != testing.CoverMode() {
return errors.Newf("unexpected coverage mode in subcommand")
return errors.New("unexpected coverage mode in subcommand")
}
if cover.Mode == "" {
cover.Mode = scanner.Mode()
Expand Down Expand Up @@ -83,7 +82,7 @@ func mergeCoverProfile(cover *testing.Cover, path string) error {
}
flush()
if scanner.Err() != nil {
return errors.Notef(err, nil, "error scanning profile")
return fmt.Errorf("error scanning profile: %v", err)
}
return nil
}
Expand All @@ -104,7 +103,7 @@ func finalizeCoverProfile(dir string) error {
}
return nil
}); err != nil {
return errors.Wrap(err)
return err
}
if err := os.RemoveAll(dir); err != nil {
// The RemoveAll seems to fail very rarely, with messages like
Expand All @@ -116,7 +115,7 @@ func finalizeCoverProfile(dir string) error {
}
return nil
})
return errors.Wrap(err)
return err
}

// We need to include our own top-level coverage profile too.
Expand All @@ -128,18 +127,18 @@ func finalizeCoverProfile(dir string) error {
// Finally, write the resulting merged profile.
f, err := os.Create(cprof)
if err != nil {
return errors.Notef(err, nil, "cannot create cover profile")
return fmt.Errorf("cannot create cover profile: %v", err)
}
defer f.Close()
w := bufio.NewWriter(f)
if err := writeCoverProfile1(w, cover); err != nil {
return errors.Wrap(err)
return err
}
if err := w.Flush(); err != nil {
return errors.Wrap(err)
return err
}
if err := f.Close(); err != nil {
return errors.Wrap(err)
return err
}
return nil
}
Expand All @@ -164,7 +163,7 @@ func writeCoverProfile1(w io.Writer, cover testing.Cover) error {
count,
)
if err != nil {
return errors.Wrap(err)
return err
}
}
}
Expand Down Expand Up @@ -207,7 +206,7 @@ func newProfileScanner(r io.Reader) (*profileScanner, error) {
// encoding/base64/base64.go:34.44,37.40 3 1
// where the fields are: name.go:line.column,line.column numberOfStatements count
if !s.scanner.Scan() {
return nil, errors.Newf("no lines found in profile: %v", s.Err())
return nil, fmt.Errorf("no lines found in profile: %v", s.Err())
}
line := s.scanner.Text()
mode := strings.TrimPrefix(line, "mode: ")
Expand Down Expand Up @@ -263,7 +262,7 @@ func (s *profileScanner) Scan() bool {
}
m := profileLineRe.FindStringSubmatch(s.scanner.Text())
if m == nil {
s.err = errors.Newf("line %q doesn't match expected format %v", m, profileLineRe)
s.err = fmt.Errorf("line %q doesn't match expected format %v", m, profileLineRe)
return false
}
s.filename = m[1]
Expand Down

0 comments on commit b66946f

Please sign in to comment.