Sasha Smundak | ff36da0 | 2019-02-12 17:12:08 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
Sasha Smundak | ff36da0 | 2019-02-12 17:12:08 -0800 | [diff] [blame] | 18 | "testing" |
| 19 | ) |
| 20 | |
| 21 | func testVtsConfig(test *testing.T, bpFileContents string) *TestContext { |
Sasha Smundak | ff36da0 | 2019-02-12 17:12:08 -0800 | [diff] [blame] | 22 | config := TestArchConfig(buildDir, nil) |
Sasha Smundak | ff36da0 | 2019-02-12 17:12:08 -0800 | [diff] [blame] | 23 | |
| 24 | ctx := NewTestArchContext() |
| 25 | ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory)) |
| 26 | ctx.Register() |
| 27 | mockFiles := map[string][]byte{ |
| 28 | "Android.bp": []byte(bpFileContents), |
| 29 | } |
| 30 | ctx.MockFileSystem(mockFiles) |
| 31 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 32 | FailIfErrored(test, errs) |
| 33 | _, errs = ctx.PrepareBuildActions(config) |
| 34 | FailIfErrored(test, errs) |
| 35 | return ctx |
| 36 | } |
| 37 | |
| 38 | func TestVtsConfig(t *testing.T) { |
| 39 | ctx := testVtsConfig(t, ` |
| 40 | vts_config { name: "plain"} |
| 41 | vts_config { name: "with_manifest", test_config: "manifest.xml" } |
| 42 | `) |
| 43 | |
| 44 | variants := ctx.ModuleVariantsForTests("plain") |
| 45 | if len(variants) > 1 { |
| 46 | t.Errorf("expected 1, got %d", len(variants)) |
| 47 | } |
| 48 | expectedOutputFilename := ctx.ModuleForTests( |
| 49 | "plain", variants[0]).Module().(*VtsConfig).OutputFilePath.Base() |
| 50 | if expectedOutputFilename != "plain" { |
| 51 | t.Errorf("expected plain, got %q", expectedOutputFilename) |
| 52 | } |
| 53 | } |