Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/ArcanistBundleTestCase.php
| Show All 14 Lines | list($err, $stdout) = exec_manual( | ||||
| 'diff --unified=65535 --label %s --label %s -- %s %s', | 'diff --unified=65535 --label %s --label %s -- %s %s', | ||||
| 'file 9999-99-99', | 'file 9999-99-99', | ||||
| 'file 9999-99-99', | 'file 9999-99-99', | ||||
| $this->getResourcePath($old), | $this->getResourcePath($old), | ||||
| $this->getResourcePath($new)); | $this->getResourcePath($new)); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| 1, | 1, | ||||
| $err, | $err, | ||||
| "Expect `diff` to find changes between '{$old}' and '{$new}'."); | pht( | ||||
| "Expect `%s` to find changes between '%s' and '%s'.", | |||||
| 'diff', | |||||
| $old, | |||||
| $new)); | |||||
| return $stdout; | return $stdout; | ||||
| } | } | ||||
| private function loadOneChangeBundle($old, $new) { | private function loadOneChangeBundle($old, $new) { | ||||
| $diff = $this->loadDiff($old, $new); | $diff = $this->loadDiff($old, $new); | ||||
| return ArcanistBundle::newFromDiff($diff); | return ArcanistBundle::newFromDiff($diff); | ||||
| } | } | ||||
| /** | /** | ||||
| * Unarchive a saved git repository and apply each commit as though via | * Unarchive a saved git repository and apply each commit as though via | ||||
| * "arc patch", verifying that the resulting tree hash is identical to the | * "arc patch", verifying that the resulting tree hash is identical to the | ||||
| * tree hash produced by the real commit. | * tree hash produced by the real commit. | ||||
| */ | */ | ||||
| public function testGitRepository() { | public function testGitRepository() { | ||||
| if (phutil_is_windows()) { | if (phutil_is_windows()) { | ||||
| $this->assertSkipped('This test is not supported under Windows.'); | $this->assertSkipped(pht('This test is not supported under Windows.')); | ||||
| } | } | ||||
| $archive = dirname(__FILE__).'/bundle.git.tgz'; | $archive = dirname(__FILE__).'/bundle.git.tgz'; | ||||
| $fixture = PhutilDirectoryFixture::newFromArchive($archive); | $fixture = PhutilDirectoryFixture::newFromArchive($archive); | ||||
| $old_dir = getcwd(); | $old_dir = getcwd(); | ||||
| chdir($fixture->getPath()); | chdir($fixture->getPath()); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | foreach ($commits as $commit) { | ||||
| $expect = Filesystem::readFile($expect_path); | $expect = Filesystem::readFile($expect_path); | ||||
| } | } | ||||
| if ($patch === $expect) { | if ($patch === $expect) { | ||||
| $this->assertEqual($expect, $patch); | $this->assertEqual($expect, $patch); | ||||
| } else { | } else { | ||||
| Filesystem::writeFile($expect_path.'.real', $patch); | Filesystem::writeFile($expect_path.'.real', $patch); | ||||
| throw new Exception( | throw new Exception( | ||||
| "Expected patch and actual patch for {$commit_hash} differ. ". | pht( | ||||
| "Wrote actual patch to '{$expect_path}.real'."); | "Expected patch and actual patch for %s differ. ". | ||||
| "Wrote actual patch to '%s.real'.", | |||||
| $commit_hash, | |||||
| $expect_path)); | |||||
| } | } | ||||
| try { | try { | ||||
| id(new ExecFuture('git apply --index --reject')) | id(new ExecFuture('git apply --index --reject')) | ||||
| ->write($patch) | ->write($patch) | ||||
| ->resolvex(); | ->resolvex(); | ||||
| } catch (CommandException $ex) { | } catch (CommandException $ex) { | ||||
| $temp = new TempFile(substr($commit_hash, 0, 8).'.patch'); | $temp = new TempFile(substr($commit_hash, 0, 8).'.patch'); | ||||
| $temp->setPreserveFile(true); | $temp->setPreserveFile(true); | ||||
| Filesystem::writeFile($temp, $patch); | Filesystem::writeFile($temp, $patch); | ||||
| PhutilConsole::getConsole()->writeErr( | PhutilConsole::getConsole()->writeErr( | ||||
| "Wrote failing patch to '%s'.\n", | "%s\n", | ||||
| $temp); | pht("Wrote failing patch to '%s'.", $temp)); | ||||
| throw $ex; | throw $ex; | ||||
| } | } | ||||
| execx('git commit -m %s', $subject); | execx('git commit -m %s', $subject); | ||||
| list($result_hash) = execx('git log -n1 --format=%s', '%T'); | list($result_hash) = execx('git log -n1 --format=%s', '%T'); | ||||
| $result_hash = trim($result_hash); | $result_hash = trim($result_hash); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $tree_hash, | $tree_hash, | ||||
| $result_hash, | $result_hash, | ||||
| "Commit {$commit_hash}: {$subject}"); | pht('Commit %s: %s', $commit_hash, $subject)); | ||||
| } | } | ||||
| } | } | ||||
| private function makeChangeAssertions($commit, array $raw_changes) { | private function makeChangeAssertions($commit, array $raw_changes) { | ||||
| $changes = array(); | $changes = array(); | ||||
| // Verify that there are no duplicate changes, and rekey the changes on | // Verify that there are no duplicate changes, and rekey the changes on | ||||
| // affected path because we don't care about the order in which the | // affected path because we don't care about the order in which the | ||||
| ▲ Show 20 Lines • Show All 415 Lines • ▼ Show 20 Lines | switch ($commit) { | ||||
| $c->getType()); | $c->getType()); | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| ArcanistDiffChangeType::FILE_TEXT, | ArcanistDiffChangeType::FILE_TEXT, | ||||
| $c->getFileType()); | $c->getFileType()); | ||||
| break; | break; | ||||
| case '228d7be4840313ed805c25c15bba0f7b188af3e6': | case '228d7be4840313ed805c25c15bba0f7b188af3e6': | ||||
| // "Add a text file." | // "Add a text file." | ||||
| // This commit is never reached because we skip the 0th commit junk. | // This commit is never reached because we skip the 0th commit junk. | ||||
| $this->assertTrue(true, 'This is never reached.'); | $this->assertTrue(true, pht('This is never reached.')); | ||||
| break; | break; | ||||
| default: | default: | ||||
| throw new Exception( | throw new Exception( | ||||
| "Commit {$commit} has no change assertions!"); | pht('Commit %s has no change assertions!', $commit)); | ||||
| } | } | ||||
| } | } | ||||
| public function testTrailingContext() { | public function testTrailingContext() { | ||||
| // Diffs need to generate without extra trailing context, or 'patch' will | // Diffs need to generate without extra trailing context, or 'patch' will | ||||
| // choke on them. | // choke on them. | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $this->loadResource('trailing-context.diff'), | $this->loadResource('trailing-context.diff'), | ||||
| ▲ Show 20 Lines • Show All 328 Lines • Show Last 20 Lines | |||||