sh_conversion_test.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2021 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. "testing"
  17. "android/soong/android"
  18. "android/soong/sh"
  19. )
  20. func TestShBinaryLoadStatement(t *testing.T) {
  21. testCases := []struct {
  22. bazelTargets BazelTargets
  23. expectedLoadStatements string
  24. }{
  25. {
  26. bazelTargets: BazelTargets{
  27. BazelTarget{
  28. name: "sh_binary_target",
  29. ruleClass: "sh_binary",
  30. // Note: no bzlLoadLocation for native rules
  31. // TODO(ruperts): Could open source the existing, experimental Starlark sh_ rules?
  32. },
  33. },
  34. expectedLoadStatements: ``,
  35. },
  36. }
  37. for _, testCase := range testCases {
  38. actual := testCase.bazelTargets.LoadStatements()
  39. expected := testCase.expectedLoadStatements
  40. if actual != expected {
  41. t.Fatalf("Expected load statements to be %s, got %s", expected, actual)
  42. }
  43. }
  44. }
  45. func runShBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
  46. t.Helper()
  47. RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
  48. }
  49. func TestShBinarySimple(t *testing.T) {
  50. runShBinaryTestCase(t, Bp2buildTestCase{
  51. Description: "sh_binary test",
  52. ModuleTypeUnderTest: "sh_binary",
  53. ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
  54. Blueprint: `sh_binary {
  55. name: "foo",
  56. src: "foo.sh",
  57. filename: "foo.exe",
  58. sub_dir: "sub",
  59. bazel_module: { bp2build_available: true },
  60. }`,
  61. ExpectedBazelTargets: []string{
  62. MakeBazelTarget("sh_binary", "foo", AttrNameToString{
  63. "srcs": `["foo.sh"]`,
  64. "filename": `"foo.exe"`,
  65. "sub_dir": `"sub"`,
  66. })},
  67. })
  68. }
  69. func TestShBinaryDefaults(t *testing.T) {
  70. runShBinaryTestCase(t, Bp2buildTestCase{
  71. Description: "sh_binary test",
  72. ModuleTypeUnderTest: "sh_binary",
  73. ModuleTypeUnderTestFactory: sh.ShBinaryFactory,
  74. Blueprint: `sh_binary {
  75. name: "foo",
  76. src: "foo.sh",
  77. bazel_module: { bp2build_available: true },
  78. }`,
  79. ExpectedBazelTargets: []string{
  80. MakeBazelTarget("sh_binary", "foo", AttrNameToString{
  81. "srcs": `["foo.sh"]`,
  82. })},
  83. })
  84. }