blob: 6e8b026536e0baf26b09779f816e089d1d75e5c8 [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.*",
36 out: "package/**/*.class",
37 },
38 {
39 name: "all wildcard",
40 in: "*",
41 out: "**/*.class",
42 },
43 }
44
45 for _, testCase := range testCases {
46 t.Run(testCase.name, func(t *testing.T) {
47 got, err := jacocoFilterToSpec(testCase.in)
48 if err != nil {
49 t.Error(err)
50 }
51 if got != testCase.out {
52 t.Errorf("expected %q got %q", testCase.out, got)
53 }
54 })
55 }
56}
57
58func TestJacocoFiltersToZipCommand(t *testing.T) {
59 testCases := []struct {
60 name string
61 includes, excludes []string
62 out string
63 }{
64 {
65 name: "implicit wildcard",
66 includes: []string{},
67 out: "**/*.class",
68 },
69 {
70 name: "only include",
71 includes: []string{"package/Class.class"},
72 out: "package/Class.class",
73 },
74 {
75 name: "multiple includes",
76 includes: []string{"package/Class.class", "package2/Class.class"},
77 out: "package/Class.class package2/Class.class",
78 },
Colin Crossd7deceb2017-12-19 13:59:44 -080079 {
80 name: "excludes",
81 includes: []string{"package/**/*.class"},
82 excludes: []string{"package/Class.class"},
83 out: "-x package/Class.class package/**/*.class",
84 },
Colin Cross7a3139e2017-12-19 13:57:50 -080085 }
86
87 for _, testCase := range testCases {
88 t.Run(testCase.name, func(t *testing.T) {
89 got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes)
90 if got != testCase.out {
91 t.Errorf("expected %q got %q", testCase.out, got)
92 }
93 })
94 }
95}