github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/work/cover.go (about)

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Action graph execution methods related to coverage.
     6  
     7  package work
     8  
     9  import (
    10  	"github.com/shogo82148/std/context"
    11  	"github.com/shogo82148/std/io"
    12  )
    13  
    14  // CovData invokes "go tool covdata" with the specified arguments
    15  // as part of the execution of action 'a'.
    16  func (b *Builder) CovData(a *Action, cmdargs ...any) ([]byte, error)
    17  
    18  // BuildActionCoverMetaFile locates and returns the path of the
    19  // meta-data file written by the "go tool cover" step as part of the
    20  // build action for the "go test -cover" run action 'runAct'. Note
    21  // that if the package has no functions the meta-data file will exist
    22  // but will be empty; in this case the return is an empty string.
    23  func BuildActionCoverMetaFile(runAct *Action) (string, error)
    24  
    25  // WriteCoveragePercent writes out to the writer 'w' a "percent
    26  // statements covered" for the package whose test-run action is
    27  // 'runAct', based on the meta-data file 'mf'. This helper is used in
    28  // cases where a user runs "go test -cover" on a package that has
    29  // functions but no tests; in the normal case (package has tests)
    30  // the percentage is written by the test binary when it runs.
    31  func WriteCoveragePercent(b *Builder, runAct *Action, mf string, w io.Writer) error
    32  
    33  // WriteCoverageProfile writes out a coverage profile fragment for the
    34  // package whose test-run action is 'runAct'; content is written to
    35  // the file 'outf' based on the coverage meta-data info found in
    36  // 'mf'. This helper is used in cases where a user runs "go test
    37  // -cover" on a package that has functions but no tests.
    38  func WriteCoverageProfile(b *Builder, runAct *Action, mf, outf string, w io.Writer) error
    39  
    40  // WriteCoverMetaFilesFile writes out a summary file ("meta-files
    41  // file") as part of the action function for the "writeCoverMeta"
    42  // pseudo action employed during "go test -coverpkg" runs where there
    43  // are multiple tests and multiple packages covered. It builds up a
    44  // table mapping package import path to meta-data file fragment and
    45  // writes it out to a file where it can be read by the various test
    46  // run actions. Note that this function has to be called A) after the
    47  // build actions are complete for all packages being tested, and B)
    48  // before any of the "run test" actions for those packages happen.
    49  // This requirement is enforced by adding making this action ("a")
    50  // dependent on all test package build actions, and making all test
    51  // run actions dependent on this action.
    52  func WriteCoverMetaFilesFile(b *Builder, ctx context.Context, a *Action) error