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);
}
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);
}
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();
}
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");
}
}
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"));
}
Aggregations