blob: b43cf53746d6486a8088bb5419f316fecf65f4d4 [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
Jingwen Chen5146ac02021-09-02 11:44:42 +000028 runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
29}
30
31func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
32
33func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
34 runFilegroupTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050035 description: "filegroup - same name as file, with one file",
36 filesystem: map[string]string{},
Jingwen Chen5146ac02021-09-02 11:44:42 +000037 blueprint: `
38filegroup {
39 name: "foo",
40 srcs: ["foo"],
41}
42`,
43 expectedBazelTargets: []string{}})
44}
45
46func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
47 runFilegroupTestCase(t, bp2buildTestCase{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050048 description: "filegroup - same name as file, with multiple files",
49 filesystem: map[string]string{},
Jingwen Chen5146ac02021-09-02 11:44:42 +000050 blueprint: `
51filegroup {
52 name: "foo",
53 srcs: ["foo", "bar"],
54}
55`,
56 expectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
57 })
58}