Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 1 | // Copyright 2021 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 bp2build |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "fmt" |
| 20 | |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func runFilegroupTestCase(t *testing.T, tc bp2buildTestCase) { |
| 25 | t.Helper() |
| 26 | runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc) |
| 27 | } |
| 28 | |
| 29 | func registerFilegroupModuleTypes(ctx android.RegistrationContext) {} |
| 30 | |
| 31 | func TestFilegroupSameNameAsFile_OneFile(t *testing.T) { |
| 32 | runFilegroupTestCase(t, bp2buildTestCase{ |
| 33 | description: "filegroup - same name as file, with one file", |
| 34 | moduleTypeUnderTest: "filegroup", |
| 35 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 36 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 37 | filesystem: map[string]string{}, |
| 38 | blueprint: ` |
| 39 | filegroup { |
| 40 | name: "foo", |
| 41 | srcs: ["foo"], |
| 42 | } |
| 43 | `, |
| 44 | expectedBazelTargets: []string{}}) |
| 45 | } |
| 46 | |
| 47 | func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) { |
| 48 | runFilegroupTestCase(t, bp2buildTestCase{ |
| 49 | description: "filegroup - same name as file, with multiple files", |
| 50 | moduleTypeUnderTest: "filegroup", |
| 51 | moduleTypeUnderTestFactory: android.FileGroupFactory, |
| 52 | moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build, |
| 53 | filesystem: map[string]string{}, |
| 54 | blueprint: ` |
| 55 | filegroup { |
| 56 | name: "foo", |
| 57 | srcs: ["foo", "bar"], |
| 58 | } |
| 59 | `, |
| 60 | expectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"), |
| 61 | }) |
| 62 | } |