Skip to content

Commit

Permalink
cmd/{cover,covdata}: minor code cleanups
Browse files Browse the repository at this point in the history
Delete some unused code, and fix a few warnings from staticcheck.

Change-Id: I3d3a6f13dccffda060449948769c305d93a0389c
Reviewed-on: https://go-review.googlesource.com/c/go/+/441936
Reviewed-by: Bryan Mills <[email protected]>
  • Loading branch information
thanm committed Oct 12, 2022
1 parent 4bcf94b commit 0394cbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/cmd/covdata/subtractintersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func makeSubtractIntersectOp(mode string) covOperation {
// away most of the grubby details of reading coverage data files.
type sstate struct {
mm *metaMerge
indir string // current input directory
inidx int
mode string
// Used only for intersection; keyed by pkg/fn ID, it keeps track of
Expand Down
12 changes: 5 additions & 7 deletions src/cmd/covdata/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"internal/coverage/pods"
"internal/goexperiment"
"internal/testenv"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -104,11 +103,11 @@ func gobuild(t *testing.T, indir string, bargs []string) {
}

func emitFile(t *testing.T, dst, src string) {
payload, err := ioutil.ReadFile(src)
payload, err := os.ReadFile(src)
if err != nil {
t.Fatalf("error reading %q: %v", src, err)
}
if err := ioutil.WriteFile(dst, payload, 0666); err != nil {
if err := os.WriteFile(dst, payload, 0666); err != nil {
t.Fatalf("writing %q: %v", dst, err)
}
}
Expand All @@ -134,8 +133,8 @@ func buildProg(t *testing.T, prog string, dir string, tag string, flags []string

// Emit go.mod.
mod := filepath.Join(subdir, "go.mod")
modsrc := fmt.Sprintf("\nmodule prog\n\ngo 1.19\n")
if err := ioutil.WriteFile(mod, []byte(modsrc), 0666); err != nil {
modsrc := "\nmodule prog\n\ngo 1.19\n"
if err := os.WriteFile(mod, []byte(modsrc), 0666); err != nil {
t.Fatal(err)
}
exepath := filepath.Join(subdir, prog+".exe")
Expand Down Expand Up @@ -418,7 +417,7 @@ func testTextfmt(t *testing.T, s state) {
}

// Open and read the first few bits of the file.
payload, err := ioutil.ReadFile(outf)
payload, err := os.ReadFile(outf)
if err != nil {
t.Errorf("opening %s: %v\n", outf, err)
}
Expand Down Expand Up @@ -616,7 +615,6 @@ func testMergeSelect(t *testing.T, s state, indir1, indir2 string, tag string) {
}
want[line] = 1
continue
} else {
}
// no other functions or packages expected.
if strings.HasPrefix(line, "Func:") || strings.HasPrefix(line, "Package path:") {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cover/cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestCoverWithCfg(t *testing.T) {

// Expect err if config file contains unknown stuff.
t.Logf("mangling in config")
writeFile(t, incfg, []byte(fmt.Sprintf("blah=foo\n")))
writeFile(t, incfg, []byte("blah=foo\n"))
_, _, errmsg = runPkgCover(t, instdira, tag, incfg, mode,
pfiles("a"), errExpected)
want = "error reading pkgconfig file"
Expand All @@ -177,7 +177,7 @@ func TestCoverWithCfg(t *testing.T) {

// Expect error on empty config file.
t.Logf("writing empty config")
writeFile(t, incfg, []byte(fmt.Sprintf("\n")))
writeFile(t, incfg, []byte("\n"))
_, _, errmsg = runPkgCover(t, instdira, tag, incfg, mode,
pfiles("a"), errExpected)
if !strings.Contains(errmsg, want) {
Expand Down
34 changes: 2 additions & 32 deletions src/cmd/cover/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"internal/coverage/encodemeta"
"internal/coverage/slicewriter"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -190,15 +189,15 @@ func parseFlags() error {
}

func readOutFileList(path string) ([]string, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error reading -outfilelist file %q: %v", path, err)
}
return strings.Split(strings.TrimSpace(string(data)), "\n"), nil
}

func readPackageConfig(path string) error {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("error reading pkgconfig file %q: %v", path, err)
}
Expand Down Expand Up @@ -1008,35 +1007,6 @@ func dedup(p1, p2 token.Position) (r1, r2 token.Position) {
return key.p1, key.p2
}

type sliceWriteSeeker struct {
payload []byte
off int64
}

func (d *sliceWriteSeeker) Write(p []byte) (n int, err error) {
amt := len(p)
towrite := d.payload[d.off:]
if len(towrite) < amt {
d.payload = append(d.payload, make([]byte, amt-len(towrite))...)
towrite = d.payload[d.off:]
}
copy(towrite, p)
d.off += int64(amt)
return amt, nil
}

func (d *sliceWriteSeeker) Seek(offset int64, whence int) (int64, error) {
if whence == io.SeekStart {
d.off = offset
return offset, nil
} else if whence == io.SeekCurrent {
d.off += offset
return d.off, nil
}
// other modes not supported
panic("bad")
}

func (p *Package) emitMetaData(w io.Writer) {
if *pkgcfg == "" {
return
Expand Down

0 comments on commit 0394cbe

Please sign in to comment.