Merge "Stop android package depending on testing.T being embedded in TestResult"

This commit is contained in:
Paul Duffin
2021-03-12 21:45:39 +00:00
committed by Gerrit Code Review
3 changed files with 29 additions and 30 deletions

View File

@@ -43,7 +43,6 @@ func TestFixtureDedup(t *testing.T) {
extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3) extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3)
h := TestHelper{t} AssertDeepEquals(t, "preparers called in wrong order",
h.AssertDeepEquals("preparers called in wrong order",
[]string{"preparer1", "preparer2", "preparer4", "preparer3"}, list) []string{"preparer1", "preparer2", "preparer4", "preparer3"}, list)
} }

View File

@@ -482,33 +482,33 @@ func TestLicenses(t *testing.T) {
RunTest(t) RunTest(t)
if test.effectiveLicenses != nil { if test.effectiveLicenses != nil {
checkEffectiveLicenses(result, test.effectiveLicenses) checkEffectiveLicenses(t, result, test.effectiveLicenses)
} }
if test.effectivePackage != nil { if test.effectivePackage != nil {
checkEffectivePackage(result, test.effectivePackage) checkEffectivePackage(t, result, test.effectivePackage)
} }
if test.effectiveNotices != nil { if test.effectiveNotices != nil {
checkEffectiveNotices(result, test.effectiveNotices) checkEffectiveNotices(t, result, test.effectiveNotices)
} }
if test.effectiveKinds != nil { if test.effectiveKinds != nil {
checkEffectiveKinds(result, test.effectiveKinds) checkEffectiveKinds(t, result, test.effectiveKinds)
} }
if test.effectiveConditions != nil { if test.effectiveConditions != nil {
checkEffectiveConditions(result, test.effectiveConditions) checkEffectiveConditions(t, result, test.effectiveConditions)
} }
if test.effectiveInheritedLicenses != nil { if test.effectiveInheritedLicenses != nil {
checkEffectiveInheritedLicenses(result, test.effectiveInheritedLicenses) checkEffectiveInheritedLicenses(t, result, test.effectiveInheritedLicenses)
} }
}) })
} }
} }
func checkEffectiveLicenses(result *TestResult, effectiveLicenses map[string][]string) { func checkEffectiveLicenses(t *testing.T, result *TestResult, effectiveLicenses map[string][]string) {
actualLicenses := make(map[string][]string) actualLicenses := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -522,7 +522,7 @@ func checkEffectiveLicenses(result *TestResult, effectiveLicenses map[string][]s
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -538,12 +538,12 @@ func checkEffectiveLicenses(result *TestResult, effectiveLicenses map[string][]s
licenses = []string{} licenses = []string{}
} }
if !compareUnorderedStringArrays(expectedLicenses, licenses) { if !compareUnorderedStringArrays(expectedLicenses, licenses) {
result.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses) t.Errorf("effective licenses mismatch for module %q: expected %q, found %q", moduleName, expectedLicenses, licenses)
} }
} }
} }
func checkEffectiveInheritedLicenses(result *TestResult, effectiveInheritedLicenses map[string][]string) { func checkEffectiveInheritedLicenses(t *testing.T, result *TestResult, effectiveInheritedLicenses map[string][]string) {
actualLicenses := make(map[string][]string) actualLicenses := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -557,7 +557,7 @@ func checkEffectiveInheritedLicenses(result *TestResult, effectiveInheritedLicen
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -580,7 +580,7 @@ func checkEffectiveInheritedLicenses(result *TestResult, effectiveInheritedLicen
} }
cmodule, ok := c.(Module) cmodule, ok := c.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", c.Name()) t.Errorf("%q not a module", c.Name())
return return
} }
cbase := cmodule.base() cbase := cmodule.base()
@@ -603,12 +603,12 @@ func checkEffectiveInheritedLicenses(result *TestResult, effectiveInheritedLicen
licenses = []string{} licenses = []string{}
} }
if !compareUnorderedStringArrays(expectedInheritedLicenses, licenses) { if !compareUnorderedStringArrays(expectedInheritedLicenses, licenses) {
result.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses) t.Errorf("effective inherited licenses mismatch for module %q: expected %q, found %q", moduleName, expectedInheritedLicenses, licenses)
} }
} }
} }
func checkEffectivePackage(result *TestResult, effectivePackage map[string]string) { func checkEffectivePackage(t *testing.T, result *TestResult, effectivePackage map[string]string) {
actualPackage := make(map[string]string) actualPackage := make(map[string]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -622,7 +622,7 @@ func checkEffectivePackage(result *TestResult, effectivePackage map[string]strin
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -643,12 +643,12 @@ func checkEffectivePackage(result *TestResult, effectivePackage map[string]strin
packageName = "" packageName = ""
} }
if expectedPackage != packageName { if expectedPackage != packageName {
result.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName) t.Errorf("effective package mismatch for module %q: expected %q, found %q", moduleName, expectedPackage, packageName)
} }
} }
} }
func checkEffectiveNotices(result *TestResult, effectiveNotices map[string][]string) { func checkEffectiveNotices(t *testing.T, result *TestResult, effectiveNotices map[string][]string) {
actualNotices := make(map[string][]string) actualNotices := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -662,7 +662,7 @@ func checkEffectiveNotices(result *TestResult, effectiveNotices map[string][]str
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -678,12 +678,12 @@ func checkEffectiveNotices(result *TestResult, effectiveNotices map[string][]str
notices = []string{} notices = []string{}
} }
if !compareUnorderedStringArrays(expectedNotices, notices) { if !compareUnorderedStringArrays(expectedNotices, notices) {
result.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices) t.Errorf("effective notice files mismatch for module %q: expected %q, found %q", moduleName, expectedNotices, notices)
} }
} }
} }
func checkEffectiveKinds(result *TestResult, effectiveKinds map[string][]string) { func checkEffectiveKinds(t *testing.T, result *TestResult, effectiveKinds map[string][]string) {
actualKinds := make(map[string][]string) actualKinds := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -697,7 +697,7 @@ func checkEffectiveKinds(result *TestResult, effectiveKinds map[string][]string)
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -713,12 +713,12 @@ func checkEffectiveKinds(result *TestResult, effectiveKinds map[string][]string)
kinds = []string{} kinds = []string{}
} }
if !compareUnorderedStringArrays(expectedKinds, kinds) { if !compareUnorderedStringArrays(expectedKinds, kinds) {
result.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds) t.Errorf("effective license kinds mismatch for module %q: expected %q, found %q", moduleName, expectedKinds, kinds)
} }
} }
} }
func checkEffectiveConditions(result *TestResult, effectiveConditions map[string][]string) { func checkEffectiveConditions(t *testing.T, result *TestResult, effectiveConditions map[string][]string) {
actualConditions := make(map[string][]string) actualConditions := make(map[string][]string)
result.Context.Context.VisitAllModules(func(m blueprint.Module) { result.Context.Context.VisitAllModules(func(m blueprint.Module) {
if _, ok := m.(*licenseModule); ok { if _, ok := m.(*licenseModule); ok {
@@ -732,7 +732,7 @@ func checkEffectiveConditions(result *TestResult, effectiveConditions map[string
} }
module, ok := m.(Module) module, ok := m.(Module)
if !ok { if !ok {
result.Errorf("%q not a module", m.Name()) t.Errorf("%q not a module", m.Name())
return return
} }
base := module.base() base := module.base()
@@ -748,7 +748,7 @@ func checkEffectiveConditions(result *TestResult, effectiveConditions map[string
conditions = []string{} conditions = []string{}
} }
if !compareUnorderedStringArrays(expectedConditions, conditions) { if !compareUnorderedStringArrays(expectedConditions, conditions) {
result.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions) t.Errorf("effective license conditions mismatch for module %q: expected %q, found %q", moduleName, expectedConditions, conditions)
} }
} }
} }

View File

@@ -1166,17 +1166,17 @@ func TestVisibility(t *testing.T) {
RunTest(t) RunTest(t)
if test.effectiveVisibility != nil { if test.effectiveVisibility != nil {
checkEffectiveVisibility(result, test.effectiveVisibility) checkEffectiveVisibility(t, result, test.effectiveVisibility)
} }
}) })
} }
} }
func checkEffectiveVisibility(result *TestResult, effectiveVisibility map[qualifiedModuleName][]string) { func checkEffectiveVisibility(t *testing.T, result *TestResult, effectiveVisibility map[qualifiedModuleName][]string) {
for moduleName, expectedRules := range effectiveVisibility { for moduleName, expectedRules := range effectiveVisibility {
rule := effectiveVisibilityRules(result.Config, moduleName) rule := effectiveVisibilityRules(result.Config, moduleName)
stringRules := rule.Strings() stringRules := rule.Strings()
result.AssertDeepEquals("effective rules mismatch", expectedRules, stringRules) AssertDeepEquals(t, "effective rules mismatch", expectedRules, stringRules)
} }
} }