use of com.facebook.buck.android.SmartDexingStep.DxPseudoRule in project buck by facebook.
the class SmartDexingStepTest method testDxPseudoRuleCaching.
/**
* Tests whether pseudo rule cache detection is working properly.
*/
@Test
public void testDxPseudoRuleCaching() throws IOException {
File testIn = new File(tmpDir.getRoot(), "testIn");
try (ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(testIn)))) {
zipOut.putNextEntry(new ZipEntry("foobar"));
zipOut.write(new byte[] { 0 });
}
File outputFile = tmpDir.newFile("out.dex");
Path outputHashFile = new File(tmpDir.getRoot(), "out.dex.hash").toPath();
Files.write("dummy", outputHashFile.toFile(), Charsets.UTF_8);
ProjectFilesystem filesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
Sha1HashCode actualHashCode = Sha1HashCode.of(Strings.repeat("a", 40));
DxPseudoRule rule = new DxPseudoRule(filesystem, ImmutableMap.of(testIn.toPath(), actualHashCode), ImmutableSet.of(testIn.toPath()), outputFile.toPath(), outputHashFile, EnumSet.of(DxStep.Option.NO_OPTIMIZE), Optional.empty(), Optional.empty());
assertFalse("'dummy' is not a matching input hash", rule.checkIsCached());
// Write the real hash into the output hash file and ensure that checkIsCached now
// yields true.
String actualHash = rule.hashInputs();
assertFalse(actualHash.isEmpty());
Files.write(actualHash, outputHashFile.toFile(), Charsets.UTF_8);
assertTrue("Matching input hash should be considered cached", rule.checkIsCached());
}
Aggregations