1// 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 t.Parallel() 21 testCases := []struct { 22 name, in, out string 23 }{ 24 { 25 name: "class", 26 in: "package.Class", 27 out: "package/Class.class", 28 }, 29 { 30 name: "class wildcard", 31 in: "package.Class*", 32 out: "package/Class*.class", 33 }, 34 { 35 name: "package wildcard", 36 in: "package.*", 37 out: "package/*.class", 38 }, 39 { 40 name: "package recursive wildcard", 41 in: "package.**", 42 out: "package/**/*.class", 43 }, 44 { 45 name: "recursive wildcard only", 46 in: "**", 47 out: "**/*.class", 48 }, 49 { 50 name: "single wildcard only", 51 in: "*", 52 out: "*.class", 53 }, 54 } 55 56 for _, testCase := range testCases { 57 t.Run(testCase.name, func(t *testing.T) { 58 t.Parallel() 59 got, err := jacocoFilterToSpec(testCase.in) 60 if err != nil { 61 t.Error(err) 62 } 63 if got != testCase.out { 64 t.Errorf("expected %q got %q", testCase.out, got) 65 } 66 }) 67 } 68} 69 70func TestJacocoFiltersToZipCommand(t *testing.T) { 71 t.Parallel() 72 testCases := []struct { 73 name string 74 includes, excludes []string 75 out string 76 }{ 77 { 78 name: "implicit wildcard", 79 includes: []string{}, 80 out: "'**/*.class'", 81 }, 82 { 83 name: "only include", 84 includes: []string{"package/Class.class"}, 85 out: "package/Class.class", 86 }, 87 { 88 name: "multiple includes", 89 includes: []string{"package/Class.class", "package2/Class.class"}, 90 out: "package/Class.class package2/Class.class", 91 }, 92 { 93 name: "excludes", 94 includes: []string{"package/**/*.class"}, 95 excludes: []string{"package/Class.class"}, 96 out: "-x package/Class.class package/**/*.class", 97 }, 98 } 99 100 for _, testCase := range testCases { 101 t.Run(testCase.name, func(t *testing.T) { 102 t.Parallel() 103 got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes) 104 if got != testCase.out { 105 t.Errorf("expected %q got %q", testCase.out, got) 106 } 107 }) 108 } 109} 110