From df6ffdf42084bdf6fc163cc4fdb14dfa901f8ec7 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Fri, 15 Apr 2011 00:54:11 +0200 Subject: [PATCH] Three more test cases for the mtn interface added - add tests for getTree(), getChanges() and isCommitLarge() - anonymize the test data somewhat - return false instead of null for unknown revisions given to getChanges() --- src/IDF/Scm/Monotone.php | 2 +- test/IDF/Scm/MonotoneTest.php | 270 +++++++++++++++++++++++++++++++--- 2 files changed, 249 insertions(+), 23 deletions(-) diff --git a/src/IDF/Scm/Monotone.php b/src/IDF/Scm/Monotone.php index 3be8ee5..d75fa6d 100644 --- a/src/IDF/Scm/Monotone.php +++ b/src/IDF/Scm/Monotone.php @@ -599,7 +599,7 @@ class IDF_Scm_Monotone extends IDF_Scm { $revs = $this->_resolveSelector($commit); if (count($revs) == 0) - return null; + return false; $revision = $revs[0]; $out = $this->stdio->exec(array('get_revision', $revision)); diff --git a/test/IDF/Scm/MonotoneTest.php b/test/IDF/Scm/MonotoneTest.php index 8c0c0c0..a278fba 100644 --- a/test/IDF/Scm/MonotoneTest.php +++ b/test/IDF/Scm/MonotoneTest.php @@ -226,8 +226,129 @@ END; public function testGetTree() { - // test root and sub tree fetching - $this->markTestIncomplete(); + $instance = $this->createMock(); + // + // non-existing revision + // + $this->assertEquals(array(), $instance->getTree('789')); + + $stdio = "7890123456789012345678901234567890123456\n"; + $instance->getStdio()->setExpectedOutput(array('select', 't:789'), array(), $stdio); + + $stdio =<<getStdio()->setExpectedOutput(array('get_extended_manifest_of', '7890123456789012345678901234567890123456'), array(), $stdio); + + $stdio =<<getStdio()->setExpectedOutput(array('certs', '276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f'), array(), $stdio); + + // + // root directory + // + $entries = $instance->getTree('t:789'); + $this->assertEquals(3, count($entries)); + + $file = $entries[0]; + $this->assertEquals('', $file->fullpath); + $this->assertEquals('', $file->efullpath); + $this->assertEquals('', $file->file); + $this->assertEquals('tree', $file->type); + $this->assertEquals(0, $file->size); + $this->assertEquals('276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f', $file->rev); + $this->assertEquals('joe@user.com', $file->author); + $this->assertEquals('2011-01-24 00:00:23', $file->date); + $this->assertEquals('initial revision', $file->log); + + $file = $entries[1]; + $this->assertEquals('NEWS', $file->fullpath); + $this->assertEquals('NEWS', $file->efullpath); + $this->assertEquals('NEWS', $file->file); + $this->assertEquals('blob', $file->type); + $this->assertEquals(2104, $file->size); + $this->assertEquals('bf51bb66d1c1ffde9ed2fffe2e8c00942deeaa03', $file->hash); + $this->assertEquals('276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f', $file->rev); + $this->assertEquals('joe@user.com', $file->author); + $this->assertEquals('2011-01-24 00:00:23', $file->date); + $this->assertEquals('initial revision', $file->log); + + $file = $entries[2]; + $this->assertEquals('doc', $file->fullpath); + $this->assertEquals('doc', $file->efullpath); + $this->assertEquals('doc', $file->file); + $this->assertEquals('tree', $file->type); + $this->assertEquals(0, $file->size); + $this->assertEquals('276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f', $file->rev); + $this->assertEquals('joe@user.com', $file->author); + $this->assertEquals('2011-01-24 00:00:23', $file->date); + $this->assertEquals('initial revision', $file->log); + + // + // sub directory + // + $entries = $instance->getTree('t:789', 'doc'); + $this->assertEquals(1, count($entries)); + + $file = $entries[0]; + $this->assertEquals('doc/AUTHORS', $file->fullpath); + $this->assertEquals('doc/AUTHORS', $file->efullpath); + $this->assertEquals('AUTHORS', $file->file); + $this->assertEquals('blob', $file->type); + $this->assertEquals(17024, $file->size); + $this->assertEquals('de9ed2fffe2e8c0094bf51bb66d1c1ff2deeaa03', $file->hash); + $this->assertEquals('276264b0b3f1e70fc1835a700e6e61bdbe4c3f2f', $file->rev); + $this->assertEquals('joe@user.com', $file->author); + $this->assertEquals('2011-01-24 00:00:23', $file->date); + $this->assertEquals('initial revision', $file->log); + + // + // non-existing sub directory + // + $this->assertEquals(array(), $instance->getTree('t:789', 'foo')); } public function testFindAuthor() @@ -277,20 +398,19 @@ END; key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "author" - value "me@thomaskeller.biz" + value "joe@user.com" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "branch" - value "net.venge.monotone" + value "main.branch" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "changelog" - value "* po/de.po: German translation updated -" + value "something changed" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] @@ -306,9 +426,9 @@ END; $this->assertEquals(1, count($ret)); $this->assertTrue($ret[0] instanceof stdClass); - $this->assertEquals('me@thomaskeller.biz', $ret[0]->author); - $this->assertEquals('net.venge.monotone', $ret[0]->branch); - $this->assertEquals('* po/de.po: German translation updated', $ret[0]->title); + $this->assertEquals('joe@user.com', $ret[0]->author); + $this->assertEquals('main.branch', $ret[0]->branch); + $this->assertEquals('something changed', $ret[0]->title); $this->assertEquals('1234567890123456789012345678901234567890', $ret[0]->commit); $this->assertEquals('2011-03-19 13:59:47', $ret[0]->date); } @@ -354,13 +474,13 @@ END; key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "author" - value "me@thomaskeller.biz" + value "joe@user.com" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "branch" - value "net.venge.monotone.source-tree-cleanup" + value "some.branch" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] @@ -386,7 +506,7 @@ END; $this->assertEquals('blob', $file->type); $this->assertEquals(17024, $file->size); $this->assertEquals('fdb579b6682d78fac24912e7a82a8209b9a54099', $file->rev); - $this->assertEquals('me@thomaskeller.biz', $file->author); + $this->assertEquals('joe@user.com', $file->author); $this->assertEquals('2011-01-24 00:00:23', $file->date); $this->assertEquals('update the source paths', $file->log); @@ -397,13 +517,13 @@ END; key [10b5b36b4aadc46c0a946b6e76e087ccdddf8b86] signature "ok" name "author" - value "graydon@pobox.com" + value "mary@jane.com" trust "trusted" key [10b5b36b4aadc46c0a946b6e76e087ccdddf8b86] signature "ok" name "branch" - value "net.venge.monotone.visualc8" + value "feature.branch" trust "trusted" key [10b5b36b4aadc46c0a946b6e76e087ccdddf8b86] @@ -427,7 +547,7 @@ END; $this->assertEquals('tree', $file->type); $this->assertEquals(0, $file->size); $this->assertEquals('a10037b1aa8a905018b72e6bd96fb8f8475f0f65', $file->rev); - $this->assertEquals('graydon@pobox.com', $file->author); + $this->assertEquals('mary@jane.com', $file->author); $this->assertEquals('2006-03-13 08:06:22', $file->date); $this->assertEquals('initial build working', $file->log); } @@ -457,8 +577,68 @@ END; public function testGetChanges() { - // test retrieving the changes of a specific revision - $this->markTestIncomplete(); + $instance = $this->createMock(); + + $this->assertFalse($instance->getChanges('t:234')); + + $stdio = "2345678901234567890123456789012345678901\n"; + $instance->getStdio()->setExpectedOutput(array('select', 't:234'), array(), $stdio); + + $stdio =<<getStdio()->setExpectedOutput(array('get_revision', '2345678901234567890123456789012345678901'), array(), $stdio); + + $expected = (object) array( + 'additions' => array('new_dir', 'new_dir/new_file'), + 'deletions' => array('old_dir', 'old_dir/old_file'), + 'renames' => array('dir_with_old_name' => 'new_dir/dir_with_new_name'), + 'patches' => array('existing_file'), + 'properties' => array( + 'new_dir/dir_with_new_name' => array( + 'some-key' => null, + ), + 'existing_file' => array( + "multi\nline\nkey" => "\nand another\nmultiline\nvalue", + ), + ), + ); + + $this->assertEquals($expected, $instance->getChanges('t:234')); + + // FIXME: properly handle and test merge revisions (issue 581) } public function testGetCommit() @@ -478,13 +658,13 @@ END; key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "author" - value "me@thomaskeller.biz" + value "joe@user.com" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] signature "ok" name "author" - value "graydon@pobox.com" + value "mary@jane.com" trust "trusted" key [1aaecf3a7c227e5545b0504aea5d3716d3128117] @@ -526,7 +706,7 @@ END; $this->assertEquals(array('1234567890123456789012345678901234567891', '1234567890123456789012345678901234567892'), $commit->parents); - $this->assertEquals('me@thomaskeller.biz, graydon@pobox.com', $commit->author); + $this->assertEquals('joe@user.com, mary@jane.com', $commit->author); $this->assertEquals('2011-03-19 13:59:47', $commit->date); $this->assertEquals('something changed', $commit->title); $this->assertEquals("---\nsomething changed here as\nwell, unbelievable!", $commit->full_message); @@ -548,8 +728,54 @@ END; public function testIsCommitLarge() { - // test for true / false with commits with more than 100 changes - $this->markTestIncomplete(); + $instance = $this->createMock(); + + // kind of misleading, I know + $this->assertFalse($instance->isCommitLarge('890')); + + $stdio = "8901234567890123456789012345678901234567\n"; + $instance->getStdio()->setExpectedOutput(array('select', 't:890'), array(), $stdio); + + $stdio =<<getStdio()->setExpectedOutput(array('get_revision', '8901234567890123456789012345678901234567'), array(), $stdio); + + // easy case + $this->assertFalse($instance->isCommitLarge('t:890')); + + // slightly more complex case + $stdio =<<getStdio()->setExpectedOutput(array('get_revision', '8901234567890123456789012345678901234567'), array(), $stdio); + + $this->assertTrue($instance->isCommitLarge('t:890')); } public function testGetChangeLog()