aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-10-28 16:35:08 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-10-29 07:46:13 +0000
commit3b2eae3935c41cf940f3aeb177e25dc7fdcabeeb (patch)
tree9e168bd24798ed7474468de44f074c61b30e2e71 /src/test/java/com
parenteb71eccefb02ca17a87ff25435f2a8e170e03c6b (diff)
Use JUnit4 for some of the skyframe tests.
-- MOS_MIGRATED_REVID=106504113
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java30
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java21
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java77
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java8
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java35
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java58
7 files changed, 204 insertions, 35 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java
index 8c15b6c8d9..42934a0356 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionExecutionInactivityWatchdogTest.java
@@ -14,18 +14,22 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog.InactivityMonitor;
import com.google.devtools.build.lib.skyframe.ActionExecutionInactivityWatchdog.InactivityReporter;
import com.google.devtools.build.lib.testutil.MoreAsserts;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.util.ArrayList;
import java.util.List;
/** Tests for ActionExecutionInactivityWatchdog. */
-public final class ActionExecutionInactivityWatchdogTest extends TestCase {
+@RunWith(JUnit4.class)
+public class ActionExecutionInactivityWatchdogTest {
private void assertInactivityWatchdogReports(final boolean shouldReport) throws Exception {
// The monitor implementation below is a state machine. This variable indicates which state
@@ -157,10 +161,12 @@ public final class ActionExecutionInactivityWatchdogTest extends TestCase {
.inOrder();
}
+ @Test
public void testInactivityWatchdogReportsWhenItShould() throws Exception {
assertInactivityWatchdogReports(true);
}
+ @Test
public void testInactivityWatchdogDoesNotReportWhenItShouldNot() throws Exception {
assertInactivityWatchdogReports(false);
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index e9efdfd81a..7cb2076cd4 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -16,6 +16,11 @@ package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.skyframe.FileArtifactValue.create;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
@@ -51,7 +56,10 @@ import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.IOException;
import java.util.Arrays;
@@ -67,7 +75,8 @@ import java.util.concurrent.atomic.AtomicReference;
* Tests for {@link ArtifactFunction}.
*/
// Doesn't actually need any particular Skyframe, but is only relevant to Skyframe full mode.
-public class ArtifactFunctionTest extends TestCase {
+@RunWith(JUnit4.class)
+public class ArtifactFunctionTest {
private static final SkyKey OWNER_KEY = new SkyKey(SkyFunctions.ACTION_LOOKUP, "OWNER");
private static final ActionLookupKey ALL_OWNER = new SingletonActionLookupKey();
@@ -79,9 +88,9 @@ public class ArtifactFunctionTest extends TestCase {
private Path root;
private TimestampGranularityMonitor tsgm = new TimestampGranularityMonitor(BlazeClock.instance());
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
setupRoot(new CustomInMemoryFs());
AtomicReference<PathPackageLocator> pkgLocator =
new AtomicReference<>(new PathPackageLocator());
@@ -111,21 +120,25 @@ public class ArtifactFunctionTest extends TestCase {
assertValueMatches(path.stat(), expectDigest ? path.getMD5Digest() : null, evaluateFAN(output));
}
+ @Test
public void testBasicArtifact() throws Throwable {
fastDigest = false;
assertFileArtifactValueMatches(/*expectDigest=*/ true);
}
+ @Test
public void testBasicArtifactWithXattr() throws Throwable {
fastDigest = true;
assertFileArtifactValueMatches(/*expectDigest=*/ true);
}
+ @Test
public void testMissingNonMandatoryArtifact() throws Throwable {
Artifact input = createSourceArtifact("input1");
assertNotNull(evaluateArtifactValue(input, /*mandatory=*/ false));
}
+ @Test
public void testMissingMandatoryArtifact() throws Throwable {
Artifact input = createSourceArtifact("input1");
try {
@@ -136,6 +149,7 @@ public class ArtifactFunctionTest extends TestCase {
}
}
+ @Test
public void testMiddlemanArtifact() throws Throwable {
Artifact output = createDerivedArtifact("output");
Artifact input1 = createSourceArtifact("input1");
@@ -161,6 +175,7 @@ public class ArtifactFunctionTest extends TestCase {
.containsExactly(Pair.of(input1, create(input1)), Pair.of(input2, create(input2)));
}
+ @Test
public void testIOException() throws Exception {
fastDigest = false;
final IOException exception = new IOException("beep");
@@ -185,6 +200,7 @@ public class ArtifactFunctionTest extends TestCase {
* Tests that ArtifactFunction rethrows transitive {@link IOException}s as
* {@link MissingInputFileException}s.
*/
+ @Test
public void testIOException_EndToEnd() throws Throwable {
final IOException exception = new IOException("beep");
setupRoot(
@@ -205,6 +221,7 @@ public class ArtifactFunctionTest extends TestCase {
}
}
+ @Test
public void testNoMtimeIfNonemptyFile() throws Exception {
Artifact artifact = createDerivedArtifact("no-digest");
Path path = artifact.getPath();
@@ -219,6 +236,7 @@ public class ArtifactFunctionTest extends TestCase {
}
}
+ @Test
public void testDirectory() throws Exception {
Artifact artifact = createDerivedArtifact("dir");
Path path = artifact.getPath();
@@ -231,6 +249,7 @@ public class ArtifactFunctionTest extends TestCase {
// Empty files need to store their mtimes, so touching an empty file
// can be used to trigger rebuilds.
+ @Test
public void testEmptyFile() throws Exception {
Artifact artifact = createDerivedArtifact("empty");
Path path = artifact.getPath();
@@ -242,6 +261,7 @@ public class ArtifactFunctionTest extends TestCase {
assertEquals(0L, value.getSize());
}
+ @Test
public void testEquality() throws Exception {
Artifact artifact1 = createDerivedArtifact("artifact1");
Artifact artifact2 = createDerivedArtifact("artifact2");
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java
index bd28c33fec..1ade3d4383 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java
@@ -14,6 +14,9 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
@@ -26,7 +29,10 @@ import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.util.List;
import java.util.Map;
@@ -37,21 +43,23 @@ import javax.annotation.Nullable;
* Unit tests for {@link DiffAwarenessManager}, especially of the fact that it works in a sequential
* manner and of its correctness in the presence of unprocesed diffs.
*/
-public class DiffAwarenessManagerTest extends TestCase {
+@RunWith(JUnit4.class)
+public class DiffAwarenessManagerTest {
private FileSystem fs;
private Path root;
protected EventCollectionApparatus events;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
fs = new InMemoryFileSystem();
root = fs.getRootDirectory();
events = new EventCollectionApparatus();
events.setFailFast(false);
}
+ @Test
public void testEverythingModifiedIfNoDiffAwareness() throws Exception {
Path pathEntry = root.getRelative("pathEntry");
DiffAwarenessFactoryStub factory = new DiffAwarenessFactoryStub();
@@ -63,6 +71,7 @@ public class DiffAwarenessManagerTest extends TestCase {
events.assertNoWarningsOrErrors();
}
+ @Test
public void testResetAndSetPathEntriesCallClose() throws Exception {
Path pathEntry = root.getRelative("pathEntry");
ModifiedFileSet diff = ModifiedFileSet.NOTHING_MODIFIED;
@@ -81,6 +90,7 @@ public class DiffAwarenessManagerTest extends TestCase {
events.assertNoWarningsOrErrors();
}
+ @Test
public void testHandlesUnprocessedDiffs() throws Exception {
Path pathEntry = root.getRelative("pathEntry");
ModifiedFileSet diff1 = ModifiedFileSet.builder().modify(new PathFragment("file1")).build();
@@ -110,6 +120,7 @@ public class DiffAwarenessManagerTest extends TestCase {
events.assertContainsWarning("error");
}
+ @Test
public void testHandlesBrokenDiffs() throws Exception {
Path pathEntry = root.getRelative("pathEntry");
DiffAwarenessFactoryStub factory1 = new DiffAwarenessFactoryStub();
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 8899d79d4d..abeea7687e 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
@@ -16,6 +16,13 @@ package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.skyframe.SkyframeExecutor.DEFAULT_THREAD_COUNT;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
@@ -54,7 +61,10 @@ import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -74,7 +84,8 @@ import javax.annotation.Nullable;
/**
* Tests for {@link FileFunction}.
*/
-public class FileFunctionTest extends TestCase {
+@RunWith(JUnit4.class)
+public class FileFunctionTest {
private CustomInMemoryFs fs;
private Path pkgRoot;
private PathPackageLocator pkgLocator;
@@ -83,9 +94,9 @@ public class FileFunctionTest extends TestCase {
private ManualClock manualClock;
private RecordingDifferencer differencer;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
fastMd5 = true;
manualClock = new ManualClock();
createFsAndRoot(new CustomInMemoryFs(manualClock));
@@ -142,6 +153,7 @@ public class FileFunctionTest extends TestCase {
return result.get(key);
}
+ @Test
public void testFileValueHashCodeAndEqualsContract() throws Exception {
Path pathA = file(pkgRoot + "a", "a");
Path pathB = file(pkgRoot + "b", "b");
@@ -155,6 +167,7 @@ public class FileFunctionTest extends TestCase {
.testEquals();
}
+ @Test
public void testIsDirectory() throws Exception {
assertFalse(valueForPath(file("a")).isDirectory());
assertFalse(valueForPath(path("nonexistent")).isDirectory());
@@ -166,6 +179,7 @@ public class FileFunctionTest extends TestCase {
assertTrue(valueForPath(symlink("ssdir", "sdir")).isDirectory());
}
+ @Test
public void testIsFile() throws Exception {
assertTrue(valueForPath(file("a")).isFile());
assertFalse(valueForPath(path("nonexistent")).isFile());
@@ -177,6 +191,7 @@ public class FileFunctionTest extends TestCase {
assertTrue(valueForPath(symlink("ssfile", "sa")).isFile());
}
+ @Test
public void testSimpleIndependentFiles() throws Exception {
file("a");
file("b");
@@ -187,6 +202,7 @@ public class FileFunctionTest extends TestCase {
assertThat(seenFiles).containsExactly(rootedPath("a"), rootedPath("b"), rootedPath(""));
}
+ @Test
public void testSimpleSymlink() throws Exception {
symlink("a", "b");
file("b");
@@ -195,6 +211,7 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("b", true, "a");
}
+ @Test
public void testTransitiveSymlink() throws Exception {
symlink("a", "b");
symlink("b", "c");
@@ -207,12 +224,14 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("c", true, "a");
}
+ @Test
public void testFileUnderDirectorySymlink() throws Exception {
symlink("a", "b/c");
symlink("b", "d");
assertValueChangesIfContentsOfDirectoryChanges("b", true, "a/e");
}
+ @Test
public void testSymlinkInDirectory() throws Exception {
symlink("a/aa", "ab");
file("a/ab");
@@ -221,18 +240,21 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("a/ab", true, "a/aa");
}
+ @Test
public void testRelativeSymlink() throws Exception {
symlink("a/aa/aaa", "../ab/aba");
file("a/ab/aba");
assertValueChangesIfContentsOfFileChanges("a/ab/aba", true, "a/aa/aaa");
}
+ @Test
public void testDoubleRelativeSymlink() throws Exception {
symlink("a/b/c/d", "../../e/f");
file("a/e/f");
assertValueChangesIfContentsOfFileChanges("a/e/f", true, "a/b/c/d");
}
+ @Test
public void testExternalRelativeSymlink() throws Exception {
symlink("a", "../outside");
file("b");
@@ -249,6 +271,7 @@ public class FileFunctionTest extends TestCase {
RootedPath.toRootedPath(fs.getRootDirectory(), new PathFragment("outside")));
}
+ @Test
public void testAbsoluteSymlink() throws Exception {
symlink("a", "/absolute");
file("b");
@@ -265,18 +288,21 @@ public class FileFunctionTest extends TestCase {
RootedPath.toRootedPath(fs.getRootDirectory(), new PathFragment("absolute")));
}
+ @Test
public void testSymlinkAsAncestor() throws Exception {
file("a/b/c/d");
symlink("f", "a/b/c");
assertValueChangesIfContentsOfFileChanges("a/b/c/d", true, "f/d");
}
+ @Test
public void testSymlinkAsAncestorNested() throws Exception {
file("a/b/c/d");
symlink("f", "a/b");
assertValueChangesIfContentsOfFileChanges("a/b/c/d", true, "f/c/d");
}
+ @Test
public void testTwoSymlinksInAncestors() throws Exception {
file("a/aa/aaa/aaaa");
symlink("b/ba/baa", "../../a/aa");
@@ -287,22 +313,26 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("a/aa/aaa/aaaa", true, "c/ca/baa/aaa/aaaa");
}
+ @Test
public void testSelfReferencingSymlink() throws Exception {
symlink("a", "a");
assertError("a");
}
+ @Test
public void testMutuallyReferencingSymlinks() throws Exception {
symlink("a", "b");
symlink("b", "a");
assertError("a");
}
+ @Test
public void testRecursiveNestingSymlink() throws Exception {
symlink("a/a", "../a");
assertError("a/a/b");
}
+ @Test
public void testBrokenSymlink() throws Exception {
symlink("a", "b");
Set<RootedPath> seenFiles = Sets.newHashSet();
@@ -311,6 +341,7 @@ public class FileFunctionTest extends TestCase {
assertThat(seenFiles).containsExactly(rootedPath("a"), rootedPath("b"), rootedPath(""));
}
+ @Test
public void testBrokenDirectorySymlink() throws Exception {
symlink("a", "b");
file("c");
@@ -322,6 +353,7 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("c", false, "a/aa");
}
+ @Test
public void testTraverseIntoVirtualNonDirectory() throws Exception {
file("dir/a");
symlink("vdir", "dir");
@@ -329,6 +361,7 @@ public class FileFunctionTest extends TestCase {
assertNoError("vdir/a/aa/aaa");
}
+ @Test
public void testFileCreation() throws Exception {
FileValue a = valueForPath(path("file"));
Path p = file("file");
@@ -336,6 +369,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(a.equals(b));
}
+ @Test
public void testEmptyFile() throws Exception {
final byte[] digest = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
createFsAndRoot(
@@ -362,6 +396,7 @@ public class FileFunctionTest extends TestCase {
assertThat(valueForPath(p)).isNotEqualTo(a);
}
+ @Test
public void testFileModificationModTime() throws Exception {
fastMd5 = false;
Path p = file("file");
@@ -371,6 +406,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(a.equals(b));
}
+ @Test
public void testFileModificationDigest() throws Exception {
fastMd5 = true;
Path p = file("file");
@@ -380,6 +416,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(a.equals(b));
}
+ @Test
public void testModTimeVsDigest() throws Exception {
Path p = file("somefile", "fizzley");
@@ -391,6 +428,7 @@ public class FileFunctionTest extends TestCase {
new EqualsTester().addEqualityGroup(aMd5).addEqualityGroup(aModTime).testEquals();
}
+ @Test
public void testFileDeletion() throws Exception {
Path p = file("file");
FileValue a = valueForPath(p);
@@ -399,6 +437,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(a.equals(b));
}
+ @Test
public void testFileTypeChange() throws Exception {
Path p = file("file");
FileValue a = valueForPath(p);
@@ -413,6 +452,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(a.equals(c));
}
+ @Test
public void testSymlinkTargetChange() throws Exception {
Path p = symlink("symlink", "foo");
FileValue a = valueForPath(p);
@@ -422,6 +462,7 @@ public class FileFunctionTest extends TestCase {
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testSymlinkTargetContentsChangeModTime() throws Exception {
fastMd5 = false;
Path fooPath = file("foo");
@@ -433,6 +474,7 @@ public class FileFunctionTest extends TestCase {
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testSymlinkTargetContentsChangeDigest() throws Exception {
fastMd5 = true;
Path fooPath = file("foo");
@@ -444,6 +486,7 @@ public class FileFunctionTest extends TestCase {
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testRealPath() throws Exception {
file("file");
directory("directory");
@@ -474,6 +517,7 @@ public class FileFunctionTest extends TestCase {
assertRealPath("deadlink", "missing_file");
}
+ @Test
public void testRealPathRelativeSymlink() throws Exception {
directory("dir");
symlink("dir/link", "../dir2");
@@ -484,6 +528,7 @@ public class FileFunctionTest extends TestCase {
checkRealPath("dir/link/filelink");
}
+ @Test
public void testSymlinkAcrossPackageRoots() throws Exception {
Path otherPkgRoot = fs.getRootDirectory().getRelative("other_root");
pkgLocator = new PathPackageLocator(pkgRoot, otherPkgRoot);
@@ -491,6 +536,7 @@ public class FileFunctionTest extends TestCase {
assertValueChangesIfContentsOfFileChanges("/other_root/b", true, "a");
}
+ @Test
public void testFilesOutsideRootHasDepOnBuildID() throws Exception {
Path file = file("/outsideroot");
SequentialBuildDriver driver = makeDriver();
@@ -527,6 +573,7 @@ public class FileFunctionTest extends TestCase {
assertFalse(newValue.exists());
}
+ @Test
public void testFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("/outsideroot");
@@ -541,6 +588,7 @@ public class FileFunctionTest extends TestCase {
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testAbsoluteSymlinksToFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("/outsideroot");
symlink("a", "/outsideroot");
@@ -556,6 +604,7 @@ public class FileFunctionTest extends TestCase {
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testRelativeSymlinksToFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("../outsideroot");
symlink("a", "../outsideroot");
@@ -569,6 +618,7 @@ public class FileFunctionTest extends TestCase {
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testAbsoluteSymlinksBackIntoSourcesOkWhenExternalDisallowed() throws Exception {
Path file = file("insideroot");
symlink("a", file.getPathString());
@@ -594,6 +644,7 @@ public class FileFunctionTest extends TestCase {
SkyKey.NODE_NAME));
}
+ @Test
public void testSize() throws Exception {
Path file = file("file");
int fileSize = 20;
@@ -635,6 +686,7 @@ public class FileFunctionTest extends TestCase {
}
}
+ @Test
public void testDigest() throws Exception {
final AtomicInteger digestCalls = new AtomicInteger(0);
int expectedCalls = 0;
@@ -701,6 +753,7 @@ public class FileFunctionTest extends TestCase {
assertEquals(0, digestCalls.get());
}
+ @Test
public void testFilesystemInconsistencies_ParentDoesntExistAndChildIsSymlink() throws Exception {
symlink("a/b", "doesntmatter");
// Our custom filesystem says "a/b" exists but "a" does not exist.
@@ -719,6 +772,7 @@ public class FileFunctionTest extends TestCase {
+ "nonexistent path");
}
+ @Test
public void testFilesystemInconsistencies_ParentIsntADirectory() throws Exception {
file("a/b");
// Our custom filesystem says "a/b" exists but its parent "a" is a file.
@@ -780,6 +834,7 @@ public class FileFunctionTest extends TestCase {
.contains("file /root/a/b exists but its parent path /root/a isn't an existing directory");
}
+ @Test
public void testFilesystemInconsistencies_GetFastDigest() throws Exception {
file("a");
// Our custom filesystem says "a/b" exists but "a" does not exist.
@@ -874,22 +929,27 @@ public class FileFunctionTest extends TestCase {
.contains("circular symlinks detected");
}
+ @Test
public void testSymlinkCycle_AncestorCycle_StartInCycle() throws Exception {
runTestSymlinkCycle(/*ancestorCycle=*/ true, /*startInCycle=*/ true);
}
+ @Test
public void testSymlinkCycle_AncestorCycle_StartOutOfCycle() throws Exception {
runTestSymlinkCycle(/*ancestorCycle=*/ true, /*startInCycle=*/ false);
}
+ @Test
public void testSymlinkCycle_RegularCycle_StartInCycle() throws Exception {
runTestSymlinkCycle(/*ancestorCycle=*/ false, /*startInCycle=*/ true);
}
+ @Test
public void testSymlinkCycle_RegularCycle_StartOutOfCycle() throws Exception {
runTestSymlinkCycle(/*ancestorCycle=*/ false, /*startInCycle=*/ false);
}
+ @Test
public void testSerialization() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
@@ -929,6 +989,7 @@ public class FileFunctionTest extends TestCase {
}
}
+ @Test
public void testFileStateEquality() throws Exception {
file("a");
symlink("b1", "a");
@@ -961,6 +1022,7 @@ public class FileFunctionTest extends TestCase {
.testEquals();
}
+ @Test
public void testSymlinkToPackagePathBoundary() throws Exception {
Path path = path("this/is/a/path");
FileSystemUtils.ensureSymbolicLink(path, pkgRoot);
@@ -1034,22 +1096,27 @@ public class FileFunctionTest extends TestCase {
.contains("infinite symlink expansion detected");
}
+ @Test
public void testInfiniteSymlinkExpansion_AbsoluteSymlinkToDescendant() throws Exception {
runTestInfiniteSymlinkExpansion(/*ancestor=*/ false, /*absoluteSymlink=*/ true);
}
+ @Test
public void testInfiniteSymlinkExpansion_RelativeSymlinkToDescendant() throws Exception {
runTestInfiniteSymlinkExpansion(/*ancestor=*/ false, /*absoluteSymlink=*/ false);
}
+ @Test
public void testInfiniteSymlinkExpansion_AbsoluteSymlinkToAncestor() throws Exception {
runTestInfiniteSymlinkExpansion(/*ancestor=*/ true, /*absoluteSymlink=*/ true);
}
+ @Test
public void testInfiniteSymlinkExpansion_RelativeSymlinkToAncestor() throws Exception {
runTestInfiniteSymlinkExpansion(/*ancestor=*/ true, /*absoluteSymlink=*/ false);
}
+ @Test
public void testChildOfNonexistentParent() throws Exception {
Path ancestor = directory("this/is/an/ancestor");
Path parent = ancestor.getChild("parent");
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java
index edfc2c54de..49414a95ea 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java
@@ -20,10 +20,14 @@ import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-public class FileSymlinkCycleUniquenessFunctionTest extends TestCase {
+@RunWith(JUnit4.class)
+public class FileSymlinkCycleUniquenessFunctionTest {
+ @Test
public void testHashCodeAndEqualsContract() throws Exception {
Path root = new InMemoryFileSystem().getRootDirectory().getRelative("root");
RootedPath p1 = RootedPath.toRootedPath(root, new PathFragment("p1"));
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 d917c8eef5..1f2a12d969 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
@@ -14,6 +14,10 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -50,7 +54,11 @@ import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.IOException;
import java.util.ArrayList;
@@ -67,7 +75,8 @@ import javax.annotation.Nullable;
/**
* Tests for {@link FilesystemValueChecker}.
*/
-public class FilesystemValueCheckerTest extends TestCase {
+@RunWith(JUnit4.class)
+public class FilesystemValueCheckerTest {
private RecordingDifferencer differencer;
private MemoizingEvaluator evaluator;
@@ -76,10 +85,8 @@ public class FilesystemValueCheckerTest extends TestCase {
private Path pkgRoot;
private TimestampGranularityMonitor tsgm;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
ImmutableMap.Builder<SkyFunctionName, SkyFunction> skyFunctions = ImmutableMap.builder();
fs = new MockFileSystem();
@@ -102,16 +109,13 @@ public class FilesystemValueCheckerTest extends TestCase {
PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
+ @Test
public void testEmpty() throws Exception {
FilesystemValueChecker checker = new FilesystemValueChecker(evaluator, tsgm, null);
assertEmptyDiff(getDirtyFilesystemKeys(checker));
}
+ @Test
public void testSimple() throws Exception {
FilesystemValueChecker checker = new FilesystemValueChecker(evaluator, tsgm, null);
@@ -155,6 +159,7 @@ public class FilesystemValueCheckerTest extends TestCase {
* the same. Then do a null build, change sym1 back to point at path, and change symlink to not be
* a symlink anymore. The fact that it is not a symlink should be detected.
*/
+ @Test
public void testDirtySymlink() throws Exception {
FilesystemValueChecker checker = new FilesystemValueChecker(evaluator, tsgm, null);
@@ -226,6 +231,7 @@ public class FilesystemValueCheckerTest extends TestCase {
assertEmptyDiff(getDirtyFilesystemKeys(checker));
}
+ @Test
public void testExplicitFiles() throws Exception {
FilesystemValueChecker checker = new FilesystemValueChecker(evaluator, tsgm, null);
@@ -263,6 +269,7 @@ public class FilesystemValueCheckerTest extends TestCase {
assertEmptyDiff(getDirtyFilesystemKeys(checker));
}
+ @Test
public void testFileWithIOExceptionNotConsideredDirty() throws Exception {
Path path = fs.getPath("/testroot/foo");
path.getParentDirectory().createDirectory();
@@ -285,6 +292,7 @@ public class FilesystemValueCheckerTest extends TestCase {
assertThat(diff.changedKeysWithNewValues()).isEmpty();
}
+ @Test
public void testFilesInCycleNotConsideredDirty() throws Exception {
Path path1 = pkgRoot.getRelative("foo1");
Path path2 = pkgRoot.getRelative("foo2");
@@ -346,10 +354,12 @@ public class FilesystemValueCheckerTest extends TestCase {
outputPath.getRelative(relPath), Root.asDerivedRoot(fs.getPath("/"), outputPath));
}
+ @Test
public void testDirtyActions() throws Exception {
checkDirtyActions(null, false);
}
+ @Test
public void testDirtyActionsBatchStat() throws Exception {
checkDirtyActions(
new BatchStat() {
@@ -369,6 +379,7 @@ public class FilesystemValueCheckerTest extends TestCase {
false);
}
+ @Test
public void testDirtyActionsBatchStatWithDigest() throws Exception {
checkDirtyActions(
new BatchStat() {
@@ -387,6 +398,7 @@ public class FilesystemValueCheckerTest extends TestCase {
true);
}
+ @Test
public void testDirtyActionsBatchStatFallback() throws Exception {
checkDirtyActions(
new BatchStat() {
@@ -415,6 +427,7 @@ public class FilesystemValueCheckerTest extends TestCase {
return new ActionExecutionValue(artifactData, ImmutableMap.<Artifact, FileArtifactValue>of());
}
+ @Test
public void testPropagatesRuntimeExceptions() throws Exception {
Collection<SkyKey> values =
ImmutableList.of(FileValue.key(RootedPath.toRootedPath(pkgRoot, new PathFragment("foo"))));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
index d70b98ae9e..2c2b77acaa 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java
@@ -14,6 +14,9 @@
package com.google.devtools.build.lib.skyframe;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableList;
@@ -50,7 +53,10 @@ import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import java.io.IOException;
import java.util.HashMap;
@@ -63,7 +69,8 @@ import javax.annotation.Nullable;
/**
* Tests for {@link GlobFunction}.
*/
-public abstract class GlobFunctionTest extends TestCase {
+public abstract class GlobFunctionTest {
+ @RunWith(JUnit4.class)
public static class GlobFunctionAlwaysUseDirListingTest extends GlobFunctionTest {
@Override
protected boolean alwaysUseDirListing() {
@@ -71,6 +78,7 @@ public abstract class GlobFunctionTest extends TestCase {
}
}
+ @RunWith(JUnit4.class)
public static class RegularGlobFunctionTest extends GlobFunctionTest {
@Override
protected boolean alwaysUseDirListing() {
@@ -89,9 +97,9 @@ public abstract class GlobFunctionTest extends TestCase {
private static final PackageIdentifier PKG_PATH_ID = PackageIdentifier.createInDefaultRepo("pkg");
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
fs = new CustomInMemoryFs(new ManualClock());
root = fs.getRootDirectory().getRelative("root/workspace");
pkgPath = root.getRelative(PKG_PATH_ID.getPackageFragment());
@@ -147,78 +155,96 @@ public abstract class GlobFunctionTest extends TestCase {
FileSystemUtils.createEmptyFile(pkgPath.getRelative("a2/b2/BUILD"));
}
+ @Test
public void testSimple() throws Exception {
assertGlobMatches("food", /* => */ "food");
}
+ @Test
public void testStartsWithStar() throws Exception {
assertGlobMatches("*oo", /* => */ "foo");
}
+ @Test
public void testStartsWithStarWithMiddleStar() throws Exception {
assertGlobMatches("*f*o", /* => */ "foo");
}
+ @Test
public void testSingleMatchEqual() throws Exception {
assertGlobsEqual("*oo", "*f*o"); // both produce "foo"
}
+ @Test
public void testEndsWithStar() throws Exception {
assertGlobMatches("foo*", /* => */ "foo", "food", "fool");
}
+ @Test
public void testEndsWithStarWithMiddleStar() throws Exception {
assertGlobMatches("f*oo*", /* => */ "foo", "food", "fool");
}
+ @Test
public void testMultipleMatchesEqual() throws Exception {
assertGlobsEqual("foo*", "f*oo*"); // both produce "foo", "food", "fool"
}
+ @Test
public void testMiddleStar() throws Exception {
assertGlobMatches("f*o", /* => */ "foo");
}
+ @Test
public void testTwoMiddleStars() throws Exception {
assertGlobMatches("f*o*o", /* => */ "foo");
}
+ @Test
public void testSingleStarPatternWithNamedChild() throws Exception {
assertGlobMatches("*/bar", /* => */ "foo/bar");
}
+ @Test
public void testDeepSubpackages() throws Exception {
assertGlobMatches("*/*/c", /* => */ "a1/b1/c");
}
+ @Test
public void testSingleStarPatternWithChildGlob() throws Exception {
assertGlobMatches(
"*/bar*", /* => */ "foo/bar", "foo/barnacle", "food/barnacle", "fool/barnacle");
}
+ @Test
public void testSingleStarAsChildGlob() throws Exception {
assertGlobMatches("foo/*/wiz", /* => */ "foo/bar/wiz", "foo/barnacle/wiz");
}
+ @Test
public void testNoAsteriskAndFilesDontExist() throws Exception {
// Note un-UNIX like semantics:
assertGlobMatches("ceci/n'est/pas/une/globbe" /* => nothing */);
}
+ @Test
public void testSingleAsteriskUnderNonexistentDirectory() throws Exception {
// Note un-UNIX like semantics:
assertGlobMatches("not-there/*" /* => nothing */);
}
+ @Test
public void testDifferentGlobsSameResultEqual() throws Exception {
// Once the globs are run, it doesn't matter what pattern ran; only the output.
assertGlobsEqual("not-there/*", "syzygy/*"); // Both produce nothing.
}
+ @Test
public void testGlobUnderFile() throws Exception {
assertGlobMatches("foo/bar/wiz/file/*" /* => nothing */);
}
+ @Test
public void testGlobEqualsHashCode() throws Exception {
// Each "equality group" forms a set of elements that are all equals() to one another,
// and also produce the same hashCode.
@@ -232,6 +258,7 @@ public abstract class GlobFunctionTest extends TestCase {
.testEquals();
}
+ @Test
public void testGlobMissingPackage() throws Exception {
// This is a malformed value key, because "missing" is not a package. Nevertheless, we have a
// sanity check that building the corresponding GlobValue fails loudly. The test depends on
@@ -258,18 +285,21 @@ public abstract class GlobFunctionTest extends TestCase {
}
}
+ @Test
public void testGlobDoesNotCrossPackageBoundary() throws Exception {
FileSystemUtils.createEmptyFile(pkgPath.getRelative("foo/BUILD"));
// "foo/bar" should not be in the results because foo is a separate package.
assertGlobMatches("f*/*", /* => */ "food/barnacle", "fool/barnacle");
}
+ @Test
public void testGlobDirectoryMatchDoesNotCrossPackageBoundary() throws Exception {
FileSystemUtils.createEmptyFile(pkgPath.getRelative("foo/bar/BUILD"));
// "foo/bar" should not be in the results because foo/bar is a separate package.
assertGlobMatches("foo/*", /* => */ "foo/barnacle");
}
+ @Test
public void testStarStarDoesNotCrossPackageBoundary() throws Exception {
FileSystemUtils.createEmptyFile(pkgPath.getRelative("foo/bar/BUILD"));
// "foo/bar" should not be in the results because foo/bar is a separate package.
@@ -326,6 +356,7 @@ public abstract class GlobFunctionTest extends TestCase {
return (GlobValue) result.get(skyKey);
}
+ @Test
public void testGlobWithoutWildcards() throws Exception {
String pattern = "foo/bar/wiz/file";
@@ -366,6 +397,7 @@ public abstract class GlobFunctionTest extends TestCase {
}
}
+ @Test
public void testIllegalPatterns() throws Exception {
assertIllegalPattern("(illegal) pattern");
assertIllegalPattern("[illegal pattern");
@@ -382,6 +414,7 @@ public abstract class GlobFunctionTest extends TestCase {
assertIllegalPattern("foo//bar");
}
+ @Test
public void testIllegalRecursivePatterns() throws Exception {
for (String prefix : Lists.newArrayList("", "*/", "**/", "ba/")) {
String suffix = ("/" + prefix).substring(0, prefix.length());
@@ -404,6 +437,7 @@ public abstract class GlobFunctionTest extends TestCase {
/**
* Tests that globs can contain Java regular expression special characters
*/
+ @Test
public void testSpecialRegexCharacter() throws Exception {
Path aDotB = pkgPath.getChild("a.b");
FileSystemUtils.createEmptyFile(aDotB);
@@ -414,10 +448,12 @@ public abstract class GlobFunctionTest extends TestCase {
.containsExactly(aDotB);
}
+ @Test
public void testMatchesCallWithNoCache() {
assertTrue(UnixGlob.matches("*a*b", "CaCb", null));
}
+ @Test
public void testHiddenFiles() throws Exception {
for (String dir : ImmutableList.of(".hidden", "..also.hidden", "not.hidden")) {
FileSystemUtils.createDirectoryAndParents(pkgPath.getRelative(dir));
@@ -428,6 +464,7 @@ public abstract class GlobFunctionTest extends TestCase {
assertGlobMatches("*.hidden", "not.hidden");
}
+ @Test
public void testDoubleStar() throws Exception {
assertGlobMatches(
"**",
@@ -451,10 +488,12 @@ public abstract class GlobFunctionTest extends TestCase {
"fool/barnacle/wiz");
}
+ @Test
public void testDoubleStarExcludeDirs() throws Exception {
assertGlobWithoutDirsMatches("**", "BUILD", "foo/bar/wiz/file");
}
+ @Test
public void testDoubleDoubleStar() throws Exception {
assertGlobMatches(
"**/**",
@@ -478,6 +517,7 @@ public abstract class GlobFunctionTest extends TestCase {
"fool/barnacle/wiz");
}
+ @Test
public void testDirectoryWithDoubleStar() throws Exception {
assertGlobMatches(
"foo/**",
@@ -489,14 +529,17 @@ public abstract class GlobFunctionTest extends TestCase {
"foo/barnacle/wiz");
}
+ @Test
public void testDoubleStarPatternWithNamedChild() throws Exception {
assertGlobMatches("**/bar", "foo/bar");
}
+ @Test
public void testDoubleStarPatternWithChildGlob() throws Exception {
assertGlobMatches("**/ba*", "foo/bar", "foo/barnacle", "food/barnacle", "fool/barnacle");
}
+ @Test
public void testDoubleStarAsChildGlob() throws Exception {
FileSystemUtils.createEmptyFile(pkgPath.getRelative("foo/barnacle/wiz/wiz"));
FileSystemUtils.createDirectoryAndParents(pkgPath.getRelative("foo/barnacle/baz/wiz"));
@@ -509,15 +552,18 @@ public abstract class GlobFunctionTest extends TestCase {
"foo/barnacle/wiz/wiz");
}
+ @Test
public void testDoubleStarUnderNonexistentDirectory() throws Exception {
assertGlobMatches("not-there/**" /* => nothing */);
}
+ @Test
public void testDoubleStarUnderFile() throws Exception {
assertGlobMatches("foo/bar/wiz/file/**" /* => nothing */);
}
/** Regression test for b/13319874: Directory listing crash. */
+ @Test
public void testResilienceToFilesystemInconsistencies_DirectoryExistence() throws Exception {
long nodeId = pkgPath.getRelative("BUILD").stat().getNodeId();
// Our custom filesystem says "pkgPath/BUILD" exists but "pkgPath" does not exist.
@@ -546,6 +592,7 @@ public abstract class GlobFunctionTest extends TestCase {
assertThat(errorInfo.getException().getMessage()).contains(expectedMessage);
}
+ @Test
public void testResilienceToFilesystemInconsistencies_SubdirectoryExistence() throws Exception {
// Our custom filesystem says directory "pkgPath/foo/bar" contains a subdirectory "wiz" but a
// direct stat on "pkgPath/foo/bar/wiz" says it does not exist.
@@ -572,6 +619,7 @@ public abstract class GlobFunctionTest extends TestCase {
assertThat(errorInfo.getException().getMessage()).contains(expectedMessage);
}
+ @Test
public void testResilienceToFilesystemInconsistencies_SymlinkType() throws Exception {
RootedPath wizRootedPath = RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz"));
RootedPath fileRootedPath =