diff options
Diffstat (limited to 'src/test/java')
7 files changed, 88 insertions, 34 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java index ab2afc9e3c..088740b343 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictEx import com.google.devtools.build.lib.actions.util.ActionsTestUtil; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.cmdline.RepositoryName; +import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -192,6 +193,27 @@ public class ArtifactFactoryTest { } @Test + public void testAbsoluteArtifact() throws Exception { + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(execRoot)); + ArtifactRoot absoluteRoot = + ArtifactRoot.asSourceRoot(Root.absoluteRoot(scratch.getFileSystem())); + + assertThat(artifactFactory.getSourceArtifact(PathFragment.create("foo"), root).getExecPath()) + .isEqualTo(PathFragment.create("foo")); + assertThat( + artifactFactory + .getSourceArtifact(PathFragment.create("/foo"), absoluteRoot) + .getExecPath()) + .isEqualTo(PathFragment.create("/foo")); + MoreAsserts.expectThrows( + IllegalArgumentException.class, + () -> artifactFactory.getSourceArtifact(PathFragment.create("/foo"), root)); + MoreAsserts.expectThrows( + IllegalArgumentException.class, + () -> artifactFactory.getSourceArtifact(PathFragment.create("foo"), absoluteRoot)); + } + + @Test public void testSetGeneratingActionIdempotenceNewActionGraph() throws Exception { Artifact a = artifactFactory.getDerivedArtifact(fooRelative, outRoot, NULL_ARTIFACT_OWNER); Artifact b = artifactFactory.getDerivedArtifact(barRelative, outRoot, NULL_ARTIFACT_OWNER); diff --git a/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java b/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java index dd756cafc3..9a455b9846 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java +++ b/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java @@ -246,8 +246,8 @@ public final class ActionsTestUtil { public static final Artifact DUMMY_ARTIFACT = new Artifact( - PathFragment.create("dummy"), - ArtifactRoot.asSourceRoot(Root.fromFileSystemRoot(new InMemoryFileSystem()))); + PathFragment.create("/dummy"), + ArtifactRoot.asSourceRoot(Root.absoluteRoot(new InMemoryFileSystem()))); public static final ActionOwner NULL_ACTION_OWNER = ActionOwner.create( diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java index 18c5bb460d..1bd5bed2d3 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java @@ -163,7 +163,7 @@ public abstract class ResourceTestBase { public void setup() { errorConsumer = new FakeRuleErrorConsumer(); fileSystem = new InMemoryFileSystem(); - root = ArtifactRoot.asSourceRoot(Root.fromFileSystemRoot(fileSystem)); + root = ArtifactRoot.asSourceRoot(Root.fromPath(fileSystem.getPath("/"))); } @After diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java index d0e33b537b..c472b26896 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java @@ -186,7 +186,7 @@ public class FileFunctionTest { } private FileValue valueForPathOutsidePkgRoot(Path path) throws InterruptedException { - return valueForPathHelper(Root.fromFileSystemRoot(fs), path); + return valueForPathHelper(Root.absoluteRoot(fs), path); } private FileValue valueForPathHelper(Root root, Path path) throws InterruptedException { @@ -315,8 +315,8 @@ public class FileFunctionTest { .containsExactly( rootedPath("a"), rootedPath(""), - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.EMPTY_FRAGMENT), - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("outside"))); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/")), + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/outside"))); } @Test @@ -332,8 +332,8 @@ public class FileFunctionTest { .containsExactly( rootedPath("a"), rootedPath(""), - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.EMPTY_FRAGMENT), - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("absolute"))); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/")), + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/absolute"))); } @Test @@ -347,17 +347,17 @@ public class FileFunctionTest { seenFiles.addAll(getFilesSeenAndAssertValueChangesIfContentsOfFileChanges("b", false, "a")); seenFiles.addAll( getFilesSeenAndAssertValueChangesIfContentsOfFileChanges(externalPath, true, "a")); - Root root = Root.fromFileSystemRoot(fs); + Root root = Root.absoluteRoot(fs); assertThat(seenFiles) .containsExactly( rootedPath("WORKSPACE"), rootedPath("a"), rootedPath(""), - RootedPath.toRootedPath(root, PathFragment.EMPTY_FRAGMENT), - RootedPath.toRootedPath(root, PathFragment.create("output_base")), - RootedPath.toRootedPath(root, PathFragment.create("output_base/external")), - RootedPath.toRootedPath(root, PathFragment.create("output_base/external/a")), - RootedPath.toRootedPath(root, PathFragment.create("output_base/external/a/b"))); + RootedPath.toRootedPath(root, PathFragment.create("/")), + RootedPath.toRootedPath(root, PathFragment.create("/output_base")), + RootedPath.toRootedPath(root, PathFragment.create("/output_base/external")), + RootedPath.toRootedPath(root, PathFragment.create("/output_base/external/a")), + RootedPath.toRootedPath(root, PathFragment.create("/output_base/external/a/b"))); } @Test @@ -1111,7 +1111,7 @@ public class FileFunctionTest { // InMemoryFS is not supported for serialization. FileSystem fs = FileSystems.getJavaIoFileSystem(); Path.setFileSystemForSerialization(fs); - pkgRoot = Root.fromFileSystemRoot(fs); + pkgRoot = Root.absoluteRoot(fs); FileValue a = valueForPath(fs.getPath("/")); @@ -1654,7 +1654,7 @@ public class FileFunctionTest { return RootedPath.toRootedPath(root, path); } } - return RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), path); + return RootedPath.toRootedPath(Root.absoluteRoot(fs), path); } private SkyKey skyKey(String pathString) { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java index 851b7a8351..8b421f65f0 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java @@ -160,7 +160,7 @@ public class FilesystemValueCheckerTest { SkyKey skyKey = FileStateValue.key( - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo"))); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo"))); EvaluationResult<SkyValue> result = driver.evaluate( ImmutableList.of(skyKey), @@ -211,14 +211,13 @@ public class FilesystemValueCheckerTest { FileSystemUtils.ensureSymbolicLink(sym1, path); FileSystemUtils.ensureSymbolicLink(sym2, path); SkyKey fooKey = - FileValue.key( - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo"))); + FileValue.key(RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo"))); RootedPath symlinkRootedPath = - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("bar")); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/bar")); SkyKey symlinkKey = FileValue.key(symlinkRootedPath); SkyKey symlinkFileStateKey = FileStateValue.key(symlinkRootedPath); RootedPath sym1RootedPath = - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("sym1")); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/sym1")); SkyKey sym1FileStateKey = FileStateValue.key(sym1RootedPath); Iterable<SkyKey> allKeys = ImmutableList.of(symlinkKey, fooKey); @@ -280,10 +279,10 @@ public class FilesystemValueCheckerTest { SkyKey key1 = FileStateValue.key( - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo1"))); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo1"))); SkyKey key2 = FileStateValue.key( - RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo2"))); + RootedPath.toRootedPath(Root.absoluteRoot(fs), PathFragment.create("/foo2"))); Iterable<SkyKey> skyKeys = ImmutableList.of(key1, key2); EvaluationResult<SkyValue> result = driver.evaluate( diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java index e9605e328a..c3daa37846 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java @@ -33,7 +33,8 @@ public class GlobDescriptorTest { @Test public void testSerialization() throws Exception { ObjectCodecTester.newBuilder( - GlobDescriptor.getCodec(Root.getCodec(new PathCodec(FsUtils.TEST_FILESYSTEM)))) + GlobDescriptor.getCodec( + Root.getCodec(FsUtils.TEST_FILESYSTEM, new PathCodec(FsUtils.TEST_FILESYSTEM)))) .addSubjects( GlobDescriptor.create( PackageIdentifier.create("@foo", PathFragment.create("//bar")), diff --git a/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java b/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java index c007f4b35d..974d68e36a 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java @@ -15,11 +15,15 @@ package com.google.devtools.build.lib.vfs; import static com.google.common.truth.Truth.assertThat; +import com.google.common.collect.Lists; import com.google.common.testing.EqualsTester; import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; import com.google.devtools.build.lib.skyframe.serialization.testutils.ObjectCodecTester; +import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; +import java.util.Comparator; +import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,8 +41,10 @@ public class RootTest { @Test public void testEqualsAndHashCodeContract() throws Exception { + FileSystem otherFs = new InMemoryFileSystem(BlazeClock.instance()); new EqualsTester() - .addEqualityGroup(Root.fromFileSystemRoot(fs), Root.fromFileSystemRoot(fs)) + .addEqualityGroup(Root.absoluteRoot(fs), Root.absoluteRoot(fs)) + .addEqualityGroup(Root.absoluteRoot(otherFs), Root.absoluteRoot(otherFs)) .addEqualityGroup(Root.fromPath(fs.getPath("/foo")), Root.fromPath(fs.getPath("/foo"))) .testEquals(); } @@ -49,27 +55,53 @@ public class RootTest { assertThat(root.asPath()).isEqualTo(fs.getPath("/foo")); assertThat(root.contains(fs.getPath("/foo/bar"))).isTrue(); assertThat(root.contains(fs.getPath("/boo/bar"))).isFalse(); + assertThat(root.contains(PathFragment.create("/foo/bar"))).isTrue(); + assertThat(root.contains(PathFragment.create("foo/bar"))).isFalse(); assertThat(root.getRelative(PathFragment.create("bar"))).isEqualTo(fs.getPath("/foo/bar")); assertThat(root.getRelative("bar")).isEqualTo(fs.getPath("/foo/bar")); + assertThat(root.getRelative(PathFragment.create("/bar"))).isEqualTo(fs.getPath("/bar")); assertThat(root.relativize(fs.getPath("/foo/bar"))).isEqualTo(PathFragment.create("bar")); + assertThat(root.relativize(PathFragment.create("/foo/bar"))) + .isEqualTo(PathFragment.create("bar")); + MoreAsserts.expectThrows( + IllegalArgumentException.class, () -> root.relativize(PathFragment.create("foo"))); } @Test - public void testFileSystemRootPath() throws Exception { - Root root = Root.fromFileSystemRoot(fs); - assertThat(root.asPath()).isEqualTo(fs.getPath("/")); + public void testFileSystemAbsoluteRoot() throws Exception { + Root root = Root.absoluteRoot(fs); + assertThat(root.asPath()).isNull(); assertThat(root.contains(fs.getPath("/foo"))).isTrue(); - assertThat(root.getRelative(PathFragment.create("foo"))).isEqualTo(fs.getPath("/foo")); - assertThat(root.getRelative("foo")).isEqualTo(fs.getPath("/foo")); - assertThat(root.relativize(fs.getPath("/foo"))).isEqualTo(PathFragment.create("foo")); + assertThat(root.contains(PathFragment.create("/foo/bar"))).isTrue(); + assertThat(root.contains(PathFragment.create("foo/bar"))).isFalse(); + assertThat(root.getRelative("/foo")).isEqualTo(fs.getPath("/foo")); + assertThat(root.relativize(fs.getPath("/foo"))).isEqualTo(PathFragment.create("/foo")); + assertThat(root.relativize(PathFragment.create("/foo"))).isEqualTo(PathFragment.create("/foo")); + + MoreAsserts.expectThrows( + IllegalArgumentException.class, () -> root.getRelative(PathFragment.create("foo"))); + MoreAsserts.expectThrows( + IllegalArgumentException.class, () -> root.getRelative(PathFragment.create("foo"))); + MoreAsserts.expectThrows( + IllegalArgumentException.class, () -> root.relativize(PathFragment.create("foo"))); + } + + @Test + public void testCompareTo() throws Exception { + Root a = Root.fromPath(fs.getPath("/a")); + Root b = Root.fromPath(fs.getPath("/b")); + Root root = Root.absoluteRoot(fs); + List<Root> list = Lists.newArrayList(a, root, b); + list.sort(Comparator.naturalOrder()); + assertThat(list).containsExactly(root, a, b).inOrder(); } @Test public void testSerialization() throws Exception { - ObjectCodec<Root> codec = Root.getCodec(new PathCodec(fs)); + ObjectCodec<Root> codec = Root.getCodec(fs, new PathCodec(fs)); ObjectCodecTester.newBuilder(codec) - .verificationFunction((a, b) -> a.equals(b)) - .addSubjects(Root.fromFileSystemRoot(fs), Root.fromPath(fs.getPath("/foo"))) + .addSubjects(Root.absoluteRoot(fs), Root.fromPath(fs.getPath("/foo"))) + .skipBadDataTest() .buildAndRunTests(); } } |