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 | |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 24 | func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) { |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 25 | t.Helper() |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 26 | (&tc).ModuleTypeUnderTest = "filegroup" |
| 27 | (&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory |
| 28 | RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func registerFilegroupModuleTypes(ctx android.RegistrationContext) {} |
| 32 | |
| 33 | func TestFilegroupSameNameAsFile_OneFile(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 34 | runFilegroupTestCase(t, Bp2buildTestCase{ |
| 35 | Description: "filegroup - same name as file, with one file", |
| 36 | Filesystem: map[string]string{}, |
| 37 | Blueprint: ` |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 38 | filegroup { |
| 39 | name: "foo", |
| 40 | srcs: ["foo"], |
| 41 | } |
| 42 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 43 | ExpectedBazelTargets: []string{}}) |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) { |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 47 | runFilegroupTestCase(t, Bp2buildTestCase{ |
| 48 | Description: "filegroup - same name as file, with multiple files", |
| 49 | Filesystem: map[string]string{}, |
| 50 | Blueprint: ` |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 51 | filegroup { |
| 52 | name: "foo", |
| 53 | srcs: ["foo", "bar"], |
| 54 | } |
| 55 | `, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 56 | ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"), |
Jingwen Chen | 5146ac0 | 2021-09-02 11:44:42 +0000 | [diff] [blame] | 57 | }) |
| 58 | } |