androidmk_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2016 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 main
  15. import (
  16. "bytes"
  17. "fmt"
  18. "strings"
  19. "testing"
  20. "android/soong/androidmk/androidmk"
  21. "android/soong/bpfix/bpfix"
  22. _ "android/soong/partner/bpfix/extensions"
  23. )
  24. var testCases = []struct {
  25. desc string
  26. in string
  27. expected string
  28. }{
  29. {
  30. desc: "headers replacement",
  31. in: `
  32. include $(CLEAR_VARS)
  33. LOCAL_MODULE := test
  34. LOCAL_SRC_FILES := a.c
  35. LOCAL_C_INCLUDES := test1 $(TARGET_OUT_HEADERS)/my_headers test2
  36. include $(BUILD_SHARED_LIBRARY)`,
  37. expected: `
  38. cc_library_shared {
  39. name: "test",
  40. srcs: ["a.c"],
  41. include_dirs: [
  42. "test1",
  43. "test2",
  44. ],
  45. header_libs: ["my_header_lib"]
  46. }`,
  47. },
  48. }
  49. func TestEndToEnd(t *testing.T) {
  50. for i, test := range testCases {
  51. expected, err := bpfix.Reformat(test.expected)
  52. if err != nil {
  53. t.Error(err)
  54. }
  55. got, errs := androidmk.ConvertFile(fmt.Sprintf("<testcase %d>", i), bytes.NewBufferString(test.in))
  56. if len(errs) > 0 {
  57. t.Errorf("Unexpected errors: %q", errs)
  58. continue
  59. }
  60. if got != expected {
  61. t.Errorf("failed testcase '%s'\ninput:\n%s\n\nexpected:\n%s\ngot:\n%s\n", test.desc, strings.TrimSpace(test.in), expected, got)
  62. }
  63. }
  64. }