Search in sources :

Example 1 with SettableFakeClock

use of com.facebook.buck.timing.SettableFakeClock in project buck by facebook.

the class ProjectGeneratorTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
    clock = new SettableFakeClock(0, 0);
    fakeProjectFilesystem = new FakeProjectFilesystem(clock);
    projectCell = (new TestCellBuilder()).setFilesystem(fakeProjectFilesystem).build();
    projectFilesystem = projectCell.getFilesystem();
    rootPath = projectFilesystem.getRootPath();
    // Add files and directories used to test resources.
    projectFilesystem.createParentDirs(Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("foodir", "foo.png"));
    projectFilesystem.writeContentsToPath("", Paths.get("bar.png"));
    fakeProjectFilesystem.touch(Paths.get("Base.lproj", "Bar.storyboard"));
    halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(fakeProjectFilesystem);
    ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("cflags", "-Wno-deprecated -Wno-conversion", "cxxflags", "-Wundeclared-selector -Wno-objc-designated-initializers"), "apple", ImmutableMap.of("force_dsym_mode_in_build_with_buck", "false"), "swift", ImmutableMap.of("version", "1.23"));
    BuckConfig config = FakeBuckConfig.builder().setSections(sections).build();
    cxxBuckConfig = new CxxBuckConfig(config);
    appleConfig = new AppleConfig(config);
    swiftBuckConfig = new SwiftBuckConfig(config);
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 2 with SettableFakeClock

use of com.facebook.buck.timing.SettableFakeClock in project buck by facebook.

the class PathHashingTest method sameContentsSameNameHaveSameHash.

@Test
public void sameContentsSameNameHaveSameHash() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(1000, 0);
    FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
    filesystem1.touch(Paths.get("foo/bar.txt"));
    FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
    filesystem2.touch(Paths.get("foo/bar.txt"));
    Hasher hasher1 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
    Hasher hasher2 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
    assertThat(hasher1.hash(), equalTo(hasher2.hash()));
}
Also used : Hasher(com.google.common.hash.Hasher) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 3 with SettableFakeClock

use of com.facebook.buck.timing.SettableFakeClock in project buck by facebook.

the class PathHashingTest method sameContentsDifferentNameHaveDifferentHashes.

@Test
public void sameContentsDifferentNameHaveDifferentHashes() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(1000, 0);
    FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
    filesystem1.touch(Paths.get("foo/bar.txt"));
    FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
    filesystem2.touch(Paths.get("foo/baz.txt"));
    Hasher hasher1 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
    Hasher hasher2 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
    assertThat(hasher1.hash(), not(equalTo(hasher2.hash())));
}
Also used : Hasher(com.google.common.hash.Hasher) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 4 with SettableFakeClock

use of com.facebook.buck.timing.SettableFakeClock in project buck by facebook.

the class PathHashingTest method sameNameDifferentContentsHaveDifferentHashes.

@Test
public void sameNameDifferentContentsHaveDifferentHashes() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(1000, 0);
    FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
    filesystem1.touch(Paths.get("foo/bar.txt"));
    FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
    filesystem2.touch(Paths.get("foo/bar.txt"));
    Hasher hasher1 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
    Hasher hasher2 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher2, modifiedFileHashCache, filesystem2, Paths.get("foo"));
    assertThat(hasher1.hash(), not(equalTo(hasher2.hash())));
}
Also used : Hasher(com.google.common.hash.Hasher) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 5 with SettableFakeClock

use of com.facebook.buck.timing.SettableFakeClock in project buck by facebook.

the class PathHashingTest method hashDoesNotDependOnFilesystemIterationOrder.

@Test
public void hashDoesNotDependOnFilesystemIterationOrder() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(1000, 0);
    FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
    filesystem1.touch(Paths.get("foo/foo.txt"));
    filesystem1.touch(Paths.get("foo/bar.txt"));
    filesystem1.touch(Paths.get("foo/baz.txt"));
    FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
    filesystem2.touch(Paths.get("foo/bar.txt"));
    filesystem2.touch(Paths.get("foo/baz.txt"));
    filesystem2.touch(Paths.get("foo/foo.txt"));
    Hasher hasher1 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
    Hasher hasher2 = Hashing.sha1().newHasher();
    PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
    assertThat(hasher1.hash(), equalTo(hasher2.hash()));
}
Also used : Hasher(com.google.common.hash.Hasher) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Aggregations

SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)24 Test (org.junit.Test)21 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 TestConsole (com.facebook.buck.testutil.TestConsole)8 FakeListeningProcessExecutor (com.facebook.buck.util.FakeListeningProcessExecutor)8 Hasher (com.google.common.hash.Hasher)4 Before (org.junit.Before)3 Path (java.nio.file.Path)2 NSString (com.dd.plist.NSString)1 AppleConfig (com.facebook.buck.apple.AppleConfig)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)1 HalideBuckConfig (com.facebook.buck.halide.HalideBuckConfig)1 ReactNativeBuckConfig (com.facebook.buck.js.ReactNativeBuckConfig)1 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)1 SwiftBuckConfig (com.facebook.buck.swift.SwiftBuckConfig)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1