Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 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 | |
| 15 | package java |
| 16 | |
| 17 | import "testing" |
| 18 | |
| 19 | func TestJacocoFilterToSpecs(t *testing.T) { |
| 20 | testCases := []struct { |
| 21 | name, in, out string |
| 22 | }{ |
| 23 | { |
Colin Cross | d7deceb | 2017-12-19 13:59:44 -0800 | [diff] [blame^] | 24 | name: "class", |
| 25 | in: "package.Class", |
| 26 | out: "package/Class.class", |
| 27 | }, |
| 28 | { |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 29 | 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 | |
| 58 | func 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 Cross | d7deceb | 2017-12-19 13:59:44 -0800 | [diff] [blame^] | 79 | { |
| 80 | name: "excludes", |
| 81 | includes: []string{"package/**/*.class"}, |
| 82 | excludes: []string{"package/Class.class"}, |
| 83 | out: "-x package/Class.class package/**/*.class", |
| 84 | }, |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 85 | } |
| 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 | } |