diff options
author | ThiƩbaud Weksteen <tweek@google.com> | 2020-08-13 12:55:59 +0200 |
---|---|---|
committer | ThiƩbaud Weksteen <tweek@google.com> | 2020-08-13 15:58:09 +0200 |
commit | 9e8451e5243e77fef5fddfdf4f000d82f66e395f (patch) | |
tree | a855d09c583178e0a256aae041c3fedb1f09ffb0 /rust/compiler_test.go | |
parent | 29737cfc944f73f5c1095126d1d2d701b1a7db09 (diff) |
rust: modify linting properties
Move the linting properties to an enum with 4 possible options:
"default", "android", "vendor" or "none". The previous logic for
default, based on the module's location, is kept. It is now possible to
force the upgrade to a certain lint level for some modules (e.g.
external/[...]/android). Update the unit tests and documentation.
Bug: 163400111
Test: m
Change-Id: I8e464b04401158ed2d3c518a9b72f145a9835c99
Diffstat (limited to 'rust/compiler_test.go')
-rw-r--r-- | rust/compiler_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/rust/compiler_test.go b/rust/compiler_test.go index b85319643..8b9fccc61 100644 --- a/rust/compiler_test.go +++ b/rust/compiler_test.go @@ -17,6 +17,8 @@ package rust import ( "strings" "testing" + + "android/soong/android" ) // Test that feature flags are being correctly generated. @@ -104,3 +106,74 @@ func TestInstallDir(t *testing.T) { t.Fatalf("unexpected install path for binary: %#v", install_path_bin) } } + +func TestLints(t *testing.T) { + + bp := ` + // foo uses the default value of lints + rust_library { + name: "libfoo", + srcs: ["foo.rs"], + crate_name: "foo", + } + // bar forces the use of the "android" lint set + rust_library { + name: "libbar", + srcs: ["foo.rs"], + crate_name: "bar", + lints: "android", + } + // foobar explicitly disable all lints + rust_library { + name: "libfoobar", + srcs: ["foo.rs"], + crate_name: "foobar", + lints: "none", + }` + + bp = bp + GatherRequiredDepsForTest() + + fs := map[string][]byte{ + // Reuse the same blueprint file for subdirectories. + "external/Android.bp": []byte(bp), + "hardware/Android.bp": []byte(bp), + } + + var lintTests = []struct { + modulePath string + fooFlags string + }{ + {"", "${config.RustDefaultLints}"}, + {"external/", "${config.RustAllowAllLints}"}, + {"hardware/", "${config.RustVendorLints}"}, + } + + for _, tc := range lintTests { + t.Run("path="+tc.modulePath, func(t *testing.T) { + + config := android.TestArchConfig(buildDir, nil, bp, fs) + ctx := CreateTestContext() + ctx.Register(config) + _, errs := ctx.ParseFileList(".", []string{tc.modulePath + "Android.bp"}) + android.FailIfErrored(t, errs) + _, errs = ctx.PrepareBuildActions(config) + android.FailIfErrored(t, errs) + + r := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("rustc") + if !strings.Contains(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") + if !strings.Contains(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}") + } + + }) + } +} |