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