blob: 7d4c9b1cf999b646fff9c6e01857964e4469828a [file] [log] [blame]
Sasha Smundakff36da02019-02-12 17:12:08 -08001// Copyright 2018 Google Inc. All rights reserved.
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 android
16
17import (
18 "io/ioutil"
19 "os"
20 "testing"
21)
22
23func testVtsConfig(test *testing.T, bpFileContents string) *TestContext {
24 buildDir, err := ioutil.TempDir("", "soong_vts_config_test")
25 if err != nil {
26 test.Fatal(err)
27 }
28
29 config := TestArchConfig(buildDir, nil)
30 defer func() { os.RemoveAll(buildDir) }()
31
32 ctx := NewTestArchContext()
33 ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory))
34 ctx.Register()
35 mockFiles := map[string][]byte{
36 "Android.bp": []byte(bpFileContents),
37 }
38 ctx.MockFileSystem(mockFiles)
39 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
40 FailIfErrored(test, errs)
41 _, errs = ctx.PrepareBuildActions(config)
42 FailIfErrored(test, errs)
43 return ctx
44}
45
46func TestVtsConfig(t *testing.T) {
47 ctx := testVtsConfig(t, `
48vts_config { name: "plain"}
49vts_config { name: "with_manifest", test_config: "manifest.xml" }
50`)
51
52 variants := ctx.ModuleVariantsForTests("plain")
53 if len(variants) > 1 {
54 t.Errorf("expected 1, got %d", len(variants))
55 }
56 expectedOutputFilename := ctx.ModuleForTests(
57 "plain", variants[0]).Module().(*VtsConfig).OutputFilePath.Base()
58 if expectedOutputFilename != "plain" {
59 t.Errorf("expected plain, got %q", expectedOutputFilename)
60 }
61}