File: twodeep.php

package info (click to toggle)
watchman 4.9.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,992 kB
  • sloc: cpp: 27,459; python: 6,538; java: 3,404; php: 3,257; ansic: 2,803; javascript: 1,116; makefile: 671; ruby: 364; sh: 124; xml: 102; lisp: 4
file content (63 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/* Copyright 2012-present Facebook, Inc.
 * Licensed under the Apache License, Version 2.0 */

class twodeepTestCase extends WatchmanTestCase {
  function testTwoDeep() {
    $dir = new WatchmanDirectoryFixture();
    $root = $dir->getPath();
    $watch = $this->watch($root);

    $this->assertFileList($root, array());

    $this->assertEqual(true, mkdir("$root/foo"));
    $this->assertEqual(true, mkdir("$root/foo/bar"));

    // Guarantee that 111's mtime is greater than its directory's
    sleep(1);
    $this->assertEqual(3, file_put_contents("$root/foo/bar/111", "111"));
    $this->watchmanCommand('log', 'debug', 'XXX: created 111');

    $this->assertFileList($root, array(
      "foo",
      "foo/bar",
      "foo/bar/111"
    ));

    $query = $this->watchmanCommand('find', $root, 'foo/bar/111');
    $wfile = $query['files'][0];
    clearstatcache();
    $sfile = stat("$root/foo/bar/111");

    $query = $this->watchmanCommand('find', $root, 'foo/bar');
    $wdir = $query['files'][0];
    clearstatcache();
    $sdir = stat("$root/foo/bar");

    $this->watchmanCommand('log', 'debug', 'XXX: perform assertions');

    $compare_fields = array('size', 'mode', 'uid', 'gid',
                            'mtime', 'ctime');
    if (!phutil_is_windows()) {
      // These are meaningless in msvcrt, so no sense in comparing them
      $compare_fields[] = 'dev';
      $compare_fields[] = 'ino';
      // We can only get this by directly examining a file, but not implicitly
      // when crawling the dir
      $compare_fields[] = 'nlink';
    }
    foreach ($compare_fields as $field) {
      $this->assertEqual($sfile[$field], $wfile[$field],
        "file: $field {$sfile[$field]} vs watchman {$wfile[$field]} " . json_encode($wfile));
      $this->assertEqual($sdir[$field], $wdir[$field],
        "dir: $field {$sdir[$field]} vs watchman {$wdir[$field]}");
    }

    $this->watchmanCommand('log', 'debug', 'XXX: remove it all');
    w_rmdir_recursive("$root/foo/bar");

    $this->assertFileList($root, array(
      "foo",
    ));
  }
}