Support multiple expected errors in neverallow_test.go
Extracted some common code used by visibility_test.go and neverallow_test.go into a new function CheckErrorsAgainstExpectations in testing.go. Bug: 138428610 Test: m nothing Change-Id: I6996fa52968c387e38b4a67ffa59cd07c2d524e8 Merged-In: Iafbadf12c6ffdc4d9128fcfe7f15792df5cfd020
This commit is contained in:
@@ -28,9 +28,9 @@ func init() {
|
||||
}
|
||||
|
||||
var neverallowTests = []struct {
|
||||
name string
|
||||
fs map[string][]byte
|
||||
expectedError string
|
||||
name string
|
||||
fs map[string][]byte
|
||||
expectedErrors []string
|
||||
}{
|
||||
// Test General Functionality
|
||||
|
||||
@@ -48,7 +48,9 @@ var neverallowTests = []struct {
|
||||
static_libs: ["not_allowed_in_direct_deps"],
|
||||
}`),
|
||||
},
|
||||
expectedError: `module "libother": violates neverallow deps:not_allowed_in_direct_deps`,
|
||||
expectedErrors: []string{
|
||||
`module "libother": violates neverallow deps:not_allowed_in_direct_deps`,
|
||||
},
|
||||
},
|
||||
|
||||
// Test specific rules
|
||||
@@ -63,7 +65,9 @@ var neverallowTests = []struct {
|
||||
include_dirs: ["art/libdexfile/include"],
|
||||
}`),
|
||||
},
|
||||
expectedError: "all usages of 'art' have been migrated",
|
||||
expectedErrors: []string{
|
||||
"all usages of 'art' have been migrated",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "include_dir can reference another location",
|
||||
@@ -88,7 +92,9 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "VNDK can never contain a library that is device dependent",
|
||||
expectedErrors: []string{
|
||||
"VNDK can never contain a library that is device dependent",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no vndk.enabled under device directory",
|
||||
@@ -102,7 +108,9 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "VNDK can never contain a library that is device dependent",
|
||||
expectedErrors: []string{
|
||||
"VNDK can never contain a library that is device dependent",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "vndk-ext under vendor or device directory",
|
||||
@@ -124,7 +132,6 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "",
|
||||
},
|
||||
|
||||
{
|
||||
@@ -140,7 +147,9 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "manifest enforcement should be independent",
|
||||
expectedErrors: []string{
|
||||
"manifest enforcement should be independent",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "libhidltransport enforce_vintf_manifest.cflags",
|
||||
@@ -155,7 +164,6 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "",
|
||||
},
|
||||
|
||||
{
|
||||
@@ -171,7 +179,9 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "nothing should care if linker namespaces are enabled or not",
|
||||
expectedErrors: []string{
|
||||
"nothing should care if linker namespaces are enabled or not",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "libc_bionic_ndk treble_linker_namespaces.cflags",
|
||||
@@ -186,7 +196,6 @@ var neverallowTests = []struct {
|
||||
},
|
||||
}`),
|
||||
},
|
||||
expectedError: "",
|
||||
},
|
||||
{
|
||||
name: "java_device_for_host",
|
||||
@@ -197,7 +206,9 @@ var neverallowTests = []struct {
|
||||
libs: ["core-libart"],
|
||||
}`),
|
||||
},
|
||||
expectedError: "java_device_for_host can only be used in whitelisted projects",
|
||||
expectedErrors: []string{
|
||||
"java_device_for_host can only be used in whitelisted projects",
|
||||
},
|
||||
},
|
||||
// Libcore rule tests
|
||||
{
|
||||
@@ -219,7 +230,9 @@ var neverallowTests = []struct {
|
||||
sdk_version: "none",
|
||||
}`),
|
||||
},
|
||||
expectedError: "module \"outside_core_libraries\": violates neverallow",
|
||||
expectedErrors: []string{
|
||||
"module \"outside_core_libraries\": violates neverallow",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sdk_version: \"current\"",
|
||||
@@ -237,19 +250,15 @@ func TestNeverallow(t *testing.T) {
|
||||
config := TestConfig(buildDir, nil)
|
||||
|
||||
for _, test := range neverallowTests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, errs := testNeverallow(t, config, test.fs)
|
||||
|
||||
if test.expectedError == "" {
|
||||
FailIfErrored(t, errs)
|
||||
} else {
|
||||
FailIfNoMatchingErrors(t, test.expectedError, errs)
|
||||
}
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, errs := testNeverallow(config, test.fs)
|
||||
CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) {
|
||||
func testNeverallow(config Config, fs map[string][]byte) (*TestContext, []error) {
|
||||
ctx := NewTestContext()
|
||||
ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
|
||||
ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule))
|
||||
|
Reference in New Issue
Block a user