Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 19 | |
| 20 | "android/soong/android" |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | func TestClippy(t *testing.T) { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 24 | |
| 25 | bp := ` |
| 26 | // foo uses the default value of clippy_lints |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 27 | rust_library { |
| 28 | name: "libfoo", |
| 29 | srcs: ["foo.rs"], |
| 30 | crate_name: "foo", |
| 31 | } |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 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 |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 40 | rust_library { |
| 41 | name: "libfoobar", |
| 42 | srcs: ["foo.rs"], |
| 43 | crate_name: "foobar", |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 44 | clippy_lints: "none", |
| 45 | }` |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 46 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 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 | |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 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) |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 64 | |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 65 | r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy") |
| 66 | android.AssertStringEquals(t, "libfoo flags", tc.fooFlags, r.Args["clippyFlags"]) |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 67 | |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 68 | r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy") |
| 69 | android.AssertStringEquals(t, "libbar flags", "${config.ClippyDefaultLints}", r.Args["clippyFlags"]) |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 70 | |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 71 | r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy") |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 72 | if r.Rule != nil { |
| 73 | t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"]) |
| 74 | } |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 75 | }) |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 76 | } |
| 77 | } |