Use JUnit4 for some of the skyframe tests.
--
MOS_MIGRATED_REVID=106504113
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 8899d79..abeea76 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 @@
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.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 @@
/**
* 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 @@
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 @@
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 @@
.testEquals();
}
+ @Test
public void testIsDirectory() throws Exception {
assertFalse(valueForPath(file("a")).isDirectory());
assertFalse(valueForPath(path("nonexistent")).isDirectory());
@@ -166,6 +179,7 @@
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 @@
assertTrue(valueForPath(symlink("ssfile", "sa")).isFile());
}
+ @Test
public void testSimpleIndependentFiles() throws Exception {
file("a");
file("b");
@@ -187,6 +202,7 @@
assertThat(seenFiles).containsExactly(rootedPath("a"), rootedPath("b"), rootedPath(""));
}
+ @Test
public void testSimpleSymlink() throws Exception {
symlink("a", "b");
file("b");
@@ -195,6 +211,7 @@
assertValueChangesIfContentsOfFileChanges("b", true, "a");
}
+ @Test
public void testTransitiveSymlink() throws Exception {
symlink("a", "b");
symlink("b", "c");
@@ -207,12 +224,14 @@
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 @@
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 @@
RootedPath.toRootedPath(fs.getRootDirectory(), new PathFragment("outside")));
}
+ @Test
public void testAbsoluteSymlink() throws Exception {
symlink("a", "/absolute");
file("b");
@@ -265,18 +288,21 @@
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 @@
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 @@
assertThat(seenFiles).containsExactly(rootedPath("a"), rootedPath("b"), rootedPath(""));
}
+ @Test
public void testBrokenDirectorySymlink() throws Exception {
symlink("a", "b");
file("c");
@@ -322,6 +353,7 @@
assertValueChangesIfContentsOfFileChanges("c", false, "a/aa");
}
+ @Test
public void testTraverseIntoVirtualNonDirectory() throws Exception {
file("dir/a");
symlink("vdir", "dir");
@@ -329,6 +361,7 @@
assertNoError("vdir/a/aa/aaa");
}
+ @Test
public void testFileCreation() throws Exception {
FileValue a = valueForPath(path("file"));
Path p = file("file");
@@ -336,6 +369,7 @@
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 @@
assertThat(valueForPath(p)).isNotEqualTo(a);
}
+ @Test
public void testFileModificationModTime() throws Exception {
fastMd5 = false;
Path p = file("file");
@@ -371,6 +406,7 @@
assertFalse(a.equals(b));
}
+ @Test
public void testFileModificationDigest() throws Exception {
fastMd5 = true;
Path p = file("file");
@@ -380,6 +416,7 @@
assertFalse(a.equals(b));
}
+ @Test
public void testModTimeVsDigest() throws Exception {
Path p = file("somefile", "fizzley");
@@ -391,6 +428,7 @@
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 @@
assertFalse(a.equals(b));
}
+ @Test
public void testFileTypeChange() throws Exception {
Path p = file("file");
FileValue a = valueForPath(p);
@@ -413,6 +452,7 @@
assertFalse(a.equals(c));
}
+ @Test
public void testSymlinkTargetChange() throws Exception {
Path p = symlink("symlink", "foo");
FileValue a = valueForPath(p);
@@ -422,6 +462,7 @@
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testSymlinkTargetContentsChangeModTime() throws Exception {
fastMd5 = false;
Path fooPath = file("foo");
@@ -433,6 +474,7 @@
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testSymlinkTargetContentsChangeDigest() throws Exception {
fastMd5 = true;
Path fooPath = file("foo");
@@ -444,6 +486,7 @@
assertThat(b).isNotEqualTo(a);
}
+ @Test
public void testRealPath() throws Exception {
file("file");
directory("directory");
@@ -474,6 +517,7 @@
assertRealPath("deadlink", "missing_file");
}
+ @Test
public void testRealPathRelativeSymlink() throws Exception {
directory("dir");
symlink("dir/link", "../dir2");
@@ -484,6 +528,7 @@
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 @@
assertValueChangesIfContentsOfFileChanges("/other_root/b", true, "a");
}
+ @Test
public void testFilesOutsideRootHasDepOnBuildID() throws Exception {
Path file = file("/outsideroot");
SequentialBuildDriver driver = makeDriver();
@@ -527,6 +573,7 @@
assertFalse(newValue.exists());
}
+ @Test
public void testFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("/outsideroot");
@@ -541,6 +588,7 @@
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testAbsoluteSymlinksToFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("/outsideroot");
symlink("a", "/outsideroot");
@@ -556,6 +604,7 @@
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testRelativeSymlinksToFilesOutsideRootWhenExternalDisallowed() throws Exception {
file("../outsideroot");
symlink("a", "../outsideroot");
@@ -569,6 +618,7 @@
.isInstanceOf(FileOutsidePackageRootsException.class);
}
+ @Test
public void testAbsoluteSymlinksBackIntoSourcesOkWhenExternalDisallowed() throws Exception {
Path file = file("insideroot");
symlink("a", file.getPathString());
@@ -594,6 +644,7 @@
SkyKey.NODE_NAME));
}
+ @Test
public void testSize() throws Exception {
Path file = file("file");
int fileSize = 20;
@@ -635,6 +686,7 @@
}
}
+ @Test
public void testDigest() throws Exception {
final AtomicInteger digestCalls = new AtomicInteger(0);
int expectedCalls = 0;
@@ -701,6 +753,7 @@
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 @@
+ "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 @@
.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 @@
.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 @@
}
}
+ @Test
public void testFileStateEquality() throws Exception {
file("a");
symlink("b1", "a");
@@ -961,6 +1022,7 @@
.testEquals();
}
+ @Test
public void testSymlinkToPackagePathBoundary() throws Exception {
Path path = path("this/is/a/path");
FileSystemUtils.ensureSymbolicLink(path, pkgRoot);
@@ -1034,22 +1096,27 @@
.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");