Merge "Move java test resources in mock filesystem to a different directory"
This commit is contained in:
commit
88c24a38e5
1 changed files with 36 additions and 29 deletions
|
@ -52,10 +52,11 @@ func TestMain(m *testing.M) {
|
||||||
os.Exit(run())
|
os.Exit(run())
|
||||||
}
|
}
|
||||||
func testJava(t *testing.T, bp string) *android.TestContext {
|
func testJava(t *testing.T, bp string) *android.TestContext {
|
||||||
return testJavaWithEnv(t, bp, nil)
|
return testJavaWithEnvFs(t, bp, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJavaWithEnv(t *testing.T, bp string, env map[string]string) *android.TestContext {
|
func testJavaWithEnvFs(t *testing.T, bp string,
|
||||||
|
env map[string]string, fs map[string][]byte) *android.TestContext {
|
||||||
config := android.TestArchConfig(buildDir, env)
|
config := android.TestArchConfig(buildDir, env)
|
||||||
|
|
||||||
ctx := android.NewTestArchContext()
|
ctx := android.NewTestArchContext()
|
||||||
|
@ -112,17 +113,17 @@ func testJavaWithEnv(t *testing.T, bp string, env map[string]string) *android.Te
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.MockFileSystem(map[string][]byte{
|
mockFS := map[string][]byte{
|
||||||
"Android.bp": []byte(bp),
|
"Android.bp": []byte(bp),
|
||||||
"a.java": nil,
|
"a.java": nil,
|
||||||
"b.java": nil,
|
"b.java": nil,
|
||||||
"c.java": nil,
|
"c.java": nil,
|
||||||
"b.kt": nil,
|
"b.kt": nil,
|
||||||
"a.jar": nil,
|
"a.jar": nil,
|
||||||
"b.jar": nil,
|
"b.jar": nil,
|
||||||
"res/a": nil,
|
"java-res/a": nil,
|
||||||
"res/b": nil,
|
"java-res/b": nil,
|
||||||
"res2/a": nil,
|
"java-res2/a": nil,
|
||||||
|
|
||||||
"prebuilts/sdk/14/android.jar": nil,
|
"prebuilts/sdk/14/android.jar": nil,
|
||||||
"prebuilts/sdk/14/framework.aidl": nil,
|
"prebuilts/sdk/14/framework.aidl": nil,
|
||||||
|
@ -132,7 +133,13 @@ func testJavaWithEnv(t *testing.T, bp string, env map[string]string) *android.Te
|
||||||
"prebuilts/sdk/system_current/framework.aidl": nil,
|
"prebuilts/sdk/system_current/framework.aidl": nil,
|
||||||
"prebuilts/sdk/test_current/android.jar": nil,
|
"prebuilts/sdk/test_current/android.jar": nil,
|
||||||
"prebuilts/sdk/test_current/framework.aidl": nil,
|
"prebuilts/sdk/test_current/framework.aidl": nil,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
for k, v := range fs {
|
||||||
|
mockFS[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.MockFileSystem(mockFS)
|
||||||
|
|
||||||
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
||||||
fail(t, errs)
|
fail(t, errs)
|
||||||
|
@ -394,7 +401,7 @@ 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 := testJavaWithEnv(t, bp, map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"})
|
ctx := testJavaWithEnvFs(t, bp, map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"}, nil)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
javac := ctx.ModuleForTests("foo", variant).Rule("javac")
|
||||||
got := javac.Args["bootClasspath"]
|
got := javac.Args["bootClasspath"]
|
||||||
|
@ -497,14 +504,14 @@ func TestResources(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Test that a module with java_resource_dirs includes the files
|
// Test that a module with java_resource_dirs includes the files
|
||||||
name: "resource dirs",
|
name: "resource dirs",
|
||||||
prop: `java_resource_dirs: ["res"]`,
|
prop: `java_resource_dirs: ["java-res"]`,
|
||||||
args: "-C res -f res/a -f res/b",
|
args: "-C java-res -f java-res/a -f java-res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with java_resources includes the files
|
// Test that a module with java_resources includes the files
|
||||||
name: "resource files",
|
name: "resource files",
|
||||||
prop: `java_resources: ["res/a", "res/b"]`,
|
prop: `java_resources: ["java-res/a", "java-res/b"]`,
|
||||||
args: "-C . -f res/a -f res/b",
|
args: "-C . -f java-res/a -f java-res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with a filegroup in java_resources includes the files with the
|
// Test that a module with a filegroup in java_resources includes the files with the
|
||||||
|
@ -514,10 +521,10 @@ func TestResources(t *testing.T) {
|
||||||
extra: `
|
extra: `
|
||||||
filegroup {
|
filegroup {
|
||||||
name: "foo-res",
|
name: "foo-res",
|
||||||
path: "res",
|
path: "java-res",
|
||||||
srcs: ["res/a", "res/b"],
|
srcs: ["java-res/a", "java-res/b"],
|
||||||
}`,
|
}`,
|
||||||
args: "-C res -f res/a -f res/b",
|
args: "-C java-res -f java-res/a -f java-res/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test that a module with "include_srcs: true" includes its source files in the resources jar
|
// Test that a module with "include_srcs: true" includes its source files in the resources jar
|
||||||
|
@ -562,21 +569,21 @@ func TestExcludeResources(t *testing.T) {
|
||||||
java_library {
|
java_library {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
java_resource_dirs: ["res", "res2"],
|
java_resource_dirs: ["java-res", "java-res2"],
|
||||||
exclude_java_resource_dirs: ["res2"],
|
exclude_java_resource_dirs: ["java-res2"],
|
||||||
}
|
}
|
||||||
|
|
||||||
java_library {
|
java_library {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
java_resources: ["res/*"],
|
java_resources: ["java-res/*"],
|
||||||
exclude_java_resources: ["res/b"],
|
exclude_java_resources: ["java-res/b"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
|
||||||
|
|
||||||
expected := "-C res -f res/a -f res/b"
|
expected := "-C java-res -f java-res/a -f java-res/b"
|
||||||
if fooRes.Args["jarArgs"] != expected {
|
if fooRes.Args["jarArgs"] != expected {
|
||||||
t.Errorf("foo resource jar args %q is not %q",
|
t.Errorf("foo resource jar args %q is not %q",
|
||||||
fooRes.Args["jarArgs"], expected)
|
fooRes.Args["jarArgs"], expected)
|
||||||
|
@ -585,7 +592,7 @@ func TestExcludeResources(t *testing.T) {
|
||||||
|
|
||||||
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
|
||||||
|
|
||||||
expected = "-C . -f res/a"
|
expected = "-C . -f java-res/a"
|
||||||
if barRes.Args["jarArgs"] != expected {
|
if barRes.Args["jarArgs"] != expected {
|
||||||
t.Errorf("bar resource jar args %q is not %q",
|
t.Errorf("bar resource jar args %q is not %q",
|
||||||
barRes.Args["jarArgs"], expected)
|
barRes.Args["jarArgs"], expected)
|
||||||
|
@ -606,7 +613,7 @@ func TestGeneratedSources(t *testing.T) {
|
||||||
|
|
||||||
genrule {
|
genrule {
|
||||||
name: "gen",
|
name: "gen",
|
||||||
tool_files: ["res/a"],
|
tool_files: ["java-res/a"],
|
||||||
out: ["gen.java"],
|
out: ["gen.java"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
Loading…
Reference in a new issue