platform_build_soong/cc/cc_test.go
Colin Cross dd84e056ed Dedup exported flags from dependencies
Soong command lines have gotten very long due to hidl modules
reexporting lots of libraries.  Dedup the include dir flags.

Test: m -j checkbuild
Change-Id: I6ada1251012da42344e2c00ae66001a649023d2c
2017-05-17 14:22:22 -07:00

215 lines
4 KiB
Go

package cc
import (
"android/soong/android"
"reflect"
"testing"
)
var firstUniqueElementsTestCases = []struct {
in []string
out []string
}{
{
in: []string{"a"},
out: []string{"a"},
},
{
in: []string{"a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"a", "a"},
out: []string{"a"},
},
{
in: []string{"a", "b", "a"},
out: []string{"a", "b"},
},
{
in: []string{"b", "a", "a"},
out: []string{"b", "a"},
},
{
in: []string{"a", "a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"a", "b", "a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
out: []string{"liblog", "libdl", "libc++", "libc", "libm"},
},
}
func TestFirstUniqueElements(t *testing.T) {
for _, testCase := range firstUniqueElementsTestCases {
out := firstUniqueElements(testCase.in)
if !reflect.DeepEqual(out, testCase.out) {
t.Errorf("incorrect output:")
t.Errorf(" input: %#v", testCase.in)
t.Errorf(" expected: %#v", testCase.out)
t.Errorf(" got: %#v", out)
}
}
}
var lastUniqueElementsTestCases = []struct {
in []string
out []string
}{
{
in: []string{"a"},
out: []string{"a"},
},
{
in: []string{"a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"a", "a"},
out: []string{"a"},
},
{
in: []string{"a", "b", "a"},
out: []string{"b", "a"},
},
{
in: []string{"b", "a", "a"},
out: []string{"b", "a"},
},
{
in: []string{"a", "a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"a", "b", "a", "b"},
out: []string{"a", "b"},
},
{
in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
out: []string{"liblog", "libc++", "libdl", "libc", "libm"},
},
}
func TestLastUniqueElements(t *testing.T) {
for _, testCase := range lastUniqueElementsTestCases {
out := lastUniqueElements(testCase.in)
if !reflect.DeepEqual(out, testCase.out) {
t.Errorf("incorrect output:")
t.Errorf(" input: %#v", testCase.in)
t.Errorf(" expected: %#v", testCase.out)
t.Errorf(" got: %#v", out)
}
}
}
var (
str11 = "01234567891"
str10 = str11[:10]
str9 = str11[:9]
str5 = str11[:5]
str4 = str11[:4]
)
var splitListForSizeTestCases = []struct {
in []string
out [][]string
size int
}{
{
in: []string{str10},
out: [][]string{{str10}},
size: 10,
},
{
in: []string{str9},
out: [][]string{{str9}},
size: 10,
},
{
in: []string{str5},
out: [][]string{{str5}},
size: 10,
},
{
in: []string{str11},
out: nil,
size: 10,
},
{
in: []string{str10, str10},
out: [][]string{{str10}, {str10}},
size: 10,
},
{
in: []string{str9, str10},
out: [][]string{{str9}, {str10}},
size: 10,
},
{
in: []string{str10, str9},
out: [][]string{{str10}, {str9}},
size: 10,
},
{
in: []string{str5, str4},
out: [][]string{{str5, str4}},
size: 10,
},
{
in: []string{str5, str4, str5},
out: [][]string{{str5, str4}, {str5}},
size: 10,
},
{
in: []string{str5, str4, str5, str4},
out: [][]string{{str5, str4}, {str5, str4}},
size: 10,
},
{
in: []string{str5, str4, str5, str5},
out: [][]string{{str5, str4}, {str5}, {str5}},
size: 10,
},
{
in: []string{str5, str5, str5, str4},
out: [][]string{{str5}, {str5}, {str5, str4}},
size: 10,
},
{
in: []string{str9, str11},
out: nil,
size: 10,
},
{
in: []string{str11, str9},
out: nil,
size: 10,
},
}
func TestSplitListForSize(t *testing.T) {
for _, testCase := range splitListForSizeTestCases {
out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
var outStrings [][]string
if len(out) > 0 {
outStrings = make([][]string, len(out))
for i, o := range out {
outStrings[i] = o.Strings()
}
}
if !reflect.DeepEqual(outStrings, testCase.out) {
t.Errorf("incorrect output:")
t.Errorf(" input: %#v", testCase.in)
t.Errorf(" size: %d", testCase.size)
t.Errorf(" expected: %#v", testCase.out)
t.Errorf(" got: %#v", outStrings)
}
}
}