soong_variables_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. "fmt"
  17. "path/filepath"
  18. "reflect"
  19. "testing"
  20. )
  21. type dirResolverForTest struct {
  22. ScopeBase
  23. }
  24. func (t dirResolverForTest) Get(name string) string {
  25. if name != "BUILD_SYSTEM" {
  26. return fmt.Sprintf("$(%s)", name)
  27. }
  28. return getTestDirectory()
  29. }
  30. func TestSoongVariables(t *testing.T) {
  31. testFile := filepath.Join(getTestDirectory(), "soong_variables.mk.test")
  32. var actual testVariables
  33. if err := FindSoongVariables(testFile, dirResolverForTest{}, &actual); err != nil {
  34. t.Fatal(err)
  35. }
  36. expected := testVariables{[]testVar{
  37. {"BUILD_ID", VarClassSoong, starlarkTypeString},
  38. {"PLATFORM_SDK_VERSION", VarClassSoong, starlarkTypeInt},
  39. {"DEVICE_PACKAGE_OVERLAYS", VarClassSoong, starlarkTypeList},
  40. {"ENABLE_CFI", VarClassSoong, starlarkTypeString},
  41. {"ENABLE_PREOPT", VarClassSoong, starlarkTypeString},
  42. }}
  43. if !reflect.DeepEqual(expected, actual) {
  44. t.Errorf("\nExpected: %v\n Actual: %v", expected, actual)
  45. }
  46. }