...

Source file src/github.com/bazelbuild/rules_go/go/tools/bzltestutil/lcov_test.go

Documentation: github.com/bazelbuild/rules_go/go/tools/bzltestutil

     1  package bzltestutil
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestConvertCoverToLcov(t *testing.T) {
     9  	var tests = []struct {
    10  		name         string
    11  		goCover      string
    12  		expectedLcov string
    13  	}{
    14  		{
    15  			"empty",
    16  			"",
    17  			"",
    18  		},
    19  		{
    20  			"mode only",
    21  			"mode: set\n",
    22  			"",
    23  		},
    24  		{
    25  			"single file",
    26  			`mode: count
    27  file.go:0.4,2.10 0 0
    28  `,
    29  			`SF:file.go
    30  DA:0,0
    31  DA:1,0
    32  DA:2,0
    33  LH:0
    34  LF:3
    35  end_of_record
    36  `,
    37  		},
    38  		{
    39  			"narrow ranges",
    40  			`mode: atomic
    41  path/to/pkg/file.go:0.1,0.2 5 1
    42  path/to/pkg/file2.go:1.2,1.2 4 2
    43  `,
    44  			`SF:path/to/pkg/file.go
    45  DA:0,1
    46  LH:1
    47  LF:1
    48  end_of_record
    49  SF:path/to/pkg/file2.go
    50  DA:1,2
    51  LH:1
    52  LF:1
    53  end_of_record
    54  `,
    55  		},
    56  	}
    57  	for _, tt := range tests {
    58  		t.Run(tt.name, func(t *testing.T) {
    59  			in := strings.NewReader(tt.goCover)
    60  			var out strings.Builder
    61  			err := convertCoverToLcov(in, &out)
    62  			if err != nil {
    63  				t.Errorf("convertCoverToLcov returned unexpected error: %+v", err)
    64  			}
    65  			actualLcov := out.String()
    66  			if actualLcov != tt.expectedLcov {
    67  				t.Errorf("covertCoverToLcov returned:\n%q\n, expected:\n%q\n", actualLcov, tt.expectedLcov)
    68  			}
    69  		})
    70  	}
    71  }
    72  

View as plain text