Skip to content

Commit

Permalink
fixup some more tests for Windows.
Browse files Browse the repository at this point in the history
Down to 7 failures all in trigger related tests

Ref: facebook#19
  • Loading branch information
wez committed Jul 30, 2015
1 parent 5ef973b commit 74fb80c
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 42 deletions.
22 changes: 20 additions & 2 deletions arcanist/lib/WatchmanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ function w_is_same_file_list($a, $b) {
return $a == $b;
}

function w_find_subdata_containing_file($subdata, $filename) {
if (!is_array($subdata)) {
return null;
}
$filename = w_normalize_filename($filename);
foreach ($subdata as $sub) {
if (in_array($filename, $sub['files'])) {
return $sub;
}
}
return null;
}



class WatchmanTestCase extends ArcanistPhutilTestCase {
protected $root;
protected $watchman_instance;
Expand Down Expand Up @@ -487,8 +502,11 @@ function assertEqualFileList($a, $b, $message = null) {

$message = "\nfile lists are not equal $where";
}
$this->assertEqual(w_normalize_file_list($a),
w_normalize_file_list($b), $message);
$a = w_normalize_file_list($a);
sort($a);
$b = w_normalize_file_list($b);
sort($b);
$this->assertEqual($a, $b, $message);
}

function assertFileList($root, array $files, $message = null) {
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/bigpcre.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function testBigPCRE() {

// Some libraries will happily parse this big pcre
if (isset($res['error'])) {
if ($res['error'] ==
"failed to parse query: unknown expression term 'pcre'") {
$this->assertSkipped('no PCRE support');
}

$possible = array(
'code 50 repeated subpattern is too long',
'code 20 regular expression is too large',
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/dirname.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class queryDirNameTestCase extends WatchmanTestCase {
function testDirName() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());
for ($i = 0; $i < 5; $i++) {
mkdir("$root/$i/$i/$i/$i/$i", 0777, true);
Expand Down Expand Up @@ -125,8 +125,7 @@ function testDirName() {
$this->assertFailure($results['error'] . ' ' . $label);
}
$files = $results['files'];
sort($files);
$this->assertEqual($expect, $files, $label);
$this->assertEqualFileList($expect, $files, $label);
}
}
}
2 changes: 1 addition & 1 deletion tests/integration/movereadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function testMoveReAdd() {
mkdir("$root/foo/bar");

$since = array('foo/bar');
if (PHP_OS == 'SunOS') {
if (PHP_OS == 'SunOS' || phutil_is_windows()) {
// This makes me sad, but Solaris reports the parent dir
// as changed when we mkdir within it
array_unshift($since, 'foo');
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/pathgen.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function testPathGeneratorCase() {
}

function testPathGeneratorRelativeRoot() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());

touch("$root/a");
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/pcre.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function testPCRE() {
$this->assertFileList($root, array('bar.txt', 'foo.c'));

$out = $this->watchmanCommand('find', $root, '-p', '.*c$');
if (idx($out, 'error', '') == "unknown expression term 'pcre'") {
$this->assertSkipped('no PCRE support');
}
$this->assertEqual('foo.c', $out['files'][0]['name']);

$out = $this->watchmanCommand('find', $root, '-p', '.*txt$');
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/since.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function testSinceIssue2() {
'foo/bar',
'foo/bar/222'
);
if (PHP_OS == 'SunOS') {
if (PHP_OS == 'SunOS' || phutil_is_windows()) {
// This makes me sad, but Solaris reports the parent dir
// as changed when we mkdir within it
array_unshift($since, 'foo');
Expand Down Expand Up @@ -84,7 +84,7 @@ function testSinceIssue1() {
}

function testSinceRelativeRoot() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());

$watch = $this->watch($root);
Expand Down Expand Up @@ -117,7 +117,7 @@ function testSinceRelativeRoot() {
'relative_root' => 'subdir',
'fields' => array('name'),
));
$this->assertEqual(array(), $res['files']);
$this->assertEqualFileList(array(), $res['files']);
$clock = $res['clock'];

// touching just the subdir shouldn't cause anything to show up
Expand All @@ -127,7 +127,7 @@ function testSinceRelativeRoot() {
'relative_root' => 'subdir',
'fields' => array('name'),
));
$this->assertEqual(array(), $res['files']);
$this->assertEqualFileList(array(), $res['files']);
$clock = $res['clock'];

// touching a new file inside the subdir should cause it to show up
Expand All @@ -139,7 +139,7 @@ function testSinceRelativeRoot() {
'fields' => array('name'),
));
sort($res['files']);
$this->assertEqual(array('dir2', 'dir2/bar'), $res['files']);
$this->assertEqualFileList(array('dir2', 'dir2/bar'), $res['files']);
}

function assertFreshInstanceForSince($root, $since, $empty) {
Expand All @@ -150,9 +150,9 @@ function assertFreshInstanceForSince($root, $since, $empty) {
));
$this->assertEqual(true, $res['is_fresh_instance']);
if ($empty) {
$this->assertEqual(array(), $res['files']);
$this->assertEqualFileList(array(), $res['files']);
} else {
$this->assertEqual(array('111'), $res['files']);
$this->assertEqualFileList(array('111'), $res['files']);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/size.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class sizeCompareTestCase extends WatchmanTestCase {
function testSize() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());

touch("$root/empty");
Expand Down
24 changes: 10 additions & 14 deletions tests/integration/subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function needsLiveConnection() {
}

function testImmediateSubscribe() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());
mkdir("$root/.hg");

Expand Down Expand Up @@ -43,7 +43,8 @@ function testImmediateSubscribe() {
$wlock = $ent;
}
}
$this->assertEqual(array('name' => '.hg/wlock', 'exists' => true), $ent);
$this->assertEqual(array('name' => w_normalize_filename('.hg/wlock'),
'exists' => true), $ent);

unlink("$root/.hg/wlock");

Expand All @@ -58,7 +59,8 @@ function testImmediateSubscribe() {
$wlock = $ent;
}
}
$this->assertEqual(array('name' => '.hg/wlock', 'exists' => false), $ent);
$this->assertEqual(array('name' => w_normalize_filename('.hg/wlock'),
'exists' => false), $ent);

