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.*", |
Nan Zhang | ffe2c1c | 2018-01-25 13:53:22 -0800 | [diff] [blame] | 36 | out: "package/*.class", |
| 37 | }, |
| 38 | { |
| 39 | name: "package recursive wildcard", |
| 40 | in: "package.**", |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 41 | out: "package/**/*.class", |
| 42 | }, |
| 43 | { |
Nan Zhang | ffe2c1c | 2018-01-25 13:53:22 -0800 | [diff] [blame] | 44 | name: "recursive wildcard only", |
| 45 | in: "**", |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 46 | out: "**/*.class", |
| 47 | }, |
Nan Zhang | ffe2c1c | 2018-01-25 13:53:22 -0800 | [diff] [blame] | 48 | { |
| 49 | name: "single wildcard only", |
| 50 | in: "*", |
| 51 | out: "*.class", |
| 52 | }, |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | for _, testCase := range testCases { |
| 56 | t.Run(testCase.name, func(t *testing.T) { |
| 57 | got, err := jacocoFilterToSpec(testCase.in) |
| 58 | if err != nil { |
| 59 | t.Error(err) |
| 60 | } |
| 61 | if got != testCase.out { |
| 62 | t.Errorf("expected %q got %q", testCase.out, got) |
| 63 | } |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestJacocoFiltersToZipCommand(t *testing.T) { |
| 69 | testCases := []struct { |
| 70 | name string |
| 71 | includes, excludes []string |
| 72 | out string |
| 73 | }{ |
| 74 | { |
| 75 | name: "implicit wildcard", |
| 76 | includes: []string{}, |
| 77 | out: "**/*.class", |
| 78 | }, |
| 79 | { |
| 80 | name: "only include", |
| 81 | includes: []string{"package/Class.class"}, |
| 82 | out: "package/Class.class", |
| 83 | }, |
| 84 | { |
| 85 | name: "multiple includes", |
| 86 | includes: []string{"package/Class.class", "package2/Class.class"}, |
| 87 | out: "package/Class.class package2/Class.class", |
| 88 | }, |
Colin Cross | d7deceb | 2017-12-19 13:59:44 -0800 | [diff] [blame] | 89 | { |
| 90 | name: "excludes", |
| 91 | includes: []string{"package/**/*.class"}, |
| 92 | excludes: []string{"package/Class.class"}, |
| 93 | out: "-x package/Class.class package/**/*.class", |
| 94 | }, |
Colin Cross | 7a3139e | 2017-12-19 13:57:50 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | for _, testCase := range testCases { |
| 98 | t.Run(testCase.name, func(t *testing.T) { |
| 99 | got := jacocoFiltersToZipCommand(testCase.includes, testCase.excludes) |
| 100 | if got != testCase.out { |
| 101 | t.Errorf("expected %q got %q", testCase.out, got) |
| 102 | } |
| 103 | }) |
| 104 | } |
| 105 | } |