2015-04-23 22:29:28 +02:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package pathtools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2019-03-25 23:04:17 +01:00
|
|
|
"strings"
|
2015-04-23 22:29:28 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var pwd, _ = os.Getwd()
|
|
|
|
|
2017-10-04 00:58:50 +02:00
|
|
|
type globTestCase struct {
|
2015-04-24 02:56:11 +02:00
|
|
|
pattern string
|
|
|
|
matches []string
|
|
|
|
excludes []string
|
2017-06-23 02:01:24 +02:00
|
|
|
deps []string
|
2015-04-24 02:56:11 +02:00
|
|
|
err error
|
2017-10-04 00:58:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var globTestCases = []globTestCase{
|
2015-04-23 22:29:28 +02:00
|
|
|
// Current directory tests
|
|
|
|
{
|
|
|
|
pattern: "*",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/", "b/", "c/", "d.ext", "e.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*.ext",
|
|
|
|
matches: []string{"d.ext", "e.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "b/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*/a",
|
|
|
|
matches: []string{"a/a/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c", "a/a", "a/b", "c/f", "c/g", "c/h"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/a/a",
|
|
|
|
matches: []string{"a/a/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c", "a/a"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
2018-09-19 22:36:42 +02:00
|
|
|
{
|
|
|
|
pattern: "c/*/?",
|
|
|
|
matches: []string{"c/h/h"},
|
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "c/*/[gh]*",
|
|
|
|
matches: []string{"c/g/g.ext", "c/h/h"},
|
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "c/*/[fgh]*",
|
|
|
|
matches: []string{"c/f/f.ext", "c/g/g.ext", "c/h/h"},
|
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "c/*/[f-h]*",
|
|
|
|
matches: []string{"c/f/f.ext", "c/g/g.ext", "c/h/h"},
|
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
|
|
|
},
|
2015-04-23 22:29:28 +02:00
|
|
|
// ./ directory tests
|
|
|
|
{
|
|
|
|
pattern: "./*",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/", "b/", "c/", "d.ext", "e.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "./*.ext",
|
|
|
|
matches: []string{"d.ext", "e.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "./*/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "b/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "./[ac]/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "c"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// subdirectory tests
|
|
|
|
{
|
|
|
|
pattern: "c/*/*.ext",
|
|
|
|
matches: []string{"c/f/f.ext", "c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/*/a",
|
|
|
|
matches: []string{"a/a/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a", "a/a", "a/b"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// absolute tests
|
|
|
|
{
|
2018-09-21 23:13:03 +02:00
|
|
|
pattern: filepath.Join(pwd, "testdata/glob/c/*/*.ext"),
|
2015-04-23 22:29:28 +02:00
|
|
|
matches: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c/f/f.ext"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g/g.ext"),
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/h"),
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// no-wild tests
|
|
|
|
{
|
|
|
|
pattern: "a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a/a"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// clean tests
|
|
|
|
{
|
2015-04-24 02:56:11 +02:00
|
|
|
pattern: "./c/*/*.ext",
|
|
|
|
matches: []string{"c/f/f.ext", "c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
|
|
|
{
|
2015-04-24 02:56:11 +02:00
|
|
|
pattern: "c/../c/*/*.ext",
|
|
|
|
matches: []string{"c/f/f.ext", "c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-23 22:29:28 +02:00
|
|
|
},
|
2015-04-24 00:45:25 +02:00
|
|
|
|
|
|
|
// recursive tests
|
|
|
|
{
|
|
|
|
pattern: "**/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/", "a/a/", "a/a/a", "b/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "a/a", "a/b", "b", "c", "c/f", "c/g", "c/h"},
|
2015-04-24 00:45:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/**/a",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "a/a/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a", "a/a", "a/b"},
|
2015-04-24 00:45:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/**/*",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "a/b/", "a/a/a", "a/b/b"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a", "a/a", "a/b"},
|
2015-04-24 00:45:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// absolute recursive tests
|
|
|
|
{
|
2018-09-21 23:13:03 +02:00
|
|
|
pattern: filepath.Join(pwd, "testdata/glob/**/*.ext"),
|
2015-04-24 00:45:25 +02:00
|
|
|
matches: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/d.ext"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/e.ext"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f/f.ext"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g/g.ext"),
|
2015-04-24 00:45:25 +02:00
|
|
|
},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/a"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/a/a"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/a/b"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/b"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/h"),
|
2015-04-24 00:45:25 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// recursive error tests
|
|
|
|
{
|
|
|
|
pattern: "**/**/*",
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/**/**/*",
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/a/**/*",
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/**/a/*",
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/**",
|
|
|
|
err: GlobLastRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/**",
|
|
|
|
err: GlobLastRecursiveErr,
|
|
|
|
},
|
2019-03-25 23:04:17 +01:00
|
|
|
{
|
|
|
|
pattern: "a**/",
|
|
|
|
err: GlobInvalidRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**a/",
|
|
|
|
err: GlobInvalidRecursiveErr,
|
|
|
|
},
|
2015-04-24 02:56:11 +02:00
|
|
|
|
|
|
|
// exclude tests
|
|
|
|
{
|
|
|
|
pattern: "*.ext",
|
|
|
|
excludes: []string{"d.ext"},
|
|
|
|
matches: []string{"e.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"a/b"},
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "b/a", "c/c", "c/f/", "c/g/", "c/h/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"a/b", "c/c"},
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "b/a", "c/f/", "c/g/", "c/h/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"c/*", "*/a"},
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/b/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"*/*"},
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// absolute exclude tests
|
|
|
|
{
|
2018-09-21 23:13:03 +02:00
|
|
|
pattern: filepath.Join(pwd, "testdata/glob/c/*/*.ext"),
|
|
|
|
excludes: []string{filepath.Join(pwd, "testdata/glob/c/*/f.ext")},
|
2015-04-24 02:56:11 +02:00
|
|
|
matches: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c/g/g.ext"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/h"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2018-09-21 23:13:03 +02:00
|
|
|
pattern: filepath.Join(pwd, "testdata/glob/c/*/*.ext"),
|
|
|
|
excludes: []string{filepath.Join(pwd, "testdata/glob/c/f/*.ext")},
|
2015-04-24 02:56:11 +02:00
|
|
|
matches: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c/g/g.ext"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/h"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// recursive exclude tests
|
|
|
|
{
|
|
|
|
pattern: "*.ext",
|
|
|
|
excludes: []string{"**/*.ext"},
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"**/b"},
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"a/a/", "b/a", "c/c", "c/f/", "c/g/", "c/h/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*",
|
|
|
|
excludes: []string{"a/**/*"},
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{"b/a", "c/c", "c/f/", "c/g/", "c/h/"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"**/*"},
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "a/a", "a/b", "b", "c", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*/*",
|
|
|
|
excludes: []string{"a/**/a"},
|
|
|
|
matches: []string{"a/b/b", "c/f/f.ext", "c/g/g.ext", "c/h/h"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c", "a/a", "a/b", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "*/*/*",
|
|
|
|
excludes: []string{"**/a"},
|
|
|
|
matches: []string{"a/b/b", "c/f/f.ext", "c/g/g.ext", "c/h/h"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", "a", "b", "c", "a/a", "a/b", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "c/*/*.ext",
|
|
|
|
excludes: []string{"c/**/f.ext"},
|
|
|
|
matches: []string{"c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// absoulte recursive exclude tests
|
|
|
|
{
|
2018-09-21 23:13:03 +02:00
|
|
|
pattern: filepath.Join(pwd, "testdata/glob/c/*/*.ext"),
|
|
|
|
excludes: []string{filepath.Join(pwd, "testdata/glob/**/f.ext")},
|
2015-04-24 02:56:11 +02:00
|
|
|
matches: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c/g/g.ext"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{
|
2018-09-21 23:13:03 +02:00
|
|
|
filepath.Join(pwd, "testdata/glob/c"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/f"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/g"),
|
|
|
|
filepath.Join(pwd, "testdata/glob/c/h"),
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// clean exclude tests
|
|
|
|
{
|
|
|
|
pattern: "./c/*/*.ext",
|
|
|
|
excludes: []string{"./c/*/f.ext"},
|
|
|
|
matches: []string{"c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "c/*/*.ext",
|
|
|
|
excludes: []string{"./c/*/f.ext"},
|
|
|
|
matches: []string{"c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "./c/*/*.ext",
|
|
|
|
excludes: []string{"c/*/f.ext"},
|
|
|
|
matches: []string{"c/g/g.ext"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"c", "c/f", "c/g", "c/h"},
|
2015-04-24 02:56:11 +02:00
|
|
|
},
|
|
|
|
|
2015-06-18 19:48:15 +02:00
|
|
|
// non-existant non-wild path tests
|
|
|
|
{
|
|
|
|
pattern: "d/*",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "d",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d/*",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/a/d/*",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a/a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/a/d",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a/a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d/a/*",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d/a",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d/a/*/a",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "a/d/a/**/a",
|
|
|
|
matches: nil,
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"a"},
|
2015-06-18 19:48:15 +02:00
|
|
|
},
|
|
|
|
|
2015-04-24 02:56:11 +02:00
|
|
|
// recursive exclude error tests
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"**/**/*"},
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"a/**/**/*"},
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"**/a/**/*"},
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"**/**/a/*"},
|
|
|
|
err: GlobMultipleRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"a/**"},
|
|
|
|
err: GlobLastRecursiveErr,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "**/*",
|
|
|
|
excludes: []string{"**/**"},
|
|
|
|
err: GlobLastRecursiveErr,
|
|
|
|
},
|
2016-07-26 03:40:02 +02:00
|
|
|
|
|
|
|
// If names are excluded by default, but referenced explicitly, they should return results
|
|
|
|
{
|
|
|
|
pattern: ".test/*",
|
|
|
|
matches: []string{".test/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".test"},
|
2016-07-26 03:40:02 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: ".t*/a",
|
|
|
|
matches: []string{".test/a"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", ".test"},
|
2016-07-26 03:40:02 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: ".*/.*",
|
|
|
|
matches: []string{".test/.ing"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{".", ".test"},
|
2016-07-26 03:40:02 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: ".t*",
|
2018-02-23 23:49:45 +01:00
|
|
|
matches: []string{".test/", ".testing"},
|
2017-06-23 02:01:24 +02:00
|
|
|
deps: []string{"."},
|
2016-07-26 03:40:02 +02:00
|
|
|
},
|
2015-04-23 22:29:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-04 00:58:50 +02:00
|
|
|
func TestMockGlob(t *testing.T) {
|
|
|
|
files := []string{
|
|
|
|
"a/a/a",
|
|
|
|
"a/b/b",
|
|
|
|
"b/a",
|
|
|
|
"c/c",
|
|
|
|
"c/f/f.ext",
|
|
|
|
"c/g/g.ext",
|
|
|
|
"c/h/h",
|
|
|
|
"d.ext",
|
|
|
|
"e.ext",
|
|
|
|
".test/a",
|
|
|
|
".testing",
|
|
|
|
".test/.ing",
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
2018-09-21 23:13:03 +02:00
|
|
|
mockFiles[filepath.Join(pwd, "testdata/glob", f)] = nil
|
2017-10-04 00:58:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
2018-09-19 22:36:42 +02:00
|
|
|
for _, testCase := range globTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, mock, testCase, FollowSymlinks)
|
2017-10-04 00:58:50 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 22:29:28 +02:00
|
|
|
func TestGlob(t *testing.T) {
|
2018-09-21 23:13:03 +02:00
|
|
|
os.Chdir("testdata/glob")
|
|
|
|
defer os.Chdir("../..")
|
2018-09-19 22:36:42 +02:00
|
|
|
for _, testCase := range globTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, OsFs, testCase, FollowSymlinks)
|
2017-10-04 00:58:50 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 22:36:42 +02:00
|
|
|
var globEscapeTestCases = []globTestCase{
|
|
|
|
{
|
|
|
|
pattern: `**/*`,
|
|
|
|
matches: []string{`*`, `**/`, `?`, `a/`, `b`, `**/*`, `**/a`, `**/b/`, `**/b/b`, `a/a`},
|
|
|
|
deps: []string{`.`, `**`, `**/b`, `a`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `**/\*`,
|
|
|
|
matches: []string{`*`, `**/*`},
|
|
|
|
deps: []string{`.`, `**`, `**/b`, `a`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `\*\*/*`,
|
|
|
|
matches: []string{`**/*`, `**/a`, `**/b/`},
|
|
|
|
deps: []string{`.`, `**`},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `\*\*/**/*`,
|
|
|
|
matches: []string{`**/*`, `**/a`, `**/b/`, `**/b/b`},
|
|
|
|
deps: []string{`.`, `**`, `**/b`},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:13:03 +02:00
|
|
|
func TestMockGlobEscapes(t *testing.T) {
|
2018-09-19 22:36:42 +02:00
|
|
|
files := []string{
|
|
|
|
`*`,
|
|
|
|
`**/*`,
|
|
|
|
`**/a`,
|
|
|
|
`**/b/b`,
|
|
|
|
`?`,
|
|
|
|
`a/a`,
|
|
|
|
`b`,
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
|
|
|
for _, testCase := range globEscapeTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, mock, testCase, FollowSymlinks)
|
2018-09-19 22:36:42 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:13:03 +02:00
|
|
|
func TestGlobEscapes(t *testing.T) {
|
|
|
|
os.Chdir("testdata/escapes")
|
|
|
|
defer os.Chdir("../..")
|
|
|
|
for _, testCase := range globEscapeTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, OsFs, testCase, FollowSymlinks)
|
2018-09-21 23:13:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-21 07:44:36 +02:00
|
|
|
var globSymlinkTestCases = []globTestCase{
|
|
|
|
{
|
|
|
|
pattern: `**/*`,
|
|
|
|
matches: []string{"a/", "b/", "c/", "d/", "e", "a/a/", "a/a/a", "b/a/", "b/a/a", "c/a", "d/a"},
|
|
|
|
deps: []string{".", "a", "a/a", "b", "b/a", "c", "d"},
|
|
|
|
},
|
2018-09-22 00:30:13 +02:00
|
|
|
{
|
|
|
|
pattern: `b/**/*`,
|
|
|
|
matches: []string{"b/a/", "b/a/a"},
|
|
|
|
deps: []string{"b", "b/a"},
|
|
|
|
},
|
2018-09-21 07:44:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMockGlobSymlinks(t *testing.T) {
|
|
|
|
files := []string{
|
|
|
|
"a/a/a",
|
|
|
|
"b -> a",
|
|
|
|
"c -> a/a",
|
|
|
|
"d -> c",
|
|
|
|
"e -> a/a/a",
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
|
|
|
for _, testCase := range globSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, mock, testCase, FollowSymlinks)
|
2018-09-21 07:44:36 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGlobSymlinks(t *testing.T) {
|
|
|
|
os.Chdir("testdata/symlinks")
|
|
|
|
defer os.Chdir("../..")
|
|
|
|
|
|
|
|
for _, testCase := range globSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
2018-09-22 00:30:13 +02:00
|
|
|
testGlob(t, OsFs, testCase, FollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var globDontFollowSymlinkTestCases = []globTestCase{
|
|
|
|
{
|
|
|
|
pattern: `**/*`,
|
|
|
|
matches: []string{"a/", "b", "c", "d", "e", "a/a/", "a/a/a"},
|
|
|
|
deps: []string{".", "a", "a/a"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `b/**/*`,
|
|
|
|
matches: []string{"b/a/", "b/a/a"},
|
|
|
|
deps: []string{"b", "b/a"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMockGlobDontFollowSymlinks(t *testing.T) {
|
|
|
|
files := []string{
|
|
|
|
"a/a/a",
|
|
|
|
"b -> a",
|
|
|
|
"c -> a/a",
|
|
|
|
"d -> c",
|
|
|
|
"e -> a/a/a",
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
|
|
|
for _, testCase := range globDontFollowSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, mock, testCase, DontFollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGlobDontFollowSymlinks(t *testing.T) {
|
|
|
|
os.Chdir("testdata/symlinks")
|
|
|
|
defer os.Chdir("../..")
|
|
|
|
|
|
|
|
for _, testCase := range globDontFollowSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, OsFs, testCase, DontFollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var globDontFollowDanglingSymlinkTestCases = []globTestCase{
|
|
|
|
{
|
|
|
|
pattern: `**/*`,
|
|
|
|
matches: []string{"a/", "b", "c", "d", "dangling", "e", "f", "a/a/", "a/a/a", "a/a/f"},
|
|
|
|
deps: []string{".", "a", "a/a"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `dangling`,
|
|
|
|
matches: []string{"dangling"},
|
|
|
|
deps: []string{"dangling"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMockGlobDontFollowDanglingSymlinks(t *testing.T) {
|
|
|
|
files := []string{
|
|
|
|
"a/a/a",
|
|
|
|
"a/a/f -> ../../f",
|
|
|
|
"b -> a",
|
|
|
|
"c -> a/a",
|
|
|
|
"d -> c",
|
|
|
|
"e -> a/a/a",
|
|
|
|
"f",
|
|
|
|
"dangling -> missing",
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
|
|
|
for _, testCase := range globDontFollowDanglingSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, mock, testCase, DontFollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGlobDontFollowDanglingSymlinks(t *testing.T) {
|
|
|
|
os.Chdir("testdata/dangling")
|
|
|
|
defer os.Chdir("../..")
|
|
|
|
|
|
|
|
for _, testCase := range globDontFollowDanglingSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, OsFs, testCase, DontFollowSymlinks)
|
2018-09-21 07:44:36 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 02:50:17 +02:00
|
|
|
var globFollowDanglingSymlinkTestCases = []globTestCase{
|
|
|
|
{
|
|
|
|
pattern: `**/*`,
|
|
|
|
matches: []string{"a/", "b/", "c/", "d/", "dangling", "e", "f", "a/a/", "a/a/a", "a/a/f", "b/a/", "b/a/a", "b/a/f", "c/a", "c/f", "d/a", "d/f"},
|
|
|
|
deps: []string{".", "a", "a/a", "b", "b/a", "c", "d"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: `dangling`,
|
|
|
|
matches: []string{"dangling"},
|
|
|
|
deps: []string{"dangling"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMockGlobFollowDanglingSymlinks(t *testing.T) {
|
|
|
|
files := []string{
|
|
|
|
"a/a/a",
|
|
|
|
"a/a/f -> ../../f",
|
|
|
|
"b -> a",
|
|
|
|
"c -> a/a",
|
|
|
|
"d -> c",
|
|
|
|
"e -> a/a/a",
|
|
|
|
"f",
|
|
|
|
"dangling -> missing",
|
|
|
|
}
|
|
|
|
|
|
|
|
mockFiles := make(map[string][]byte)
|
|
|
|
|
|
|
|
for _, f := range files {
|
|
|
|
mockFiles[f] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
|
|
|
for _, testCase := range globFollowDanglingSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, mock, testCase, FollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGlobFollowDanglingSymlinks(t *testing.T) {
|
|
|
|
os.Chdir("testdata/dangling")
|
|
|
|
defer os.Chdir("../..")
|
|
|
|
|
|
|
|
for _, testCase := range globFollowDanglingSymlinkTestCases {
|
|
|
|
t.Run(testCase.pattern, func(t *testing.T) {
|
|
|
|
testGlob(t, OsFs, testCase, FollowSymlinks)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-22 00:30:13 +02:00
|
|
|
func testGlob(t *testing.T, fs FileSystem, testCase globTestCase, follow ShouldFollowSymlinks) {
|
2018-09-21 23:13:03 +02:00
|
|
|
t.Helper()
|
2021-04-07 23:28:13 +02:00
|
|
|
result, err := fs.Glob(testCase.pattern, testCase.excludes, follow)
|
2017-10-04 00:58:50 +02:00
|
|
|
if err != testCase.err {
|
2018-09-19 22:36:42 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("missing error: %s", testCase.err)
|
|
|
|
} else {
|
|
|
|
t.Fatalf("error: %s", err)
|
2015-04-23 22:29:28 +02:00
|
|
|
}
|
2017-10-04 00:58:50 +02:00
|
|
|
return
|
|
|
|
}
|
2015-04-23 22:29:28 +02:00
|
|
|
|
2021-04-07 23:28:13 +02:00
|
|
|
if !reflect.DeepEqual(result.Matches, testCase.matches) {
|
2017-10-04 00:58:50 +02:00
|
|
|
t.Errorf("incorrect matches list:")
|
|
|
|
t.Errorf(" pattern: %q", testCase.pattern)
|
|
|
|
if testCase.excludes != nil {
|
|
|
|
t.Errorf("excludes: %q", testCase.excludes)
|
2015-04-23 22:29:28 +02:00
|
|
|
}
|
2021-04-07 23:28:13 +02:00
|
|
|
t.Errorf(" got: %#v", result.Matches)
|
2017-10-04 00:58:50 +02:00
|
|
|
t.Errorf("expected: %#v", testCase.matches)
|
|
|
|
}
|
2021-04-07 23:28:13 +02:00
|
|
|
if !reflect.DeepEqual(result.Deps, testCase.deps) {
|
2017-10-04 00:58:50 +02:00
|
|
|
t.Errorf("incorrect deps list:")
|
|
|
|
t.Errorf(" pattern: %q", testCase.pattern)
|
|
|
|
if testCase.excludes != nil {
|
|
|
|
t.Errorf("excludes: %q", testCase.excludes)
|
2015-04-23 22:29:28 +02:00
|
|
|
}
|
2021-04-07 23:28:13 +02:00
|
|
|
t.Errorf(" got: %#v", result.Deps)
|
2017-10-04 00:58:50 +02:00
|
|
|
t.Errorf("expected: %#v", testCase.deps)
|
2015-04-23 22:29:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-14 06:17:48 +02:00
|
|
|
|
|
|
|
func TestMatch(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
pattern, name string
|
|
|
|
match bool
|
|
|
|
}{
|
|
|
|
{"a/*", "b/", false},
|
|
|
|
{"a/*", "b/a", false},
|
|
|
|
{"a/*", "b/b/", false},
|
|
|
|
{"a/*", "b/b/c", false},
|
|
|
|
{"a/**/*", "b/", false},
|
|
|
|
{"a/**/*", "b/a", false},
|
|
|
|
{"a/**/*", "b/b/", false},
|
|
|
|
{"a/**/*", "b/b/c", false},
|
|
|
|
|
|
|
|
{"a/*", "a/", false},
|
|
|
|
{"a/*", "a/a", true},
|
|
|
|
{"a/*", "a/b/", false},
|
|
|
|
{"a/*", "a/b/c", false},
|
|
|
|
|
|
|
|
{"a/*/", "a/", false},
|
|
|
|
{"a/*/", "a/a", false},
|
|
|
|
{"a/*/", "a/b/", true},
|
|
|
|
{"a/*/", "a/b/c", false},
|
|
|
|
|
|
|
|
{"a/**/*", "a/", false},
|
|
|
|
{"a/**/*", "a/a", true},
|
|
|
|
{"a/**/*", "a/b/", false},
|
|
|
|
{"a/**/*", "a/b/c", true},
|
|
|
|
|
|
|
|
{"a/**/*/", "a/", false},
|
|
|
|
{"a/**/*/", "a/a", false},
|
|
|
|
{"a/**/*/", "a/b/", true},
|
|
|
|
{"a/**/*/", "a/b/c", false},
|
2018-09-19 22:36:42 +02:00
|
|
|
|
2019-03-25 23:04:17 +01:00
|
|
|
{"**/*", "a/", false},
|
|
|
|
{"**/*", "a/a", true},
|
|
|
|
{"**/*", "a/b/", false},
|
|
|
|
{"**/*", "a/b/c", true},
|
|
|
|
|
|
|
|
{"**/*/", "a/", true},
|
|
|
|
{"**/*/", "a/a", false},
|
|
|
|
{"**/*/", "a/b/", true},
|
|
|
|
{"**/*/", "a/b/c", false},
|
|
|
|
|
2018-09-19 22:36:42 +02:00
|
|
|
{`a/\*\*/\*`, `a/**/*`, true},
|
|
|
|
{`a/\*\*/\*`, `a/a/*`, false},
|
|
|
|
{`a/\*\*/\*`, `a/**/a`, false},
|
|
|
|
{`a/\*\*/\*`, `a/a/a`, false},
|
|
|
|
|
|
|
|
{`a/**/\*`, `a/**/*`, true},
|
|
|
|
{`a/**/\*`, `a/a/*`, true},
|
|
|
|
{`a/**/\*`, `a/**/a`, false},
|
|
|
|
{`a/**/\*`, `a/a/a`, false},
|
|
|
|
|
|
|
|
{`a/\*\*/*`, `a/**/*`, true},
|
|
|
|
{`a/\*\*/*`, `a/a/*`, false},
|
|
|
|
{`a/\*\*/*`, `a/**/a`, true},
|
|
|
|
{`a/\*\*/*`, `a/a/a`, false},
|
|
|
|
|
|
|
|
{`*/**/a`, `a/a/a`, true},
|
|
|
|
{`*/**/a`, `*/a/a`, true},
|
|
|
|
{`*/**/a`, `a/**/a`, true},
|
|
|
|
{`*/**/a`, `*/**/a`, true},
|
|
|
|
|
|
|
|
{`\*/\*\*/a`, `a/a/a`, false},
|
|
|
|
{`\*/\*\*/a`, `*/a/a`, false},
|
|
|
|
{`\*/\*\*/a`, `a/**/a`, false},
|
|
|
|
{`\*/\*\*/a`, `*/**/a`, true},
|
|
|
|
|
|
|
|
{`a/?`, `a/?`, true},
|
|
|
|
{`a/?`, `a/a`, true},
|
|
|
|
{`a/\?`, `a/?`, true},
|
|
|
|
{`a/\?`, `a/a`, false},
|
|
|
|
|
|
|
|
{`a/?`, `a/?`, true},
|
|
|
|
{`a/?`, `a/a`, true},
|
|
|
|
{`a/\?`, `a/?`, true},
|
|
|
|
{`a/\?`, `a/a`, false},
|
|
|
|
|
|
|
|
{`a/[a-c]`, `a/b`, true},
|
|
|
|
{`a/[abc]`, `a/b`, true},
|
|
|
|
|
|
|
|
{`a/\[abc]`, `a/b`, false},
|
|
|
|
{`a/\[abc]`, `a/[abc]`, true},
|
|
|
|
|
|
|
|
{`a/\[abc\]`, `a/b`, false},
|
|
|
|
{`a/\[abc\]`, `a/[abc]`, true},
|
|
|
|
|
|
|
|
{`a/?`, `a/?`, true},
|
|
|
|
{`a/?`, `a/a`, true},
|
|
|
|
{`a/\?`, `a/?`, true},
|
|
|
|
{`a/\?`, `a/a`, false},
|
2019-03-25 23:04:17 +01:00
|
|
|
|
|
|
|
{"/a/*", "/a/", false},
|
|
|
|
{"/a/*", "/a/a", true},
|
|
|
|
{"/a/*", "/a/b/", false},
|
|
|
|
{"/a/*", "/a/b/c", false},
|
|
|
|
|
|
|
|
{"/a/*/", "/a/", false},
|
|
|
|
{"/a/*/", "/a/a", false},
|
|
|
|
{"/a/*/", "/a/b/", true},
|
|
|
|
{"/a/*/", "/a/b/c", false},
|
|
|
|
|
|
|
|
{"/a/**/*", "/a/", false},
|
|
|
|
{"/a/**/*", "/a/a", true},
|
|
|
|
{"/a/**/*", "/a/b/", false},
|
|
|
|
{"/a/**/*", "/a/b/c", true},
|
|
|
|
|
|
|
|
{"/**/*", "/a/", false},
|
|
|
|
{"/**/*", "/a/a", true},
|
|
|
|
{"/**/*", "/a/b/", false},
|
|
|
|
{"/**/*", "/a/b/c", true},
|
|
|
|
|
|
|
|
{"/**/*/", "/a/", true},
|
|
|
|
{"/**/*/", "/a/a", false},
|
|
|
|
{"/**/*/", "/a/b/", true},
|
|
|
|
{"/**/*/", "/a/b/c", false},
|
|
|
|
|
|
|
|
{`a`, `/a`, false},
|
|
|
|
{`/a`, `a`, false},
|
|
|
|
{`*`, `/a`, false},
|
|
|
|
{`/*`, `a`, false},
|
|
|
|
{`**/*`, `/a`, false},
|
|
|
|
{`/**/*`, `a`, false},
|
2018-07-14 06:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.pattern+","+test.name, func(t *testing.T) {
|
|
|
|
match, err := Match(test.pattern, test.name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if match != test.match {
|
|
|
|
t.Errorf("want: %v, got %v", test.match, match)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-03-25 23:04:17 +01:00
|
|
|
|
|
|
|
// Run the same test cases through Glob
|
|
|
|
for _, test := range testCases {
|
|
|
|
// Glob and Match disagree on matching directories
|
|
|
|
if strings.HasSuffix(test.name, "/") || strings.HasSuffix(test.pattern, "/") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
t.Run("glob:"+test.pattern+","+test.name, func(t *testing.T) {
|
|
|
|
mockFiles := map[string][]byte{
|
|
|
|
test.name: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
mock := MockFs(mockFiles)
|
|
|
|
|
2021-04-07 23:28:13 +02:00
|
|
|
result, err := mock.Glob(test.pattern, nil, DontFollowSymlinks)
|
|
|
|
t.Log(test.name, test.pattern, result.Matches)
|
2019-03-25 23:04:17 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
match := false
|
2021-04-07 23:28:13 +02:00
|
|
|
for _, x := range result.Matches {
|
2019-03-25 23:04:17 +01:00
|
|
|
if x == test.name {
|
|
|
|
match = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if match != test.match {
|
|
|
|
t.Errorf("want: %v, got %v", test.match, match)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-07-14 06:17:48 +02:00
|
|
|
}
|