diff options
author | 2016-06-06 17:45:48 +0000 | |
---|---|---|
committer | 2016-06-07 07:48:01 +0000 | |
commit | 7853e042aa484a957d952d848e79ff65e7156550 (patch) | |
tree | 63cc6735908eff80e5fa2b38ac7eecde0cdb1811 /src/test/java/com/google/devtools/build | |
parent | 146ecf9883883a97cf9c25b0b8e478fc3e5e2c22 (diff) |
Remove the dead UnixGlob#Builder#addExcludes and move some existing tests around so that we still have good test coverage for 'excludes' in globs.
--
MOS_MIGRATED_REVID=124152499
Diffstat (limited to 'src/test/java/com/google/devtools/build')
3 files changed, 65 insertions, 134 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/GlobCacheTest.java b/src/test/java/com/google/devtools/build/lib/packages/GlobCacheTest.java index 62f5ca1f0c..11d301f4f8 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/GlobCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/GlobCacheTest.java @@ -237,6 +237,61 @@ public class GlobCacheTest { "foo/second.js", "bar/second.js"); } + @Test + public void testSingleFileExclude_Star() throws Exception { + assertThat(cache.glob(list("*"), list("first.txt"), false)).containsExactly( + "BUILD", "bar", "first.js", "foo", "second.js", "second.txt").inOrder(); + } + + @Test + public void testSingleFileExclude_StarStar() throws Exception { + assertThat(cache.glob(list("**"), list("first.txt"), false)).containsExactly( + "BUILD", "bar", "bar/first.js", "bar/second.js", "first.js", "foo", "foo/first.js", + "foo/second.js", "second.js", "second.txt").inOrder(); + } + + @Test + public void testExcludeAll_Star() throws Exception { + assertThat(cache.glob(list("*"), list("*"), false)).isEmpty(); + } + + @Test + public void testExcludeAll_Star_NoMatchesAnyway() throws Exception { + assertThat(cache.glob(list("nope"), list("*"), false)).isEmpty(); + } + + @Test + public void testExcludeAll_StarStar() throws Exception { + assertThat(cache.glob(list("**"), list("**"), false)).isEmpty(); + } + + @Test + public void testExcludeAll_Manual() throws Exception { + assertThat(cache.glob(list("**"), list("*", "*/*", "*/*/*"), false)).isEmpty(); + } + + @Test + public void testSingleFileExcludeDoesntMatch() throws Exception { + assertThat(cache.glob(list("first.txt"), list("nope.txt"), false)).containsExactly("first.txt"); + } + + @Test + public void testExcludeDirectory() throws Exception { + assertThat(cache.glob(list("foo/*"), NONE, true)).containsExactly( + "foo/first.js", "foo/second.js"); + assertThat(cache.glob(list("foo/*"), list("foo"), false)).containsExactly( + "foo/first.js", "foo/second.js"); + } + + @Test + public void testChildGlobWithChildExclude() throws Exception { + assertThat(cache.glob(list("foo/*"), list("foo/*"), false)).isEmpty(); + assertThat(cache.glob(list("foo/first.js", "foo/second.js"), list("foo/*"), false)).isEmpty(); + assertThat(cache.glob(list("foo/first.js"), list("foo/first.js"), false)).isEmpty(); + assertThat(cache.glob(list("foo/first.js"), list("*/first.js"), false)).isEmpty(); + assertThat(cache.glob(list("foo/first.js"), list("*/*"), false)).isEmpty(); + } + private void assertEmpty(Collection<?> glob) { assertThat(glob).isEmpty(); } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java index 1416ca5bec..e8c08f00d5 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/GlobTest.java @@ -159,81 +159,19 @@ public class GlobTest { assertGlobMatches("foo/bar/wiz/file/*" /* => nothing */); } - @Test - public void testSingleFileExclude() throws Exception { - assertGlobWithExcludeMatches("*", "food", "foo", "fool"); - } - - @Test - public void testExcludeAll() throws Exception { - assertGlobWithExcludeMatches("*", "*"); - } - - @Test - public void testExcludeAllButNoMatches() throws Exception { - assertGlobWithExcludeMatches("not-there", "*"); - } - - @Test - public void testSingleFileExcludeDoesntMatch() throws Exception { - assertGlobWithExcludeMatches("food", "foo", "food"); - } - - @Test - public void testSingleFileExcludeForDirectoryWithChildGlob() - throws Exception { - assertGlobWithExcludeMatches("foo/*", "foo", "foo/bar", "foo/barnacle"); - } - - @Test - public void testChildGlobWithChildExclude() - throws Exception { - assertGlobWithExcludeMatches("foo/*", "foo/*"); - assertGlobWithExcludeMatches("foo/bar", "foo/*"); - assertGlobWithExcludeMatches("foo/bar", "foo/bar"); - assertGlobWithExcludeMatches("foo/bar", "*/bar"); - assertGlobWithExcludeMatches("foo/bar", "*/*"); - assertGlobWithExcludeMatches("foo/bar/wiz", "*/*/*"); - assertGlobWithExcludeMatches("foo/bar/wiz", "foo/*/*"); - assertGlobWithExcludeMatches("foo/bar/wiz", "foo/bar/*"); - assertGlobWithExcludeMatches("foo/bar/wiz", "foo/bar/wiz"); - assertGlobWithExcludeMatches("foo/bar/wiz", "*/bar/wiz"); - assertGlobWithExcludeMatches("foo/bar/wiz", "*/*/wiz"); - assertGlobWithExcludeMatches("foo/bar/wiz", "foo/*/wiz"); - } - private void assertGlobMatches(String pattern, String... expecteds) throws Exception { - assertGlobWithExcludesMatches( - Collections.singleton(pattern), Collections.<String>emptyList(), - expecteds); + assertGlobMatches(Collections.singleton(pattern), expecteds); } private void assertGlobMatches(Collection<String> pattern, String... expecteds) throws Exception { - assertGlobWithExcludesMatches(pattern, Collections.<String>emptyList(), - expecteds); - } - - private void assertGlobWithExcludeMatches(String pattern, String exclude, - String... expecteds) - throws Exception { - assertGlobWithExcludesMatches( - Collections.singleton(pattern), Collections.singleton(exclude), - expecteds); - } - - private void assertGlobWithExcludesMatches(Collection<String> pattern, - Collection<String> excludes, - String... expecteds) - throws Exception { assertThat( - new UnixGlob.Builder(tmpPath) - .addPatterns(pattern) - .addExcludes(excludes) - .globInterruptible()) - .containsExactlyElementsIn(resolvePaths(expecteds)); + new UnixGlob.Builder(tmpPath) + .addPatterns(pattern) + .globInterruptible()) + .containsExactlyElementsIn(resolvePaths(expecteds)); } private Set<Path> resolvePaths(String... relativePaths) { @@ -312,12 +250,6 @@ public class GlobTest { } @Test - public void testMultiplePatternsWithExcludes() throws Exception { - assertGlobWithExcludesMatches(Lists.newArrayList("foo", "foo?"), - Lists.newArrayList("fool"), "foo", "food"); - } - - @Test public void testMatcherMethodRecursiveBelowDir() throws Exception { FileSystemUtils.createEmptyFile(tmpPath.getRelative("foo/file")); String pattern = "foo/**/*"; diff --git a/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java b/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java index acbc2adc1c..694a91d214 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/RecursiveGlobTest.java @@ -28,7 +28,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -83,7 +82,6 @@ public class RecursiveGlobTest { for (String pattern : Lists.newArrayList("**fo", "fo**", "**fo**", "fo**fo", "fo**fo**fo")) { assertIllegalWildcard(prefix + pattern); assertIllegalWildcard(pattern + suffix); - assertIllegalWildcard("foo", pattern + suffix); } } } @@ -122,66 +120,13 @@ public class RecursiveGlobTest { assertGlobMatches("foo/bar/wiz/file/**" /* => nothing */); } - @Test - public void testSingleFileExclude() throws Exception { - assertGlobWithExcludeMatches("**", "food", ".", "foo", "foo/bar", "foo/bar/wiz", "foo/baz", - "foo/baz/quip", "foo/baz/quip/wiz", "foo/baz/wiz", - "foo/bar/wiz/file", "food/baz", "food/baz/wiz", "fool", "fool/baz", - "fool/baz/wiz"); - } - - @Test - public void testSingleFileExcludeForDirectoryWithChildGlob() - throws Exception { - assertGlobWithExcludeMatches("foo/**", "foo", "foo/bar", "foo/bar/wiz", "foo/baz", - "foo/baz/quip", "foo/baz/quip/wiz", "foo/baz/wiz", - "foo/bar/wiz/file"); - } - - @Test - public void testGlobExcludeForDirectoryWithChildGlob() - throws Exception { - assertGlobWithExcludeMatches("foo/**", "foo/*", "foo", "foo/bar/wiz", "foo/baz/quip", - "foo/baz/quip/wiz", "foo/baz/wiz", "foo/bar/wiz/file"); - } - - @Test - public void testExcludeAll() throws Exception { - assertGlobWithExcludesMatches(Lists.newArrayList("**"), - Lists.newArrayList("*", "*/*", "*/*/*", "*/*/*/*"), "."); - } - - @Test - public void testManualGlobExcludeForDirectoryWithChildGlob() - throws Exception { - assertGlobWithExcludesMatches(Lists.newArrayList("foo/**"), - Lists.newArrayList("foo", "foo/*", "foo/*/*", "foo/*/*/*")); - } - private void assertGlobMatches(String pattern, String... expecteds) throws Exception { - assertGlobWithExcludesMatches( - Collections.singleton(pattern), Collections.<String>emptyList(), - expecteds); - } - - private void assertGlobWithExcludeMatches(String pattern, String exclude, - String... expecteds) - throws Exception { - assertGlobWithExcludesMatches( - Collections.singleton(pattern), Collections.singleton(exclude), - expecteds); - } - - private void assertGlobWithExcludesMatches(Collection<String> pattern, - Collection<String> excludes, - String... expecteds) throws Exception { assertThat( - new UnixGlob.Builder(tmpPath) - .addPatterns(pattern) - .addExcludes(excludes) - .globInterruptible()) - .containsExactlyElementsIn(resolvePaths(expecteds)); + new UnixGlob.Builder(tmpPath) + .addPatterns(pattern) + .globInterruptible()) + .containsExactlyElementsIn(resolvePaths(expecteds)); } private Set<Path> resolvePaths(String... relativePaths) { @@ -209,12 +154,11 @@ public class RecursiveGlobTest { .inOrder(); } - private void assertIllegalWildcard(String pattern, String... excludePatterns) + private void assertIllegalWildcard(String pattern) throws Exception { try { new UnixGlob.Builder(tmpPath) .addPattern(pattern) - .addExcludes(excludePatterns) .globInterruptible(); fail(); } catch (IllegalArgumentException e) { |