blob: b598b855e4856f7dddfc37fa50e8caa69d47a32f [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
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runFilegroupTestCase(t *testing.T, tc Bp2buildTestCase) {
Jingwen Chen5146ac02021-09-02 11:44:42 +000025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 (&tc).ModuleTypeUnderTest = "filegroup"
27 (&tc).ModuleTypeUnderTestFactory = android.FileGroupFactory
28 RunBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
Jingwen Chen5146ac02021-09-02 11:44:42 +000029}
30
31func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
32
33func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000034 runFilegroupTestCase(t, Bp2buildTestCase{
35 Description: "filegroup - same name as file, with one file",
36 Filesystem: map[string]string{},
37 Blueprint: `
Jingwen Chen5146ac02021-09-02 11:44:42 +000038filegroup {
39 name: "foo",
40 srcs: ["foo"],
41}
42`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000043 ExpectedBazelTargets: []string{}})
Jingwen Chen5146ac02021-09-02 11:44:42 +000044}
45
46func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000047 runFilegroupTestCase(t, Bp2buildTestCase{
48 Description: "filegroup - same name as file, with multiple files",
49 Filesystem: map[string]string{},
50 Blueprint: `
Jingwen Chen5146ac02021-09-02 11:44:42 +000051filegroup {
52 name: "foo",
53 srcs: ["foo", "bar"],
54}
55`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000056 ExpectedErr: fmt.Errorf("filegroup 'foo' cannot contain a file with the same name"),
Jingwen Chen5146ac02021-09-02 11:44:42 +000057 })
58}