Ejemplo n.º 1
0
  @Test
  public void testGlobsUpToDate() throws Exception {
    assertTrue(cache.globsUpToDate());

    // Initialize the cache
    cache.getGlob("*.txt");
    assertTrue(cache.globsUpToDate());

    cache.getGlob("*.js");
    assertTrue(cache.globsUpToDate());

    // Change the filesystem
    scratch.file("isolated/third.txt", "# this is third.txt");
    assertFalse(cache.globsUpToDate());

    // Fool the cache to observe the method's behavior.
    cache.setGlobPaths(
        "*.txt",
        false,
        Futures.<List<Path>>immediateFuture(
            Lists.newArrayList(
                scratch.resolve("isolated/first.txt"),
                scratch.resolve("isolated/second.txt"),
                scratch.resolve("isolated/third.txt"))));
    assertTrue(cache.globsUpToDate());
  }
Ejemplo n.º 2
0
  @Test
  public void testGlob() throws Exception {
    assertEmpty(cache.glob(list("*.java"), NONE, false));

    assertThat(cache.glob(list("*.*"), NONE, false))
        .containsExactly("first.js", "first.txt", "second.js", "second.txt")
        .inOrder();

    assertThat(cache.glob(list("*.*"), list("first.js"), false))
        .containsExactly("first.txt", "second.js", "second.txt")
        .inOrder();

    assertThat(cache.glob(list("*.txt", "first.*"), NONE, false))
        .containsExactly("first.txt", "second.txt", "first.js")
        .inOrder();
  }
Ejemplo n.º 3
0
 @Test
 public void testSafeGlobInvalidPatterns() throws Exception {
   for (String pattern : new String[] {"Foo?.txt", "List{Test}.py", "List(Test).py"}) {
     try {
       cache.safeGlob(pattern, false);
       fail("Expected pattern " + pattern + " to fail");
     } catch (BadGlobException expected) {
     }
   }
 }
Ejemplo n.º 4
0
  @Test
  public void testSetGlobPaths() throws Exception {
    // This pattern matches no files.
    String pattern = "fake*.java";
    assertThat(cache.getKeySet()).doesNotContain(pattern);

    List<String> results = cache.getGlob(pattern, false);

    assertThat(cache.getKeySet()).contains(Pair.of(pattern, false));
    assertThat(results).isEmpty();

    cache.setGlobPaths(
        pattern,
        false,
        Futures.<List<Path>>immediateFuture(
            Lists.newArrayList(
                scratch.resolve("isolated/fake.txt"), scratch.resolve("isolated/fake.py"))));

    assertThat(cache.getGlob(pattern, false)).containsExactly("fake.py", "fake.txt");
  }
Ejemplo n.º 5
0
 @Test
 public void testRecursiveGlobDoesNotMatchSubpackage() throws Exception {
   List<String> glob = cache.getGlob("**/*.js");
   assertThat(glob)
       .containsExactly(
           "first.js",
           "second.js",
           "foo/first.js",
           "bar/first.js",
           "foo/second.js",
           "bar/second.js");
 }
Ejemplo n.º 6
0
  @Test
  public void testGetKeySet() throws Exception {
    assertThat(cache.getKeySet()).isEmpty();

    cache.getGlob("*.java");
    assertThat(cache.getKeySet()).containsExactly(Pair.of("*.java", false));

    cache.getGlob("*.java");
    assertThat(cache.getKeySet()).containsExactly(Pair.of("*.java", false));

    cache.getGlob("*.js");
    assertThat(cache.getKeySet()).containsExactly(Pair.of("*.java", false), Pair.of("*.js", false));

    cache.getGlob("*.java", true);
    assertThat(cache.getKeySet())
        .containsExactly(Pair.of("*.java", false), Pair.of("*.js", false), Pair.of("*.java", true));

    try {
      cache.getGlob("invalid?");
      fail("Expected an invalid regex exception");
    } catch (BadGlobException expected) {
    }
    assertThat(cache.getKeySet())
        .containsExactly(Pair.of("*.java", false), Pair.of("*.js", false), Pair.of("*.java", true));

    cache.getGlob("foo/first.*");
    assertThat(cache.getKeySet())
        .containsExactly(
            Pair.of("*.java", false),
            Pair.of("*.java", true),
            Pair.of("*.js", false),
            Pair.of("foo/first.*", false));
  }
Ejemplo n.º 7
0
 @Test
 public void testGetGlob_subdirectory() throws Exception {
   List<String> glob = cache.getGlob("foo/*.js");
   assertThat(glob).containsExactly("foo/first.js", "foo/second.js");
 }
Ejemplo n.º 8
0
 @Test
 public void testGetGlob() throws Exception {
   List<String> glob = cache.getGlob("*.js");
   assertThat(glob).containsExactly("first.js", "second.js");
 }
Ejemplo n.º 9
0
 @Test
 public void testSafeGlob() throws Exception {
   List<Path> paths = cache.safeGlob("*.js", false).get();
   assertPathsAre(paths, "/workspace/isolated/first.js", "/workspace/isolated/second.js");
 }