clippy_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. package rust
  15. import (
  16. "testing"
  17. "android/soong/android"
  18. )
  19. func TestClippy(t *testing.T) {
  20. bp := `
  21. // foo uses the default value of clippy_lints
  22. rust_library {
  23. name: "libfoo",
  24. srcs: ["foo.rs"],
  25. crate_name: "foo",
  26. }
  27. // bar forces the use of the "android" lint set
  28. rust_library {
  29. name: "libbar",
  30. srcs: ["foo.rs"],
  31. crate_name: "bar",
  32. clippy_lints: "android",
  33. }
  34. // foobar explicitly disable clippy
  35. rust_library {
  36. name: "libfoobar",
  37. srcs: ["foo.rs"],
  38. crate_name: "foobar",
  39. clippy_lints: "none",
  40. }`
  41. var clippyLintTests = []struct {
  42. modulePath string
  43. fooFlags string
  44. }{
  45. {"", "${config.ClippyDefaultLints}"},
  46. {"external/", ""},
  47. {"hardware/", "${config.ClippyVendorLints}"},
  48. }
  49. for _, tc := range clippyLintTests {
  50. t.Run("path="+tc.modulePath, func(t *testing.T) {
  51. result := android.GroupFixturePreparers(
  52. prepareForRustTest,
  53. // Test with the blueprint file in different directories.
  54. android.FixtureAddTextFile(tc.modulePath+"Android.bp", bp),
  55. ).RunTest(t)
  56. r := result.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
  57. android.AssertStringEquals(t, "libfoo flags", tc.fooFlags, r.Args["clippyFlags"])
  58. r = result.ModuleForTests("libbar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
  59. android.AssertStringEquals(t, "libbar flags", "${config.ClippyDefaultLints}", r.Args["clippyFlags"])
  60. r = result.ModuleForTests("libfoobar", "android_arm64_armv8-a_dylib").MaybeRule("clippy")
  61. if r.Rule != nil {
  62. t.Errorf("libfoobar is setup to use clippy when explicitly disabled: clippyFlags=%q", r.Args["clippyFlags"])
  63. }
  64. })
  65. }
  66. }