Split up testJavaWithEnvFs
Instead of passing all the options to testJavaWithEnvFs, split it up into testConfig, testContext, and run. Tests that don't need any special options can continue to use testJava, more complicated tests can call the three functions manually. This gives more flexibility in complicated tests for the next patch. Test: soong java tests Change-Id: Ifd5dcb40cf08e4cbf69bf8e02c5698adbfbcdcb3
This commit is contained in:
@@ -34,14 +34,27 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func testApp(t *testing.T, bp string) *android.TestContext {
|
func testAppContext(config android.Config, bp string, fs map[string][]byte) *android.TestContext {
|
||||||
appFs := map[string][]byte{}
|
appFS := map[string][]byte{}
|
||||||
|
for k, v := range fs {
|
||||||
for _, file := range resourceFiles {
|
appFS[k] = v
|
||||||
appFs[file] = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return testJavaWithEnvFs(t, bp, nil, appFs)
|
for _, file := range resourceFiles {
|
||||||
|
appFS[file] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return testContext(config, bp, appFS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testApp(t *testing.T, bp string) *android.TestContext {
|
||||||
|
config := testConfig(nil)
|
||||||
|
|
||||||
|
ctx := testAppContext(config, bp, nil)
|
||||||
|
|
||||||
|
run(t, ctx, config)
|
||||||
|
|
||||||
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestApp(t *testing.T) {
|
func TestApp(t *testing.T) {
|
||||||
|
@@ -51,13 +51,14 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
os.Exit(run())
|
os.Exit(run())
|
||||||
}
|
}
|
||||||
func testJava(t *testing.T, bp string) *android.TestContext {
|
|
||||||
return testJavaWithEnvFs(t, bp, nil, nil)
|
func testConfig(env map[string]string) android.Config {
|
||||||
|
return android.TestArchConfig(buildDir, env)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJavaWithEnvFs(t *testing.T, bp string,
|
func testContext(config android.Config, bp string,
|
||||||
env map[string]string, fs map[string][]byte) *android.TestContext {
|
fs map[string][]byte) *android.TestContext {
|
||||||
config := android.TestArchConfig(buildDir, env)
|
|
||||||
|
|
||||||
ctx := android.NewTestArchContext()
|
ctx := android.NewTestArchContext()
|
||||||
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
|
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
|
||||||
@@ -104,21 +105,19 @@ func testJavaWithEnvFs(t *testing.T, bp string,
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
if config.TargetOpenJDK9() {
|
systemModules := []string{
|
||||||
systemModules := []string{
|
"core-system-modules",
|
||||||
"core-system-modules",
|
"android_stubs_current_system_modules",
|
||||||
"android_stubs_current_system_modules",
|
"android_system_stubs_current_system_modules",
|
||||||
"android_system_stubs_current_system_modules",
|
"android_test_stubs_current_system_modules",
|
||||||
"android_test_stubs_current_system_modules",
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, extra := range systemModules {
|
for _, extra := range systemModules {
|
||||||
bp += fmt.Sprintf(`
|
bp += fmt.Sprintf(`
|
||||||
java_system_modules {
|
java_system_modules {
|
||||||
name: "%s",
|
name: "%s",
|
||||||
}
|
}
|
||||||
`, extra)
|
`, extra)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mockFS := map[string][]byte{
|
mockFS := map[string][]byte{
|
||||||
@@ -155,10 +154,20 @@ func testJavaWithEnvFs(t *testing.T, bp string,
|
|||||||
|
|
||||||
ctx.MockFileSystem(mockFS)
|
ctx.MockFileSystem(mockFS)
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
fail(t, errs)
|
fail(t, errs)
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
_, errs = ctx.PrepareBuildActions(config)
|
||||||
fail(t, errs)
|
fail(t, errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJava(t *testing.T, bp string) *android.TestContext {
|
||||||
|
config := testConfig(nil)
|
||||||
|
ctx := testContext(config, bp, nil)
|
||||||
|
run(t, ctx, config)
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
@@ -423,7 +432,9 @@ func TestClasspath(t *testing.T) {
|
|||||||
|
|
||||||
// Test again with javac 1.9
|
// Test again with javac 1.9
|
||||||
t.Run("1.9", func(t *testing.T) {
|
t.Run("1.9", func(t *testing.T) {
|
||||||
ctx := testJavaWithEnvFs(t, bp, map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"}, nil)
|
config := testConfig(map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"})
|
||||||
|
ctx := testContext(config, bp, nil)
|
||||||
|
run(t, ctx, config)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
||||||
got := javac.Args["bootClasspath"]
|
got := javac.Args["bootClasspath"]
|
||||||
|
Reference in New Issue
Block a user