Search in sources :

Example 46 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class NestedSetImplTest method shallowEquality.

@Test
public void shallowEquality() {
    // Used below to check that inner nested sets can be compared by reference equality.
    SetWrapper<Integer> myRef = nest(nest(flat(7, 8)), flat(9));
    // Each "equality group" contains elements that are equal to one another
    // (according to equals() and hashCode()), yet distinct from all elements
    // of all other equality groups.
    new EqualsTester().addEqualityGroup(flat(), flat(), // Empty set elision.
    nest(flat())).addEqualityGroup(NestedSetBuilder.<Integer>linkOrder().build()).addEqualityGroup(flat(3), flat(3), // Element de-duplication.
    flat(3, 3)).addEqualityGroup(flat(4), // Automatic elision of one-element nested sets.
    nest(flat(4))).addEqualityGroup(NestedSetBuilder.<Integer>linkOrder().add(4).build()).addEqualityGroup(// Like flat("4").
    nestedSetBuilder("4").build()).addEqualityGroup(flat(3, 4), flat(3, 4)).addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8)))).addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8)))).addEqualityGroup(nest(myRef), nest(myRef), // Set de-duplication.
    nest(myRef, myRef)).addEqualityGroup(nest(3, myRef)).addEqualityGroup(nest(4, myRef)).testEquals();
// Some things that are not tested by the above:
//  - ordering among direct members
//  - ordering among transitive sets
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 47 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class FileFunctionTest method testFileStateEquality.

@Test
public void testFileStateEquality() throws Exception {
    file("a");
    symlink("b1", "a");
    symlink("b2", "a");
    symlink("b3", "zzz");
    directory("d1");
    directory("d2");
    SkyKey file = fileStateSkyKey("a");
    SkyKey symlink1 = fileStateSkyKey("b1");
    SkyKey symlink2 = fileStateSkyKey("b2");
    SkyKey symlink3 = fileStateSkyKey("b3");
    SkyKey missing1 = fileStateSkyKey("c1");
    SkyKey missing2 = fileStateSkyKey("c2");
    SkyKey directory1 = fileStateSkyKey("d1");
    SkyKey directory2 = fileStateSkyKey("d2");
    ImmutableList<SkyKey> keys = ImmutableList.of(file, symlink1, symlink2, symlink3, missing1, missing2, directory1, directory2);
    SequentialBuildDriver driver = makeDriver();
    EvaluationResult<SkyValue> result = driver.evaluate(keys, false, DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE);
    new EqualsTester().addEqualityGroup(result.get(file)).addEqualityGroup(result.get(symlink1), result.get(symlink2)).addEqualityGroup(result.get(symlink3)).addEqualityGroup(result.get(missing1), result.get(missing2)).addEqualityGroup(result.get(directory1), result.get(directory2)).testEquals();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) SequentialBuildDriver(com.google.devtools.build.skyframe.SequentialBuildDriver) SkyValue(com.google.devtools.build.skyframe.SkyValue) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 48 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class ArtifactFunctionTest method testEquality.

