Convert remaining rust tests to use test fixtures
Removes now unused CreateTestContext and stops exporting the RegisterRequiredBuildComponentsForTest() method as it is only used locally. Bug: 181070625 Test: m nothing Change-Id: Ia2fd3e090f975ee4c807da2c6c162ef3cf7ac446
This commit is contained in:
parent
dd3797b44e
commit
9e0c3f9993
|
@ -18,7 +18,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClippy(t *testing.T) {
|
func TestClippy(t *testing.T) {
|
||||||
|
@ -45,15 +44,6 @@ func TestClippy(t *testing.T) {
|
||||||
clippy_lints: "none",
|
clippy_lints: "none",
|
||||||
}`
|
}`
|
||||||
|
|
||||||
bp = bp + GatherRequiredDepsForTest()
|
|
||||||
bp = bp + cc.GatherRequiredDepsForTest(android.NoOsType)
|
|
||||||
|
|
||||||
fs := map[string][]byte{
|
|
||||||
// Reuse the same blueprint file for subdirectories.
|
|
||||||
"external/Android.bp": []byte(bp),
|
|
||||||
"hardware/Android.bp": []byte(bp),
|
|
||||||
}
|
|
||||||
|
|
||||||
var clippyLintTests = []struct {
|
var clippyLintTests = []struct {
|
||||||
modulePath string
|
modulePath string
|
||||||
fooFlags string
|
fooFlags string
|
||||||
|
@ -66,29 +56,22 @@ func TestClippy(t *testing.T) {
|
||||||
for _, tc := range clippyLintTests {
|
for _, tc := range clippyLintTests {
|
||||||
t.Run("path="+tc.modulePath, func(t *testing.T) {
|
t.Run("path="+tc.modulePath, func(t *testing.T) {
|
||||||
|
|
||||||
config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
|
result := android.GroupFixturePreparers(
|
||||||
ctx := CreateTestContext(config)
|
prepareForRustTest,
|
||||||
ctx.Register()
|
// Test with the blueprint file in different directories.
|
||||||
_, errs := ctx.ParseFileList(".", []string{tc.modulePath + "Android.bp"})
|
android.FixtureAddTextFile(tc.modulePath+"Android.bp", bp),
|
||||||
android.FailIfErrored(t, errs)
|
).RunTest(t)
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
r := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||||
if r.Args["clippyFlags"] != tc.fooFlags {
|
android.AssertStringEquals(t, "libfoo flags", tc.fooFlags, r.Args["clippyFlags"])
|
||||||
t.Errorf("Incorrect flags for libfoo: %q, want %q", r.Args["clippyFlags"], tc.fooFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
r = ctx.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||||
if r.Args["clippyFlags"] != "${config.ClippyDefaultLints}" {
|
android.AssertStringEquals(t, "libbar flags", "${config.ClippyDefaultLints}", r.Args["clippyFlags"])
|
||||||
t.Errorf("Incorrect flags for libbar: %q, want %q", r.Args["clippyFlags"], "${config.ClippyDefaultLints}")
|
|
||||||
}
|
|
||||||
|
|
||||||
r = ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
|
||||||
if r.Rule != nil {
|
if r.Rule != nil {
|
||||||
t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"])
|
t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"])
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test that feature flags are being correctly generated.
|
// Test that feature flags are being correctly generated.
|
||||||
|
@ -132,15 +131,6 @@ func TestLints(t *testing.T) {
|
||||||
lints: "none",
|
lints: "none",
|
||||||
}`
|
}`
|
||||||
|
|
||||||
bp = bp + GatherRequiredDepsForTest()
|
|
||||||
bp = bp + cc.GatherRequiredDepsForTest(android.NoOsType)
|
|
||||||
|
|
||||||
fs := map[string][]byte{
|
|
||||||
// Reuse the same blueprint file for subdirectories.
|
|
||||||
"external/Android.bp": []byte(bp),
|
|
||||||
"hardware/Android.bp": []byte(bp),
|
|
||||||
}
|
|
||||||
|
|
||||||
var lintTests = []struct {
|
var lintTests = []struct {
|
||||||
modulePath string
|
modulePath string
|
||||||
fooFlags string
|
fooFlags string
|
||||||
|
@ -153,29 +143,20 @@ func TestLints(t *testing.T) {
|
||||||
for _, tc := range lintTests {
|
for _, tc := range lintTests {
|
||||||
t.Run("path="+tc.modulePath, func(t *testing.T) {
|
t.Run("path="+tc.modulePath, func(t *testing.T) {
|
||||||
|
|
||||||
config := android.TestArchConfig(t.TempDir(), nil, bp, fs)
|
result := android.GroupFixturePreparers(
|
||||||
ctx := CreateTestContext(config)
|
prepareForRustTest,
|
||||||
ctx.Register()
|
// Test with the blueprint file in different directories.
|
||||||
_, errs := ctx.ParseFileList(".", []string{tc.modulePath + "Android.bp"})
|
android.FixtureAddTextFile(tc.modulePath+"Android.bp", bp),
|
||||||
android.FailIfErrored(t, errs)
|
).RunTest(t)
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
|
||||||
android.FailIfErrored(t, errs)
|
|
||||||
|
|
||||||
r := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||||
if !strings.Contains(r.Args["rustcFlags"], tc.fooFlags) {
|
android.AssertStringDoesContain(t, "libfoo flags", r.Args["rustcFlags"], tc.fooFlags)
|
||||||
t.Errorf("Incorrect flags for libfoo: %q, want %q", r.Args["rustcFlags"], tc.fooFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
r = ctx.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||||
if !strings.Contains(r.Args["rustcFlags"], "${config.RustDefaultLints}") {
|
android.AssertStringDoesContain(t, "libbar flags", r.Args["rustcFlags"], "${config.RustDefaultLints}")
|
||||||
t.Errorf("Incorrect flags for libbar: %q, want %q", r.Args["rustcFlags"], "${config.RustDefaultLints}")
|
|
||||||
}
|
|
||||||
|
|
||||||
r = ctx.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
|
||||||
if !strings.Contains(r.Args["rustcFlags"], "${config.RustAllowAllLints}") {
|
|
||||||
t.Errorf("Incorrect flags for libfoobar: %q, want %q", r.Args["rustcFlags"], "${config.RustAllowAllLints}")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("rustc")
|
||||||
|
android.AssertStringDoesContain(t, "libfoobar flags", r.Args["rustcFlags"], "${config.RustAllowAllLints}")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,12 @@ package rust
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
"android/soong/genrule"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Preparer that will define all cc module types and a limited set of mutators and singletons that
|
// Preparer that will define all cc module types and a limited set of mutators and singletons that
|
||||||
// make those module types usable.
|
// make those module types usable.
|
||||||
var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
|
var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
|
||||||
android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
|
android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
|
||||||
)
|
)
|
||||||
|
|
||||||
// The directory in which rust test default modules will be defined.
|
// The directory in which rust test default modules will be defined.
|
||||||
|
@ -197,7 +196,7 @@ func GatherRequiredDepsForTest() string {
|
||||||
return bp
|
return bp
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
||||||
ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
|
ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
|
||||||
ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
|
ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
|
||||||
ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
|
ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
|
||||||
|
@ -231,14 +230,3 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
|
||||||
})
|
})
|
||||||
ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
|
ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTestContext(config android.Config) *android.TestContext {
|
|
||||||
ctx := android.NewTestArchContext(config)
|
|
||||||
android.RegisterPrebuiltMutators(ctx)
|
|
||||||
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
|
||||||
genrule.RegisterGenruleBuildComponents(ctx)
|
|
||||||
cc.RegisterRequiredBuildComponentsForTest(ctx)
|
|
||||||
RegisterRequiredBuildComponentsForTest(ctx)
|
|
||||||
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue