blob: d77c916cdd5e9e05766fb1d78c80fc990a707f1c [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) {
Colin Cross323dc602020-09-18 14:25:31 -070020 t.Parallel()
Colin Cross7a3139e2017-12-19 13:57:50 -080021 testCases := []struct {
22 name, in, out string
23 }{
24 {
Colin Crossd7deceb2017-12-19 13:59:44 -080025 name: "class",
26 in: "package.Class",
27 out: "package/Class.class",
28 },
29 {
Colin Cross7a3139e2017-12-19 13:57:50 -080030 name: "class wildcard",
31 in: "package.Class*",
32 out: "package/Class*.class",
33 },
34 {
35 name: "package wildcard",
36 in: "package.*",
Nan Zhangffe2c1c2018-01-25 13:53:22 -080037 out: "package/*.class",
38 },
39 {
40 name: "package recursive wildcard",
41 in: "package.**",
Colin Cross7a3139e2017-12-19 13:57:50 -080042 out: "package/**/*.class",
43 },
44 {
Nan Zhangffe2c1c2018-01-25 13:53:22 -080045 name: "recursive wildcard only",
46 in: "**",
Colin Cross7a3139e2017-12-19 13:57:50 -080047 out: "**/*.class",
48 },
Nan Zhangffe2c1c2018-01-25 13:53:22 -080049 {
50 name: "single wildcard only",
51 in: "*",
52 out: "*.class",
53 },
Colin Cross7a3139e2017-12-19 13:57:50 -080054 }
55
56 for _, testCase := range testCases {
57 t.Run(testCase.name, func(t *testing.T) {
58 got, err := jacocoFilterToSpec(testCase.in)
59 if err != nil {
60 t.Error(err)
61 }
62 if got != testCase.out {
63 t.Errorf("expected %q got %q", testCase.out, got)
64 }
65 })
66 }
67}
68
69func TestJacocoFiltersToZipCommand(t *testing.T) {
Colin Cross323dc602020-09-18 14:25:31 -070070 t.Parallel()
Colin Cross7a3139e2017-12-19 13:57:50 -080071 testCases := []struct {
72 name string
73 includes, excludes []string
74 out string
75 }{
76 {
77 name: "implicit wildcard",
78 includes: []string{},
79 out: "**/*.class",
80 },
81 {
82 name: "only include",
83 includes: []string{"package/Class.class"},
84 out: "package/Class.class",
85 },
86 {
87 name: "multiple includes",
88 includes: []string{"package/Class.class", "package2/Class.class"},
89 out: "package/Class.class package2/Class.class",
90 },
Colin Crossd7deceb2017-12-19 13:59:44 -080091 {
92 name: "excludes",
93 includes: []string{"package/**/*.class"},
94 excludes: []string{"package/Class.class"},
95 out: "-x package/Class.class package/**/*.class",
96 },
Colin Cross7a3139e2017-12-19 13:57:50 -080097 }
98
99 for _, testCase := range testCases {
100 t.Run(testCase.name, func(t *testing.T) {
101 got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes)
102 if got != testCase.out {
103 t.Errorf("expected %q got %q", testCase.out, got)
104 }
105 })
106 }
107}