$this->watchmanCommand('unsubscribe', $root, 'nodefer');
} catch (Exception $e) {
Expand Down Expand Up @@ -116,21 +118,15 @@ function testSubscribe() {
$files = $sub['files'];
$this->assertEqual(array('lemon'), $files);

// delete a file and see that subscribe tells us about it
// delete a file and see that subscribe tells us about it.
unlink("$root/a/lemon");
$this->waitForSub('myname', function ($data) {
return true;
return w_find_subdata_containing_file($data, 'a/lemon') !== null;
});
$sub = $this->tail($this->getSubData('myname'));

$sub = w_find_subdata_containing_file(
$this->getSubData('myname'), 'a/lemon');
$this->assertTrue(is_array($sub), 'missing `myname` subscription data');
$this->assertEqual(false, $sub['is_fresh_instance']);
$expect = array('a/lemon');
if (PHP_OS == 'SunOS') {
// This makes me sad, but Solaris reports the parent dir
// as changed, too
array_unshift($expect, 'a');
}
$this->assertEqualFileList($expect, $sub['files']);

$this->waitForSub('relative', function ($data) {
return true;
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/suffixgenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ function testGeneratorExpr() {
'fields' => array('name'),
'suffix' => array('c','txt')
));
sort($res['files']);
$this->assertEqualFileList(array('foo.c', 'subdir/bar.txt'), $res['files']);

$res = $this->watchmanCommand('query', $root, array(
'expression' => array('true'),
'fields' => array('name'),
'suffix' => array('c', 'txt'),
'relative_root' => 'subdir/',
'relative_root' => 'subdir',
));
$this->assertEqual(array('bar.txt'), $res['files']);
$this->assertEqualFileList(array('bar.txt'), $res['files']);

$res = $this->watchmanCommand('query', $root, array(
'expression' => array('true'),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/trigger-chdir.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function () use ($env, $root, $root_pat) {
}

function testChdirRelativeRoot() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$log = $dir->getPath() . "log";
$env = $dir->getPath() . "env";
$root = realpath($dir->getPath()) . "/dir";
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/trigger-stdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function testAppendTrigger() {
}

function testAppendTriggerRelativeRoot() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$log = $dir->getPath() . "log";
$root = realpath($dir->getPath()) . "/dir";

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/type.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function testTypeExpr() {
});
$this->assertEqual(array(
array('name' => 'foo.c', 'type' => 'f'),
array('name' => 'subdir/bar.txt', 'type' => 'f')
array('name' => w_normalize_filename('subdir/bar.txt'), 'type' => 'f')
), $res['files']);

$res = $this->watchmanCommand('query', $root, array(
Expand Down
10 changes: 3 additions & 7 deletions tests/integration/watch-del-all.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class watchDelAllTestCase extends WatchmanTestCase {
function testWatchDelAll() {
$dir = PhutilDirectoryFixture::newEmptyFixture();
$dir = new WatchmanDirectoryFixture();
$root = realpath($dir->getPath());

$files = array('a', 'b', 'c', 'd', 'e');
Expand All @@ -28,15 +28,11 @@ function ($file) use($root) {

$resp = $this->watchmanCommand('watch-list');
$watched = $resp['roots'];
sort($watched);

$this->assertEqual($dirs, $watched);
$this->assertEqualFileList($dirs, $watched);

$resp = $this->watchmanCommand('watch-del-all');
$watched = $resp['roots'];
sort($watched);

$this->assertEqual($dirs, $watched);
$this->assertEqualFileList($dirs, $watched);

$resp = $this->watchmanCommand('watch-list');

Expand Down

0 comments on commit 74fb80c

Please sign in to comment.