Migrate from result methods to function Asserts
Bug: 181070625 Test: m nothing Change-Id: Iadb85270290acb52c55f2ad70c9f145f1c34b611
This commit is contained in:
@@ -745,19 +745,3 @@ func (r *TestResult) NormalizePathsForTesting(paths Paths) []string {
|
|||||||
func (r *TestResult) Module(name string, variant string) Module {
|
func (r *TestResult) Module(name string, variant string) Module {
|
||||||
return r.ModuleForTests(name, variant).Module()
|
return r.ModuleForTests(name, variant).Module()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a *TestResult object suitable for use within a subtest.
|
|
||||||
//
|
|
||||||
// This ensures that any errors reported by the TestResult, e.g. from within one of its
|
|
||||||
// Assert... methods, will be associated with the sub test and not the main test.
|
|
||||||
//
|
|
||||||
// result := ....RunTest()
|
|
||||||
// t.Run("subtest", func(t *testing.T) {
|
|
||||||
// subResult := result.ResultForSubTest(t)
|
|
||||||
// subResult.AssertStringEquals("something", ....)
|
|
||||||
// })
|
|
||||||
func (r *TestResult) ResultForSubTest(t *testing.T) *TestResult {
|
|
||||||
subTestResult := *r
|
|
||||||
r.T = t
|
|
||||||
return &subTestResult
|
|
||||||
}
|
|
||||||
|
@@ -222,7 +222,7 @@ func TestFuchsiaTargetDecl(t *testing.T) {
|
|||||||
for _, o := range ld.Inputs {
|
for _, o := range ld.Inputs {
|
||||||
objs = append(objs, o.Base())
|
objs = append(objs, o.Base())
|
||||||
}
|
}
|
||||||
result.AssertArrayString("libTest inputs", []string{"foo.o", "bar.o"}, objs)
|
android.AssertArrayString(t, "libTest inputs", []string{"foo.o", "bar.o"}, objs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVendorSrc(t *testing.T) {
|
func TestVendorSrc(t *testing.T) {
|
||||||
@@ -3429,7 +3429,7 @@ func TestProductVariableDefaults(t *testing.T) {
|
|||||||
).RunTestWithBp(t, bp)
|
).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
|
libfoo := result.Module("libfoo", "android_arm64_armv8-a_static").(*Module)
|
||||||
result.AssertStringListContains("cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
|
android.AssertStringListContains(t, "cppflags", libfoo.flags.Local.CppFlags, "-DBAR")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
|
func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
|
||||||
@@ -3452,12 +3452,12 @@ func TestEmptyWholeStaticLibsAllowMissingDependencies(t *testing.T) {
|
|||||||
).RunTestWithBp(t, bp)
|
).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
|
libbar := result.ModuleForTests("libbar", "android_arm64_armv8-a_static").Output("libbar.a")
|
||||||
result.AssertDeepEquals("libbar rule", android.ErrorRule, libbar.Rule)
|
android.AssertDeepEquals(t, "libbar rule", android.ErrorRule, libbar.Rule)
|
||||||
|
|
||||||
result.AssertStringDoesContain("libbar error", libbar.Args["error"], "missing dependencies: libmissing")
|
android.AssertStringDoesContain(t, "libbar error", libbar.Args["error"], "missing dependencies: libmissing")
|
||||||
|
|
||||||
libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
|
libfoo := result.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Output("libfoo.a")
|
||||||
result.AssertStringListContains("libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
|
android.AssertStringListContains(t, "libfoo.a dependencies", libfoo.Inputs.Strings(), libbar.Output.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInstallSharedLibs(t *testing.T) {
|
func TestInstallSharedLibs(t *testing.T) {
|
||||||
|
@@ -103,7 +103,7 @@ func TestPrebuiltEtcOutputPath(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
result.AssertStringEquals("output file path", "foo.installed.conf", p.outputFilePath.Base())
|
android.AssertStringEquals(t, "output file path", "foo.installed.conf", p.outputFilePath.Base())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcGlob(t *testing.T) {
|
func TestPrebuiltEtcGlob(t *testing.T) {
|
||||||
@@ -120,10 +120,10 @@ func TestPrebuiltEtcGlob(t *testing.T) {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("my_foo", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
result.AssertStringEquals("my_foo output file path", "my_foo", p.outputFilePath.Base())
|
android.AssertStringEquals(t, "my_foo output file path", "my_foo", p.outputFilePath.Base())
|
||||||
|
|
||||||
p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p = result.Module("my_bar", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
result.AssertStringEquals("my_bar output file path", "bar.conf", p.outputFilePath.Base())
|
android.AssertStringEquals(t, "my_bar output file path", "bar.conf", p.outputFilePath.Base())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
||||||
@@ -153,7 +153,7 @@ func TestPrebuiltEtcAndroidMk(t *testing.T) {
|
|||||||
entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
|
entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0]
|
||||||
for k, expectedValue := range expected {
|
for k, expectedValue := range expected {
|
||||||
if value, ok := entries.EntryMap[k]; ok {
|
if value, ok := entries.EntryMap[k]; ok {
|
||||||
result.AssertDeepEquals(k, expectedValue, value)
|
android.AssertDeepEquals(t, k, expectedValue, value)
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
|
t.Errorf("No %s defined, saw %q", k, entries.EntryMap)
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ func TestPrebuiltEtcRelativeInstallPathInstallDirPath(t *testing.T) {
|
|||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/etc/bar"
|
expected := buildDir + "/target/product/test_device/system/etc/bar"
|
||||||
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
func TestPrebuiltEtcCannotSetRelativeInstallPathAndSubDir(t *testing.T) {
|
||||||
@@ -213,7 +213,7 @@ func TestPrebuiltUserShareInstallDirPath(t *testing.T) {
|
|||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
expected := buildDir + "/target/product/test_device/system/usr/share/bar"
|
||||||
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
||||||
@@ -228,7 +228,7 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
|
|||||||
buildOS := android.BuildOs.String()
|
buildOS := android.BuildOs.String()
|
||||||
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
p := result.Module("foo.conf", buildOS+"_common").(*PrebuiltEtc)
|
||||||
expected := filepath.Join(buildDir, "host", result.Config.PrebuiltOS(), "usr", "share", "bar")
|
expected := filepath.Join(buildDir, "host", result.Config.PrebuiltOS(), "usr", "share", "bar")
|
||||||
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
||||||
@@ -241,7 +241,7 @@ func TestPrebuiltFontInstallDirPath(t *testing.T) {
|
|||||||
|
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
expected := buildDir + "/target/product/test_device/system/fonts"
|
expected := buildDir + "/target/product/test_device/system/fonts"
|
||||||
result.AssertStringEquals("install dir", expected, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", expected, p.installDirPath.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
||||||
@@ -273,7 +273,7 @@ func TestPrebuiltFirmwareDirPath(t *testing.T) {
|
|||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ func TestPrebuiltDSPDirPath(t *testing.T) {
|
|||||||
t.Run(tt.description, func(t *testing.T) {
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
result := prebuiltEtcFixtureFactory.RunTestWithBp(t, tt.config)
|
||||||
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
p := result.Module("foo.conf", "android_arm64_armv8-a").(*PrebuiltEtc)
|
||||||
result.AssertStringEquals("install dir", tt.expectedPath, p.installDirPath.String())
|
android.AssertStringEquals(t, "install dir", tt.expectedPath, p.installDirPath.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -477,7 +477,7 @@ func TestGenruleCmd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gen := result.Module("gen", "").(*Module)
|
gen := result.Module("gen", "").(*Module)
|
||||||
result.AssertStringEquals("raw commands", test.expect, gen.rawCommands[0])
|
android.AssertStringEquals(t, "raw commands", test.expect, gen.rawCommands[0])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,12 +541,11 @@ func TestGenruleHashInputs(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range testcases {
|
for _, test := range testcases {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
subResult := result.ResultForSubTest(t)
|
gen := result.ModuleForTests(test.name, "")
|
||||||
gen := subResult.ModuleForTests(test.name, "")
|
|
||||||
manifest := android.RuleBuilderSboxProtoForTests(t, gen.Output("genrule.sbox.textproto"))
|
manifest := android.RuleBuilderSboxProtoForTests(t, gen.Output("genrule.sbox.textproto"))
|
||||||
hash := manifest.Commands[0].GetInputHash()
|
hash := manifest.Commands[0].GetInputHash()
|
||||||
|
|
||||||
subResult.AssertStringEquals("hash", test.expectedHash, hash)
|
android.AssertStringEquals(t, "hash", test.expectedHash, hash)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -615,11 +614,11 @@ func TestGenSrcs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gen := result.Module("gen", "").(*Module)
|
gen := result.Module("gen", "").(*Module)
|
||||||
result.AssertDeepEquals("cmd", test.cmds, gen.rawCommands)
|
android.AssertDeepEquals(t, "cmd", test.cmds, gen.rawCommands)
|
||||||
|
|
||||||
result.AssertDeepEquals("deps", test.deps, gen.outputDeps.Strings())
|
android.AssertDeepEquals(t, "deps", test.deps, gen.outputDeps.Strings())
|
||||||
|
|
||||||
result.AssertDeepEquals("files", test.files, gen.outputFiles.Strings())
|
android.AssertDeepEquals(t, "files", test.files, gen.outputFiles.Strings())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -648,10 +647,10 @@ func TestGenruleDefaults(t *testing.T) {
|
|||||||
gen := result.Module("gen", "").(*Module)
|
gen := result.Module("gen", "").(*Module)
|
||||||
|
|
||||||
expectedCmd := "cp in1 __SBOX_SANDBOX_DIR__/out/out"
|
expectedCmd := "cp in1 __SBOX_SANDBOX_DIR__/out/out"
|
||||||
result.AssertStringEquals("cmd", expectedCmd, gen.rawCommands[0])
|
android.AssertStringEquals(t, "cmd", expectedCmd, gen.rawCommands[0])
|
||||||
|
|
||||||
expectedSrcs := []string{"in1"}
|
expectedSrcs := []string{"in1"}
|
||||||
result.AssertDeepEquals("srcs", expectedSrcs, gen.properties.Srcs)
|
android.AssertDeepEquals(t, "srcs", expectedSrcs, gen.properties.Srcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenruleWithBazel(t *testing.T) {
|
func TestGenruleWithBazel(t *testing.T) {
|
||||||
@@ -673,8 +672,8 @@ func TestGenruleWithBazel(t *testing.T) {
|
|||||||
|
|
||||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/bazelone.txt",
|
expectedOutputFiles := []string{"outputbase/execroot/__main__/bazelone.txt",
|
||||||
"outputbase/execroot/__main__/bazeltwo.txt"}
|
"outputbase/execroot/__main__/bazeltwo.txt"}
|
||||||
result.AssertDeepEquals("output files", expectedOutputFiles, gen.outputFiles.Strings())
|
android.AssertDeepEquals(t, "output files", expectedOutputFiles, gen.outputFiles.Strings())
|
||||||
result.AssertDeepEquals("output deps", expectedOutputFiles, gen.outputDeps.Strings())
|
android.AssertDeepEquals(t, "output deps", expectedOutputFiles, gen.outputDeps.Strings())
|
||||||
}
|
}
|
||||||
|
|
||||||
type testTool struct {
|
type testTool struct {
|
||||||
|
@@ -58,7 +58,7 @@ func TestJavaSystemModules(t *testing.T) {
|
|||||||
|
|
||||||
// The expected paths are the header jars from the source input modules.
|
// The expected paths are the header jars from the source input modules.
|
||||||
expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
||||||
result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
|
android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
|
||||||
}
|
}
|
||||||
|
|
||||||
var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", `
|
var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", `
|
||||||
@@ -85,7 +85,7 @@ func TestJavaSystemModulesImport(t *testing.T) {
|
|||||||
|
|
||||||
// The expected paths are the header jars from the renamed prebuilt input modules.
|
// The expected paths are the header jars from the renamed prebuilt input modules.
|
||||||
expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
||||||
result.AssertArrayString("renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
|
android.AssertArrayString(t, "renamed prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
|
func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
|
||||||
@@ -100,7 +100,7 @@ func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
|
|||||||
|
|
||||||
// The expected paths are the header jars from the source input modules.
|
// The expected paths are the header jars from the source input modules.
|
||||||
expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
expectedSourcePaths := getModuleHeaderJarsAsNormalizedPaths(result, "system-module1", "system-module2")
|
||||||
result.AssertArrayString("source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
|
android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, result.NormalizePathsForTesting(sourceInputs))
|
||||||
|
|
||||||
// check the existence of the renamed prebuilt module
|
// check the existence of the renamed prebuilt module
|
||||||
prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common")
|
prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common")
|
||||||
@@ -108,5 +108,5 @@ func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
|
|||||||
|
|
||||||
// The expected paths are the header jars from the renamed prebuilt input modules.
|
// The expected paths are the header jars from the renamed prebuilt input modules.
|
||||||
expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "prebuilt_system-module1", "prebuilt_system-module2")
|
expectedPrebuiltPaths := getModuleHeaderJarsAsNormalizedPaths(result, "prebuilt_system-module1", "prebuilt_system-module2")
|
||||||
result.AssertArrayString("prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
|
android.AssertArrayString(t, "prebuilt system modules inputs", expectedPrebuiltPaths, result.NormalizePathsForTesting(prebuiltInputs))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user