Move Java lint tests to lint_test.go
Test: lint_test.go Bug: 182349282 Change-Id: I30a46c8f704e66cd04541c78d3f22a140d3284ef
This commit is contained in:
@@ -1203,107 +1203,6 @@ func TestIncludeSrcs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJavaLint(t *testing.T) {
|
|
||||||
ctx, _ := testJavaWithFS(t, `
|
|
||||||
java_library {
|
|
||||||
name: "foo",
|
|
||||||
srcs: [
|
|
||||||
"a.java",
|
|
||||||
"b.java",
|
|
||||||
"c.java",
|
|
||||||
],
|
|
||||||
min_sdk_version: "29",
|
|
||||||
sdk_version: "system_current",
|
|
||||||
}
|
|
||||||
`, map[string][]byte{
|
|
||||||
"lint-baseline.xml": nil,
|
|
||||||
})
|
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "android_common")
|
|
||||||
|
|
||||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
|
||||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") {
|
|
||||||
t.Error("did not pass --baseline flag")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJavaLintWithoutBaseline(t *testing.T) {
|
|
||||||
ctx, _ := testJavaWithFS(t, `
|
|
||||||
java_library {
|
|
||||||
name: "foo",
|
|
||||||
srcs: [
|
|
||||||
"a.java",
|
|
||||||
"b.java",
|
|
||||||
"c.java",
|
|
||||||
],
|
|
||||||
min_sdk_version: "29",
|
|
||||||
sdk_version: "system_current",
|
|
||||||
}
|
|
||||||
`, map[string][]byte{})
|
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "android_common")
|
|
||||||
|
|
||||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
|
||||||
if strings.Contains(*sboxProto.Commands[0].Command, "--baseline") {
|
|
||||||
t.Error("passed --baseline flag for non existent file")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) {
|
|
||||||
android.GroupFixturePreparers(
|
|
||||||
PrepareForTestWithJavaDefaultModules,
|
|
||||||
android.PrepareForTestDisallowNonExistentPaths,
|
|
||||||
).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern([]string{`source path "mybaseline.xml" does not exist`})).
|
|
||||||
RunTestWithBp(t, `
|
|
||||||
java_library {
|
|
||||||
name: "foo",
|
|
||||||
srcs: [
|
|
||||||
],
|
|
||||||
min_sdk_version: "29",
|
|
||||||
sdk_version: "system_current",
|
|
||||||
lint: {
|
|
||||||
baseline_filename: "mybaseline.xml",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestJavaLintUsesCorrectBpConfig(t *testing.T) {
|
|
||||||
ctx, _ := testJavaWithFS(t, `
|
|
||||||
java_library {
|
|
||||||
name: "foo",
|
|
||||||
srcs: [
|
|
||||||
"a.java",
|
|
||||||
"b.java",
|
|
||||||
"c.java",
|
|
||||||
],
|
|
||||||
min_sdk_version: "29",
|
|
||||||
sdk_version: "system_current",
|
|
||||||
lint: {
|
|
||||||
error_checks: ["SomeCheck"],
|
|
||||||
baseline_filename: "mybaseline.xml",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
`, map[string][]byte{
|
|
||||||
"mybaseline.xml": nil,
|
|
||||||
})
|
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "android_common")
|
|
||||||
|
|
||||||
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
|
||||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") {
|
|
||||||
t.Error("did not use the correct file for baseline")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") {
|
|
||||||
t.Error("should check NewApi errors")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check SomeCheck") {
|
|
||||||
t.Error("should combine NewApi errors with SomeCheck errors")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGeneratedSources(t *testing.T) {
|
func TestGeneratedSources(t *testing.T) {
|
||||||
ctx, _ := testJavaWithFS(t, `
|
ctx, _ := testJavaWithFS(t, `
|
||||||
java_library {
|
java_library {
|
||||||
|
@@ -15,11 +15,113 @@
|
|||||||
package java
|
package java
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestJavaLint(t *testing.T) {
|
||||||
|
ctx, _ := testJavaWithFS(t, `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: [
|
||||||
|
"a.java",
|
||||||
|
"b.java",
|
||||||
|
"c.java",
|
||||||
|
],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "system_current",
|
||||||
|
}
|
||||||
|
`, map[string][]byte{
|
||||||
|
"lint-baseline.xml": nil,
|
||||||
|
})
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
|
||||||
|
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
||||||
|
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") {
|
||||||
|
t.Error("did not pass --baseline flag")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaLintWithoutBaseline(t *testing.T) {
|
||||||
|
ctx, _ := testJavaWithFS(t, `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: [
|
||||||
|
"a.java",
|
||||||
|
"b.java",
|
||||||
|
"c.java",
|
||||||
|
],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "system_current",
|
||||||
|
}
|
||||||
|
`, map[string][]byte{})
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
|
||||||
|
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
||||||
|
if strings.Contains(*sboxProto.Commands[0].Command, "--baseline") {
|
||||||
|
t.Error("passed --baseline flag for non existent file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) {
|
||||||
|
android.GroupFixturePreparers(
|
||||||
|
PrepareForTestWithJavaDefaultModules,
|
||||||
|
android.PrepareForTestDisallowNonExistentPaths,
|
||||||
|
).ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern([]string{`source path "mybaseline.xml" does not exist`})).
|
||||||
|
RunTestWithBp(t, `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: [
|
||||||
|
],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "system_current",
|
||||||
|
lint: {
|
||||||
|
baseline_filename: "mybaseline.xml",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJavaLintUsesCorrectBpConfig(t *testing.T) {
|
||||||
|
ctx, _ := testJavaWithFS(t, `
|
||||||
|
java_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: [
|
||||||
|
"a.java",
|
||||||
|
"b.java",
|
||||||
|
"c.java",
|
||||||
|
],
|
||||||
|
min_sdk_version: "29",
|
||||||
|
sdk_version: "system_current",
|
||||||
|
lint: {
|
||||||
|
error_checks: ["SomeCheck"],
|
||||||
|
baseline_filename: "mybaseline.xml",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`, map[string][]byte{
|
||||||
|
"mybaseline.xml": nil,
|
||||||
|
})
|
||||||
|
|
||||||
|
foo := ctx.ModuleForTests("foo", "android_common")
|
||||||
|
|
||||||
|
sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto"))
|
||||||
|
if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") {
|
||||||
|
t.Error("did not use the correct file for baseline")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") {
|
||||||
|
t.Error("should check NewApi errors")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check SomeCheck") {
|
||||||
|
t.Error("should combine NewApi errors with SomeCheck errors")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestJavaLintBypassUpdatableChecks(t *testing.T) {
|
func TestJavaLintBypassUpdatableChecks(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
Reference in New Issue
Block a user