1// Copyright 2020 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package rust 16 17import ( 18 "testing" 19 20 "android/soong/android" 21) 22 23func TestClippy(t *testing.T) { 24 25 bp := ` 26 // foo uses the default value of clippy_lints 27 rust_library { 28 name: "libfoo", 29 srcs: ["foo.rs"], 30 crate_name: "foo", 31 } 32 // bar forces the use of the "android" lint set 33 rust_library { 34 name: "libbar", 35 srcs: ["foo.rs"], 36 crate_name: "bar", 37 clippy_lints: "android", 38 } 39 // foobar explicitly disable clippy 40 rust_library { 41 name: "libfoobar", 42 srcs: ["foo.rs"], 43 crate_name: "foobar", 44 clippy_lints: "none", 45 }` 46 47 var clippyLintTests = []struct { 48 modulePath string 49 fooFlags string 50 }{ 51 {"", "${config.ClippyDefaultLints}"}, 52 {"external/", ""}, 53 {"hardware/", "${config.ClippyVendorLints}"}, 54 } 55 56 for _, tc := range clippyLintTests { 57 t.Run("path="+tc.modulePath, func(t *testing.T) { 58 59 result := android.GroupFixturePreparers( 60 prepareForRustTest, 61 // Test with the blueprint file in different directories. 62 android.FixtureAddTextFile(tc.modulePath+"Android.bp", bp), 63 ).RunTest(t) 64 65 r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy") 66 android.AssertStringEquals(t, "libfoo flags", tc.fooFlags, r.Args["clippyFlags"]) 67 68 r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy") 69 android.AssertStringEquals(t, "libbar flags", "${config.ClippyDefaultLints}", r.Args["clippyFlags"]) 70 71 r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy") 72 if r.Rule != nil { 73 t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"]) 74 } 75 }) 76 } 77} 78