github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/pods/pods.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 pods
     6  
     7  // Pod encapsulates a set of files emitted during the executions of a
     8  // coverage-instrumented binary. Each pod contains a single meta-data
     9  // file, and then 0 or more counter data files that refer to that
    10  // meta-data file. Pods are intended to simplify processing of
    11  // coverage output files in the case where we have several coverage
    12  // output directories containing output files derived from more
    13  // than one instrumented executable. In the case where the files that
    14  // make up a pod are spread out across multiple directories, each
    15  // element of the "Origins" field below will be populated with the
    16  // index of the originating directory for the corresponding counter
    17  // data file (within the slice of input dirs handed to CollectPods).
    18  // The ProcessIDs field will be populated with the process ID of each
    19  // data file in the CounterDataFiles slice.
    20  type Pod struct {
    21  	MetaFile         string
    22  	CounterDataFiles []string
    23  	Origins          []int
    24  	ProcessIDs       []int
    25  }
    26  
    27  // CollectPods visits the files contained within the directories in
    28  // the list 'dirs', collects any coverage-related files, partitions
    29  // them into pods, and returns a list of the pods to the caller, along
    30  // with an error if something went wrong during directory/file
    31  // reading.
    32  //
    33  // CollectPods skips over any file that is not related to coverage
    34  // (e.g. avoids looking at things that are not meta-data files or
    35  // counter-data files). CollectPods also skips over 'orphaned' counter
    36  // data files (e.g. counter data files for which we can't find the
    37  // corresponding meta-data file). If "warn" is true, CollectPods will
    38  // issue warnings to stderr when it encounters non-fatal problems (for
    39  // orphans or a directory with no meta-data files).
    40  func CollectPods(dirs []string, warn bool) ([]Pod, error)
    41  
    42  // CollectPodsFromFiles functions the same as "CollectPods" but
    43  // operates on an explicit list of files instead of a directory.
    44  func CollectPodsFromFiles(files []string, warn bool) []Pod