blob: 8321017125b7e65c136c57da83f0c5be81d6e763 [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 {
24 name: "class wildcard",
25 in: "package.Class*",
26 out: "package/Class*.class",
27 },
28 {
29 name: "package wildcard",
30 in: "package.*",
31 out: "package/**/*.class",
32 },
33 {
34 name: "all wildcard",
35 in: "*",
36 out: "**/*.class",
37 },
38 }
39
40 for _, testCase := range testCases {
41 t.Run(testCase.name, func(t *testing.T) {
42 got, err := jacocoFilterToSpec(testCase.in)
43 if err != nil {
44 t.Error(err)
45 }
46 if got != testCase.out {
47 t.Errorf("expected %q got %q", testCase.out, got)
48 }
49 })
50 }
51}
52
53func TestJacocoFiltersToZipCommand(t *testing.T) {
54 testCases := []struct {
55 name string
56 includes, excludes []string
57 out string
58 }{
59 {
60 name: "implicit wildcard",
61 includes: []string{},
62 out: "**/*.class",
63 },
64 {
65 name: "only include",
66 includes: []string{"package/Class.class"},
67 out: "package/Class.class",
68 },
69 {
70 name: "multiple includes",
71 includes: []string{"package/Class.class", "package2/Class.class"},
72 out: "package/Class.class package2/Class.class",
73 },
74 }
75
76 for _, testCase := range testCases {
77 t.Run(testCase.name, func(t *testing.T) {
78 got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes)
79 if got != testCase.out {
80 t.Errorf("expected %q got %q", testCase.out, got)
81 }
82 })
83 }
84}