license_kind_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package android
  2. import (
  3. "testing"
  4. "github.com/google/blueprint"
  5. )
  6. var licenseKindTests = []struct {
  7. name string
  8. fs MockFS
  9. expectedErrors []string
  10. }{
  11. {
  12. name: "license_kind must not accept licenses property",
  13. fs: map[string][]byte{
  14. "top/Android.bp": []byte(`
  15. license_kind {
  16. name: "top_license",
  17. licenses: ["other_license"],
  18. }`),
  19. },
  20. expectedErrors: []string{
  21. `top/Android.bp:4:14: unrecognized property "licenses"`,
  22. },
  23. },
  24. {
  25. name: "bad license_kind",
  26. fs: map[string][]byte{
  27. "top/Android.bp": []byte(`
  28. license_kind {
  29. name: "top_notice",
  30. conditions: ["notice"],
  31. }`),
  32. "other/Android.bp": []byte(`
  33. mock_license {
  34. name: "other_notice",
  35. license_kinds: ["notice"],
  36. }`),
  37. },
  38. expectedErrors: []string{
  39. `other/Android.bp:2:5: "other_notice" depends on undefined module "notice"`,
  40. },
  41. },
  42. {
  43. name: "good license kind",
  44. fs: map[string][]byte{
  45. "top/Android.bp": []byte(`
  46. license_kind {
  47. name: "top_by_exception_only",
  48. conditions: ["by_exception_only"],
  49. }
  50. mock_license {
  51. name: "top_proprietary",
  52. license_kinds: ["top_by_exception_only"],
  53. }`),
  54. "other/Android.bp": []byte(`
  55. mock_license {
  56. name: "other_proprietary",
  57. license_kinds: ["top_proprietary"],
  58. }`),
  59. },
  60. },
  61. {
  62. name: "multiple license kinds",
  63. fs: map[string][]byte{
  64. "top/Android.bp": []byte(`
  65. license_kind {
  66. name: "top_notice",
  67. conditions: ["notice"],
  68. }
  69. license_kind {
  70. name: "top_by_exception_only",
  71. conditions: ["by_exception_only"],
  72. }
  73. mock_license {
  74. name: "top_allowed_as_notice",
  75. license_kinds: ["top_notice"],
  76. }
  77. mock_license {
  78. name: "top_proprietary",
  79. license_kinds: ["top_by_exception_only"],
  80. }`),
  81. "other/Android.bp": []byte(`
  82. mock_license {
  83. name: "other_rule",
  84. license_kinds: ["top_by_exception_only"],
  85. }`),
  86. },
  87. },
  88. }
  89. func TestLicenseKind(t *testing.T) {
  90. for _, test := range licenseKindTests {
  91. t.Run(test.name, func(t *testing.T) {
  92. GroupFixturePreparers(
  93. prepareForLicenseTest,
  94. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  95. ctx.RegisterModuleType("mock_license", newMockLicenseModule)
  96. }),
  97. test.fs.AddToFixture(),
  98. ).
  99. ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
  100. RunTest(t)
  101. })
  102. }
  103. }
  104. type mockLicenseProperties struct {
  105. License_kinds []string
  106. }
  107. type mockLicenseModule struct {
  108. ModuleBase
  109. DefaultableModuleBase
  110. properties mockLicenseProperties
  111. }
  112. func newMockLicenseModule() Module {
  113. m := &mockLicenseModule{}
  114. m.AddProperties(&m.properties)
  115. InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon)
  116. InitDefaultableModule(m)
  117. return m
  118. }
  119. type licensekindTag struct {
  120. blueprint.BaseDependencyTag
  121. }
  122. func (j *mockLicenseModule) DepsMutator(ctx BottomUpMutatorContext) {
  123. m, ok := ctx.Module().(Module)
  124. if !ok {
  125. return
  126. }
  127. ctx.AddDependency(m, licensekindTag{}, j.properties.License_kinds...)
  128. }
  129. func (p *mockLicenseModule) GenerateAndroidBuildActions(ModuleContext) {
  130. }