• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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()
26	(&tc).moduleTypeUnderTest = "filegroup"
27	(&tc).moduleTypeUnderTestFactory = android.FileGroupFactory
28	runBp2BuildTestCase(t, registerFilegroupModuleTypes, tc)
29}
30
31func registerFilegroupModuleTypes(ctx android.RegistrationContext) {}
32
33func TestFilegroupSameNameAsFile_OneFile(t *testing.T) {
34	runFilegroupTestCase(t, bp2buildTestCase{
35		description: "filegroup - same name as file, with one file",
36		filesystem:  map[string]string{},
37		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{
48		description: "filegroup - same name as file, with multiple files",
49		filesystem:  map[string]string{},
50		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}
59