license_conversion_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2022 Google Inc. All rights reserved.
  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 bp2build
  15. import (
  16. "android/soong/android"
  17. "testing"
  18. )
  19. func registerLicenseModuleTypes(_ android.RegistrationContext) {}
  20. func TestLicenseBp2Build(t *testing.T) {
  21. tests := []struct {
  22. description string
  23. module string
  24. expected ExpectedRuleTarget
  25. }{
  26. {
  27. description: "license kind and text notice",
  28. module: `
  29. license {
  30. name: "my_license",
  31. license_kinds: [ "SPDX-license-identifier-Apache-2.0"],
  32. license_text: [ "NOTICE"],
  33. }`,
  34. expected: ExpectedRuleTarget{
  35. "android_license",
  36. "my_license",
  37. AttrNameToString{
  38. "license_kinds": `["SPDX-license-identifier-Apache-2.0"]`,
  39. "license_text": `"NOTICE"`,
  40. },
  41. android.HostAndDeviceDefault,
  42. },
  43. },
  44. {
  45. description: "visibility, package_name, copyright_notice",
  46. module: `
  47. license {
  48. name: "my_license",
  49. package_name: "my_package",
  50. visibility: [":__subpackages__"],
  51. copyright_notice: "Copyright © 2022",
  52. }`,
  53. expected: ExpectedRuleTarget{
  54. "android_license",
  55. "my_license",
  56. AttrNameToString{
  57. "copyright_notice": `"Copyright © 2022"`,
  58. "package_name": `"my_package"`,
  59. "visibility": `[":__subpackages__"]`,
  60. },
  61. android.HostAndDeviceDefault,
  62. },
  63. },
  64. }
  65. for _, test := range tests {
  66. RunBp2BuildTestCase(t,
  67. registerLicenseModuleTypes,
  68. Bp2buildTestCase{
  69. Description: test.description,
  70. ModuleTypeUnderTest: "license",
  71. ModuleTypeUnderTestFactory: android.LicenseFactory,
  72. Blueprint: test.module,
  73. ExpectedBazelTargets: []string{test.expected.String()},
  74. })
  75. }
  76. }