package_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package android
  2. import (
  3. "testing"
  4. )
  5. var packageTests = []struct {
  6. name string
  7. fs MockFS
  8. expectedErrors []string
  9. }{
  10. // Package default_visibility handling is tested in visibility_test.go
  11. {
  12. name: "package must not accept visibility, name or licenses properties",
  13. fs: map[string][]byte{
  14. "top/Android.bp": []byte(`
  15. package {
  16. name: "package",
  17. visibility: ["//visibility:private"],
  18. licenses: ["license"],
  19. }`),
  20. },
  21. expectedErrors: []string{
  22. `top/Android.bp:5:14: unrecognized property "licenses"`,
  23. `top/Android.bp:3:10: unrecognized property "name"`,
  24. `top/Android.bp:4:16: unrecognized property "visibility"`,
  25. },
  26. },
  27. {
  28. name: "multiple packages in separate directories",
  29. fs: map[string][]byte{
  30. "top/Android.bp": []byte(`
  31. package {
  32. }`),
  33. "other/Android.bp": []byte(`
  34. package {
  35. }`),
  36. "other/nested/Android.bp": []byte(`
  37. package {
  38. }`),
  39. },
  40. },
  41. {
  42. name: "package must not be specified more than once per package",
  43. fs: map[string][]byte{
  44. "top/Android.bp": []byte(`
  45. package {
  46. default_visibility: ["//visibility:private"],
  47. default_applicable_licenses: ["license"],
  48. }
  49. package {
  50. }`),
  51. },
  52. expectedErrors: []string{
  53. `module "//top" already defined`,
  54. },
  55. },
  56. }
  57. func TestPackage(t *testing.T) {
  58. for _, test := range packageTests {
  59. t.Run(test.name, func(t *testing.T) {
  60. GroupFixturePreparers(
  61. PrepareForTestWithArchMutator,
  62. PrepareForTestWithPackageModule,
  63. test.fs.AddToFixture(),
  64. ).
  65. ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
  66. RunTest(t)
  67. })
  68. }
  69. }