github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/cformat/format.go (about)

     1  // Copyright 2022 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  package cformat
     6  
     7  import (
     8  	"github.com/shogo82148/std/internal/coverage"
     9  	"github.com/shogo82148/std/io"
    10  )
    11  
    12  type Formatter struct {
    13  	// Maps import path to package state.
    14  	pm map[string]*pstate
    15  	// Records current package being visited.
    16  	pkg string
    17  	// Pointer to current package state.
    18  	p *pstate
    19  	// Counter mode.
    20  	cm coverage.CounterMode
    21  }
    22  
    23  func NewFormatter(cm coverage.CounterMode) *Formatter
    24  
    25  // SetPackage tells the formatter that we're about to visit the
    26  // coverage data for the package with the specified import path.
    27  // Note that it's OK to call SetPackage more than once with the
    28  // same import path; counter data values will be accumulated.
    29  func (fm *Formatter) SetPackage(importpath string)
    30  
    31  // AddUnit passes info on a single coverable unit (file, funcname,
    32  // literal flag, range of lines, and counter value) to the formatter.
    33  // Counter values will be accumulated where appropriate.
    34  func (fm *Formatter) AddUnit(file string, fname string, isfnlit bool, unit coverage.CoverableUnit, count uint32)
    35  
    36  // EmitTextual writes the accumulated coverage data in the legacy
    37  // cmd/cover text format to the writer 'w'. We sort the data items by
    38  // importpath, source file, and line number before emitting (this sorting
    39  // is not explicitly mandated by the format, but seems like a good idea
    40  // for repeatable/deterministic dumps).
    41  func (fm *Formatter) EmitTextual(w io.Writer) error
    42  
    43  // EmitPercent writes out a "percentage covered" string to the writer 'w'.
    44  func (fm *Formatter) EmitPercent(w io.Writer, covpkgs string, noteEmpty bool, aggregate bool) error
    45  
    46  // EmitFuncs writes out a function-level summary to the writer 'w'. A
    47  // note on handling function literals: although we collect coverage
    48  // data for unnamed literals, it probably does not make sense to
    49  // include them in the function summary since there isn't any good way
    50  // to name them (this is also consistent with the legacy cmd/cover
    51  // implementation). We do want to include their counts in the overall
    52  // summary however.
    53  func (fm *Formatter) EmitFuncs(w io.Writer) error