blob: 9f4add2ff1d2d875e9474d6a91e39183dd997912 [file] [log] [blame]
Jingwen Chen5146ac02021-09-02 11:44:42 +00001// 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
15package bp2build
16
17import (
18 "android/soong/android"
19 "fmt"
20
21 "testing"
22)
23
24func runFilegroupTestCase(t *testing.T, tc bp2buildTestCase) {
25 t.Helper()
Liz Kammer78cfdaa2021-11-08 12:56:31 -050026 (&tc).moduleTypeUnderTest = "filegroup"
27 (&tc).moduleTypeUnderTestFactory = android.FileGroupFactory
28 (&tc).moduleTypeUnderTestBp2BuildMutator = android.FilegroupBp2Build
Jingwen Chen5146ac02021-09-02 11:44:42 +000029 runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
30}
31
32func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
33
34func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
35 runFilegroupTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050036 description: "filegroup - same name as file, with one file",
37 filesystem: map[string]string{},
Jingwen Chen5146ac02021-09-02 11:44:42 +000038 blueprint: `
39filegroup {
40 name: "foo",
41 srcs: ["foo"],
42}
43`,
44 expectedBazelTargets: []string{}})
45}
46
47func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
48 runFilegroupTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050049 description: "filegroup - same name as file, with multiple files",
50 filesystem: map[string]string{},
Jingwen Chen5146ac02021-09-02 11:44:42 +000051 blueprint: `
52filegroup {
53 name: "foo",
54 srcs: ["foo", "bar"],
55}
56`,
57 expectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
58 })
59}