blob: 1882908ca345ee7cd580d30cda0659341250334e [file] [log] [blame]
Colin Cross7a3139e2017-12-19 13:57:50 -08001// Copyright 2017 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 java
16
17import "testing"
18
19func TestJacocoFilterToSpecs(t *testing.T) {
20 testCases := []struct {
21 name, in, out string
22 }{
23 {
Colin Crossd7deceb2017-12-19 13:59:44 -080024 name: "class",
25 in: "package.Class",
26 out: "package/Class.class",
27 },
28 {
Colin Cross7a3139e2017-12-19 13:57:50 -080029 name: "class wildcard",
30 in: "package.Class*",
31 out: "package/Class*.class",
32 },
33 {
34 name: "package wildcard",
35 in: "package.*",
Nan Zhangffe2c1c2018-01-25 13:53:22 -080036 out: "package/*.class",
37 },
38 {
39 name: "package recursive wildcard",
40 in: "package.**",
Colin Cross7a3139e2017-12-19 13:57:50 -080041 out: "package/**/*.class",
42 },
43 {
Nan Zhangffe2c1c2018-01-25 13:53:22 -080044 name: "recursive wildcard only",
45 in: "**",
Colin Cross7a3139e2017-12-19 13:57:50 -080046 out: "**/*.class",
47 },
Nan Zhangffe2c1c2018-01-25 13:53:22 -080048 {
49 name: "single wildcard only",
50 in: "*",
51 out: "*.class",
52 },
Colin Cross7a3139e2017-12-19 13:57:50 -080053 }
54
55 for _, testCase := range testCases {
56 t.Run(testCase.name, func(t *testing.T) {
57 got, err := jacocoFilterToSpec(testCase.in)
58 if err != nil {
59 t.Error(err)
60 }
61 if got != testCase.out {
62 t.Errorf("expected %q got %q", testCase.out, got)
63 }
64 })
65 }
66}
67
68func TestJacocoFiltersToZipCommand(t *testing.T) {
69 testCases := []struct {
70 name string
71 includes, excludes []string
72 out string
73 }{
74 {
75 name: "implicit wildcard",
76 includes: []string{},
Maxim Pleshivenkov9d773842021-06-30 10:31:46 -040077 out: "'**/*.class'",
Colin Cross7a3139e2017-12-19 13:57:50 -080078 },
79 {
80 name: "only include",
81 includes: []string{"package/Class.class"},
82 out: "package/Class.class",
83 },
84 {
85 name: "multiple includes",
86 includes: []string{"package/Class.class", "package2/Class.class"},
87 out: "package/Class.class package2/Class.class",
88 },
Colin Crossd7deceb2017-12-19 13:59:44 -080089 {
90 name: "excludes",
91 includes: []string{"package/**/*.class"},
92 excludes: []string{"package/Class.class"},
93 out: "-x package/Class.class package/**/*.class",
94 },
Colin Cross7a3139e2017-12-19 13:57:50 -080095 }
96
97 for _, testCase := range testCases {
98 t.Run(testCase.name, func(t *testing.T) {
99 got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes)
100 if got != testCase.out {
101 t.Errorf("expected %q got %q", testCase.out, got)
102 }
103 })
104 }
105}