diff --git a/context.go b/context.go index 4ca4ef8..e1bd892 100644 --- a/context.go +++ b/context.go @@ -323,10 +323,10 @@ func (vm variationMap) clone() variationMap { } // Compare this variationMap to another one. Returns true if the every entry in this map -// is either the same in the other map or doesn't exist in the other map. -func (vm variationMap) subset(other variationMap) bool { +// exists and has the same value in the other map. +func (vm variationMap) subsetOf(other variationMap) bool { for k, v1 := range vm { - if v2, ok := other[k]; ok && v1 != v2 { + if v2, ok := other[k]; !ok || v1 != v2 { return false } } @@ -1687,7 +1687,7 @@ func findVariant(module *moduleInfo, possibleDeps *moduleGroup, variations []Var check := func(variant variationMap) bool { if far { - return variant.subset(newVariant) + return newVariant.subsetOf(variant) } else { return variant.equal(newVariant) } diff --git a/context_test.go b/context_test.go index b33c7bf..91089e6 100644 --- a/context_test.go +++ b/context_test.go @@ -738,6 +738,12 @@ func Test_findVariant(t *testing.T) { name: "AddFarVariationDependencies(far)", // A dependency with far variations possibleDeps: makeDependencyGroup( + &moduleInfo{ + variant: variant{ + name: "", + variations: nil, + }, + }, &moduleInfo{ variant: variant{ name: "far", @@ -789,12 +795,45 @@ func Test_findVariant(t *testing.T) { reverse: false, want: "far_b", }, + { + name: "AddFarVariationDependencies(far, b) to missing", + // A dependency with far variations and aliases + possibleDeps: makeDependencyGroup( + alias{ + variant: variant{ + name: "far", + variations: variationMap{ + "far": "far", + }, + }, + target: 1, + }, + &moduleInfo{ + variant: variant{ + name: "far_a", + variations: variationMap{ + "far": "far", + "a": "a", + }, + }, + }, + ), + variations: []Variation{{"far", "far"}, {"a", "b"}}, + far: true, + reverse: false, + want: "nil", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, _ := findVariant(module, tt.possibleDeps, tt.variations, tt.far, tt.reverse) - if g, w := got.String(), fmt.Sprintf("module %q variant %q", "dep", tt.want); g != w { - t.Errorf("findVariant() got = %v, want %v", g, w) + if g, w := got == nil, tt.want == "nil"; g != w { + t.Fatalf("findVariant() got = %v, want %v", got, tt.want) + } + if got != nil { + if g, w := got.String(), fmt.Sprintf("module %q variant %q", "dep", tt.want); g != w { + t.Errorf("findVariant() got = %v, want %v", g, w) + } } }) }