config_variables_test.go 1.8 KB

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