github.com/vlal/goveralls@v0.0.2-0.20171114042957-b71a1e4855f8/gocover_test.go (about)

     1  package main
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"golang.org/x/tools/cover"
     8  )
     9  
    10  func TestMergeProfs(t *testing.T) {
    11  	tests := []struct {
    12  		in   [][]*cover.Profile
    13  		want []*cover.Profile
    14  	}{
    15  		// empty
    16  		{in: nil, want: nil},
    17  		// The number of profiles is 1
    18  		{in: [][]*cover.Profile{[]*cover.Profile{{FileName: "name1"}}}, want: []*cover.Profile{{FileName: "name1"}}},
    19  		// merge profile blocks
    20  		{
    21  			in: [][]*cover.Profile{
    22  				[]*cover.Profile{}, // skip first empty profiles.
    23  				[]*cover.Profile{
    24  					{
    25  						FileName: "name1",
    26  						Blocks: []cover.ProfileBlock{
    27  							cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 1},
    28  						},
    29  					},
    30  					{
    31  						FileName: "name2",
    32  						Blocks: []cover.ProfileBlock{
    33  							cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 0},
    34  						},
    35  					},
    36  				},
    37  				[]*cover.Profile{}, // skip first empty profiles.
    38  				[]*cover.Profile{
    39  					{
    40  						FileName: "name1",
    41  						Blocks: []cover.ProfileBlock{
    42  							cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 1},
    43  						},
    44  					},
    45  					{
    46  						FileName: "name2",
    47  						Blocks: []cover.ProfileBlock{
    48  							cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 1},
    49  						},
    50  					},
    51  				},
    52  			},
    53  			want: []*cover.Profile{
    54  				{
    55  					FileName: "name1",
    56  					Blocks: []cover.ProfileBlock{
    57  						cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 2},
    58  					},
    59  				},
    60  				{
    61  					FileName: "name2",
    62  					Blocks: []cover.ProfileBlock{
    63  						cover.ProfileBlock{StartLine: 1, StartCol: 1, Count: 1},
    64  					},
    65  				},
    66  			},
    67  		},
    68  	}
    69  
    70  	for _, tt := range tests {
    71  		if got := mergeProfs(tt.in); !reflect.DeepEqual(got, tt.want) {
    72  			t.Errorf("mergeProfs(%#v) = %#v, want %#v", tt.in, got, tt.want)
    73  		}
    74  	}
    75  }