Search in sources :

Example 26 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class ParserTest method testValidAbsoluteImportPath.

@Test
public void testValidAbsoluteImportPath() throws SkylarkImportSyntaxException {
    String importString = "/some/skylark/file";
    List<Statement> statements = parseFileForSkylark("load('" + importString + "', 'fun_test')\n");
    LoadStatement stmt = (LoadStatement) statements.get(0);
    SkylarkImport imp = SkylarkImports.create(stmt.getImport().getValue());
    assertThat(imp.getImportString()).named("getImportString()").isEqualTo("/some/skylark/file");
    assertThat(imp.hasAbsolutePath()).named("hasAbsolutePath()").isTrue();
    assertThat(imp.getAbsolutePath()).named("getAbsolutePath()").isEqualTo(new PathFragment("/some/skylark/file.bzl"));
    int startOffset = stmt.getImport().getLocation().getStartOffset();
    int endOffset = stmt.getImport().getLocation().getEndOffset();
    assertThat(startOffset).named("getStartOffset()").isEqualTo(5);
    assertThat(endOffset).named("getEndOffset()").isEqualTo(startOffset + importString.length() + 2);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Test(org.junit.Test)

Example 27 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class SkylarkImportTest method testValidAbsolutePath.

@Test
public void testValidAbsolutePath() throws Exception {
    String pathToTest = "/some/skylark/file";
    SkylarkImport importForPath = SkylarkImports.create(pathToTest);
    assertThat(importForPath.hasAbsolutePath()).named("hasAbsolutePath()").isTrue();
    assertThat(importForPath.getImportString()).named("getImportString()").isEqualTo(pathToTest);
    Label irrelevantContainingFile = Label.parseAbsoluteUnchecked("//another/path:BUILD");
    assertThat(importForPath.getAbsolutePath()).named("getAbsolutePath()").isEqualTo(new PathFragment("//some/skylark/file.bzl"));
    assertThat(importForPath.asPathFragment()).named("asPathFragment()").isEqualTo(new PathFragment("/some/skylark/file.bzl"));
    thrown.expect(IllegalStateException.class);
    importForPath.getLabel(irrelevantContainingFile);
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Test(org.junit.Test)

Example 28 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class SkylarkImportTest method validRelativePathTest.

private void validRelativePathTest(String pathString, String containingLabelString, String expectedLabelString, String expectedPathString) throws Exception {
    SkylarkImport importForPath = SkylarkImports.create(pathString);
    assertThat(importForPath.hasAbsolutePath()).named("hasAbsolutePath()").isFalse();
    // The import label is relative to the parent's directory not the parent's package.
    Label containingLabel = Label.parseAbsolute(containingLabelString);
    assertThat(importForPath.getLabel(containingLabel)).named("getLabel()").isEqualTo(Label.parseAbsolute(expectedLabelString));
    assertThat(importForPath.asPathFragment()).named("asPathFragment()").isEqualTo(new PathFragment(expectedPathString));
    thrown.expect(IllegalStateException.class);
    importForPath.getAbsolutePath();
}
Also used : Label(com.google.devtools.build.lib.cmdline.Label) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 29 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class EnvironmentTest method testLocked.

@Test
public void testLocked() throws Exception {
    final Mutability mutability = Mutability.create("testLocked");
    class DummyFreezable implements Mutability.Freezable {

        @Override
        public Mutability mutability() {
            return mutability;
        }
    }
    DummyFreezable dummy = new DummyFreezable();
    Location locA = Location.fromPathFragment(new PathFragment("/a"));
    Location locB = Location.fromPathFragment(new PathFragment("/b"));
    Environment env = Environment.builder(mutability).build();
    // Acquire two locks, release two locks, check along the way.
    assertThat(mutability.isLocked(dummy)).isFalse();
    mutability.lock(dummy, locA);
    assertThat(mutability.isLocked(dummy)).isTrue();
    mutability.lock(dummy, locB);
    assertThat(mutability.isLocked(dummy)).isTrue();
    assertThat(mutability.getLockLocations(dummy)).containsExactly(locA, locB);
    mutability.unlock(dummy, locA);
    assertThat(mutability.isLocked(dummy)).isTrue();
    try {
        Mutability.checkMutable(dummy, env);
        fail("Able to mutate locked object");
    } catch (Mutability.MutabilityException e) {
        assertThat(e).hasMessage("trying to mutate a locked object (is it currently being iterated " + "over by a for loop or comprehension?)\n" + "Object locked at the following location(s): /b:1");
    }
    try {
        mutability.unlock(dummy, locA);
        fail("Able to unlock object with wrong location");
    } catch (AssertionError e) {
        assertThat(e).hasMessage("trying to unlock an object for a location at which " + "it was not locked (/a:1)");
    }
    mutability.unlock(dummy, locB);
    assertThat(mutability.isLocked(dummy)).isFalse();
    Mutability.checkMutable(dummy, env);
    // Acquire, then freeze.
    mutability.lock(dummy, locA);
    mutability.freeze();
    assertThat(mutability.isLocked(dummy)).isFalse();
    try {
        Mutability.checkMutable(dummy, env);
        fail("Able to mutate locked object");
    } catch (Mutability.MutabilityException e) {
        assertThat(e).hasMessage("trying to mutate a frozen object");
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Location(com.google.devtools.build.lib.events.Location) Test(org.junit.Test)

Example 30 with PathFragment

use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.

the class ParserInputSourceTest method testWillNotTryToReadInputFileIfContentProvidedAsChars.

@Test
public void testWillNotTryToReadInputFileIfContentProvidedAsChars() {
    char[] content = "Content provided as char array.".toCharArray();
    ParserInputSource.create(content, new PathFragment("/will/not/try/to/read"));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Test(org.junit.Test)

Aggregations

PathFragment (com.google.devtools.build.lib.vfs.PathFragment)512 Test (org.junit.Test)208 Artifact (com.google.devtools.build.lib.actions.Artifact)184 Path (com.google.devtools.build.lib.vfs.Path)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)65 SkyKey (com.google.devtools.build.skyframe.SkyKey)56 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)35 ImmutableList (com.google.common.collect.ImmutableList)32 Root (com.google.devtools.build.lib.actions.Root)32 HashMap (java.util.HashMap)27 Label (com.google.devtools.build.lib.cmdline.Label)26 LinkedHashMap (java.util.LinkedHashMap)26 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 Map (java.util.Map)21 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)20 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)16 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)16