blob: f5a518049c4e22c04e423490589e77b9bea90ebb [file] [log] [blame]
Sasha Smundak472afab2021-03-10 01:13:14 -08001// Copyright 2021 Google LLC
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 mk2rbc
16
17import (
18 "path/filepath"
19 "reflect"
20 "runtime"
21 "testing"
22)
23
24type testVar struct {
25 name string
26 cl varClass
27 ty starlarkType
28}
29
30type testVariables struct {
31 v []testVar
32}
33
34func (v *testVariables) NewVariable(name string, varClass varClass, valueType starlarkType) {
35 v.v = append(v.v, testVar{name, varClass, valueType})
36}
37
38// getTestDirectory returns the test directory, which should be the test/ subdirectory
39func getTestDirectory() string {
40 _, myFile, _, _ := runtime.Caller(1)
41 return filepath.Join(filepath.Dir(myFile), "test")
42}
43
44func TestConfigVariables(t *testing.T) {
45 testFile := filepath.Join(getTestDirectory(), "config_variables.mk.test")
46 var actual testVariables
47 if err := FindConfigVariables(testFile, &actual); err != nil {
48 t.Fatal(err)
49 }
50 expected := testVariables{[]testVar{
51 {"PRODUCT_NAME", VarClassConfig, starlarkTypeUnknown},
52 {"PRODUCT_MODEL", VarClassConfig, starlarkTypeUnknown},
53 {"PRODUCT_LOCALES", VarClassConfig, starlarkTypeList},
54 {"PRODUCT_AAPT_CONFIG", VarClassConfig, starlarkTypeList},
55 {"PRODUCT_AAPT_PREF_CONFIG", VarClassConfig, starlarkTypeUnknown},
56 }}
57 if !reflect.DeepEqual(expected, actual) {
58 t.Errorf("\nExpected: %v\n Actual: %v", expected, actual)
59 }
60}