@Test
public void testEquality() throws Exception {
    Artifact artifact1 = createDerivedArtifact("artifact1");
    Artifact artifact2 = createDerivedArtifact("artifact2");
    Artifact diffDigest = createDerivedArtifact("diffDigest");
    Artifact diffMtime = createDerivedArtifact("diffMtime");
    Artifact empty1 = createDerivedArtifact("empty1");
    Artifact empty2 = createDerivedArtifact("empty2");
    Artifact empty3 = createDerivedArtifact("empty3");
    Artifact dir1 = createDerivedArtifact("dir1");
    Artifact dir2 = createDerivedArtifact("dir2");
    Artifact dir3 = createDerivedArtifact("dir3");
    Path path1 = artifact1.getPath();
    Path path2 = artifact2.getPath();
    Path digestPath = diffDigest.getPath();
    Path mtimePath = diffMtime.getPath();
    writeFile(artifact1.getPath(), "content");
    writeFile(artifact2.getPath(), "content");
    path1.setLastModifiedTime(0);
    path2.setLastModifiedTime(0);
    // Same size as artifact1.
    writeFile(diffDigest.getPath(), "1234567");
    digestPath.setLastModifiedTime(0);
    writeFile(mtimePath, "content");
    mtimePath.setLastModifiedTime(1);
    Path emptyPath1 = empty1.getPath();
    Path emptyPath2 = empty2.getPath();
    Path emptyPath3 = empty3.getPath();
    writeFile(emptyPath1, "");
    writeFile(emptyPath2, "");
    writeFile(emptyPath3, "");
    emptyPath1.setLastModifiedTime(0L);
    emptyPath2.setLastModifiedTime(1L);
    emptyPath3.setLastModifiedTime(1L);
    Path dirPath1 = dir1.getPath();
    Path dirPath2 = dir2.getPath();
    Path dirPath3 = dir3.getPath();
    FileSystemUtils.createDirectoryAndParents(dirPath1);
    FileSystemUtils.createDirectoryAndParents(dirPath2);
    FileSystemUtils.createDirectoryAndParents(dirPath3);
    dirPath1.setLastModifiedTime(0L);
    dirPath2.setLastModifiedTime(1L);
    dirPath3.setLastModifiedTime(1L);
    EqualsTester equalsTester = new EqualsTester();
    equalsTester.addEqualityGroup(create(artifact1), create(artifact2), create(diffMtime)).addEqualityGroup(create(empty1), create(empty2), create(empty3)).addEqualityGroup(create(dir1)).addEqualityGroup(create(dir2), create(dir3)).testEquals();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) EqualsTester(com.google.common.testing.EqualsTester) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 49 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class ContainingPackageLookupFunctionTest method testEqualsAndHashCodeContract.

@Test
public void testEqualsAndHashCodeContract() throws Exception {
    ContainingPackageLookupValue valueA1 = ContainingPackageLookupValue.NONE;
    ContainingPackageLookupValue valueA2 = ContainingPackageLookupValue.NONE;
    ContainingPackageLookupValue valueB1 = ContainingPackageLookupValue.withContainingPackage(PackageIdentifier.createInMainRepo("b"), rootDirectory);
    ContainingPackageLookupValue valueB2 = ContainingPackageLookupValue.withContainingPackage(PackageIdentifier.createInMainRepo("b"), rootDirectory);
    PackageIdentifier cFrag = PackageIdentifier.createInMainRepo("c");
    ContainingPackageLookupValue valueC1 = ContainingPackageLookupValue.withContainingPackage(cFrag, rootDirectory);
    ContainingPackageLookupValue valueC2 = ContainingPackageLookupValue.withContainingPackage(cFrag, rootDirectory);
    ContainingPackageLookupValue valueCOther = ContainingPackageLookupValue.withContainingPackage(cFrag, rootDirectory.getRelative("other_root"));
    new EqualsTester().addEqualityGroup(valueA1, valueA2).addEqualityGroup(valueB1, valueB2).addEqualityGroup(valueC1, valueC2).addEqualityGroup(valueCOther).testEquals();
}
Also used : PackageIdentifier(com.google.devtools.build.lib.cmdline.PackageIdentifier) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 50 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class FileFunctionTest method testFileValueHashCodeAndEqualsContract.

@Test
public void testFileValueHashCodeAndEqualsContract() throws Exception {
    Path pathA = file(pkgRoot + "a", "a");
    Path pathB = file(pkgRoot + "b", "b");
    FileValue valueA1 = valueForPathOutsidePkgRoot(pathA);
    FileValue valueA2 = valueForPathOutsidePkgRoot(pathA);
    FileValue valueB1 = valueForPathOutsidePkgRoot(pathB);
    FileValue valueB2 = valueForPathOutsidePkgRoot(pathB);
    new EqualsTester().addEqualityGroup(valueA1, valueA2).addEqualityGroup(valueB1, valueB2).testEquals();
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Aggregations

EqualsTester (com.google.common.testing.EqualsTester)177 Test (org.junit.Test)83 GwtIncompatible (com.google.common.annotations.GwtIncompatible)10 ParameterizedType (java.lang.reflect.ParameterizedType)10 WildcardType (java.lang.reflect.WildcardType)8 Method (java.lang.reflect.Method)7 Entry (java.util.Map.Entry)7 GenericArrayType (java.lang.reflect.GenericArrayType)6 Type (java.lang.reflect.Type)6 ImmutableList (com.google.common.collect.ImmutableList)5 Path (com.google.devtools.build.lib.vfs.Path)5 List (java.util.List)5 Set (java.util.Set)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 HashMap (java.util.HashMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Label (com.google.devtools.build.lib.cmdline.Label)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3