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 15package main 16 17import ( 18 "bytes" 19 "fmt" 20 "strings" 21 "testing" 22 23 "android/soong/androidmk/androidmk" 24 "android/soong/bpfix/bpfix" 25 26 _ "android/soong/partner/bpfix/extensions" 27) 28 29var testCases = []struct { 30 desc string 31 in string 32 expected string 33}{ 34 { 35 desc: "headers replacement", 36 in: ` 37include $(CLEAR_VARS) 38LOCAL_MODULE := test 39LOCAL_SRC_FILES := a.c 40LOCAL_C_INCLUDES := test1 $(TARGET_OUT_HEADERS)/my_headers test2 41include $(BUILD_SHARED_LIBRARY)`, 42 expected: ` 43cc_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 56func 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} 74