1package mkcompare 2 3import ( 4 "github.com/google/go-cmp/cmp" 5 "strings" 6 "testing" 7) 8 9func TestParseMkFile(t *testing.T) { 10 tests := []struct { 11 name string 12 source string 13 want MkFile 14 wantErr bool 15 }{ 16 { 17 name: "Good1", 18 source: ` 19include $(CLEAR_VARS) # modType 20LOCAL_MODULE := mymod 21LOCAL_MODULE_CLASS := ETC 22include $(BUILD_PREBUILT) 23 24ignored 25ignored2 26 27include $(CLEAR_VARS) 28LOCAL_MODULE := mymod2 29LOCAL_MODULE_CLASS := BIN 30MY_PATH := foo 31include $(BUILD_PREBUILT) 32`, 33 want: MkFile{ 34 Modules: map[string]*MkModule{ 35 "mymod|class:ETC|target_arch:*": { 36 Type: "modType", 37 Location: 2, 38 Variables: map[string]string{"LOCAL_MODULE": "mymod", "LOCAL_MODULE_CLASS": "ETC"}, 39 }, 40 "mymod2|class:BIN|target_arch:*": { 41 Type: "$(BUILD_PREBUILT)", 42 Location: 10, 43 Variables: map[string]string{"LOCAL_MODULE": "mymod2", "LOCAL_MODULE_CLASS": "BIN", "MY_PATH": "foo"}, 44 }, 45 }, 46 }, 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 got, err := ParseMkFile(strings.NewReader(tt.source)) 52 if (err != nil) != tt.wantErr { 53 t.Errorf("ParseMkFile() error = %v, wantErr %v", err, tt.wantErr) 54 return 55 } 56 if !cmp.Equal(got.Modules, tt.want.Modules) { 57 t.Errorf("ParseMkFile() got = %v, want %v, \ndiff: %s", got.Modules, tt.want.Modules, 58 cmp.Diff(got, tt.want)) 59 } 60 }) 61 } 62} 63