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