Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/phutil/ArcanistPhutilTestCase.php
| Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | final protected function assertEqual($expect, $result, $message = null) { | ||||
| $expect = PhutilReadableSerializer::printableValue($expect); | $expect = PhutilReadableSerializer::printableValue($expect); | ||||
| $result = PhutilReadableSerializer::printableValue($result); | $result = PhutilReadableSerializer::printableValue($result); | ||||
| $caller = self::getCallerInfo(); | $caller = self::getCallerInfo(); | ||||
| $file = $caller['file']; | $file = $caller['file']; | ||||
| $line = $caller['line']; | $line = $caller['line']; | ||||
| if ($message !== null) { | if ($message !== null) { | ||||
| $output = pht( | $output = pht( | ||||
| "Assertion failed, expected values to be equal (at %s:%d): %s", | 'Assertion failed, expected values to be equal (at %s:%d): %s', | ||||
| $file, | $file, | ||||
| $line, | $line, | ||||
| $message); | $message); | ||||
| } else { | } else { | ||||
| $output = pht( | $output = pht( | ||||
| "Assertion failed, expected values to be equal (at %s:%d).", | 'Assertion failed, expected values to be equal (at %s:%d).', | ||||
| $file, | $file, | ||||
| $line); | $line); | ||||
| } | } | ||||
| $output .= "\n"; | $output .= "\n"; | ||||
| if (strpos($expect, "\n") === false && strpos($result, "\n") === false) { | if (strpos($expect, "\n") === false && strpos($result, "\n") === false) { | ||||
| $output .= "Expected: {$expect}\n"; | $output .= "Expected: {$expect}\n"; | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | /* -( Exception Handling )------------------------------------------------- */ | ||||
| final protected function tryTestCases( | final protected function tryTestCases( | ||||
| array $inputs, | array $inputs, | ||||
| array $expect, | array $expect, | ||||
| $callable, | $callable, | ||||
| $exception_class = 'Exception') { | $exception_class = 'Exception') { | ||||
| if (count($inputs) !== count($expect)) { | if (count($inputs) !== count($expect)) { | ||||
| $this->assertFailure( | $this->assertFailure( | ||||
| "Input and expectations must have the same number of values."); | 'Input and expectations must have the same number of values.'); | ||||
| } | } | ||||
| $labels = array_keys($inputs); | $labels = array_keys($inputs); | ||||
| $inputs = array_values($inputs); | $inputs = array_values($inputs); | ||||
| $expecting = array_values($expect); | $expecting = array_values($expect); | ||||
| foreach ($inputs as $idx => $input) { | foreach ($inputs as $idx => $input) { | ||||
| $expect = $expecting[$idx]; | $expect = $expecting[$idx]; | ||||
| $label = $labels[$idx]; | $label = $labels[$idx]; | ||||
| ▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | foreach ($methods as $method) { | ||||
| $exceptions['Shutdown'] = $ex; | $exceptions['Shutdown'] = $ex; | ||||
| } | } | ||||
| if ($exceptions) { | if ($exceptions) { | ||||
| if (count($exceptions) == 1) { | if (count($exceptions) == 1) { | ||||
| throw head($exceptions); | throw head($exceptions); | ||||
| } else { | } else { | ||||
| throw new PhutilAggregateException( | throw new PhutilAggregateException( | ||||
| "Multiple exceptions were raised during test execution.", | 'Multiple exceptions were raised during test execution.', | ||||
| $exceptions); | $exceptions); | ||||
| } | } | ||||
| } | } | ||||
| if (!$this->assertions) { | if (!$this->assertions) { | ||||
| $this->failTest( | $this->failTest( | ||||
| pht( | pht( | ||||
| 'This test case made no assertions. Test cases must make at '. | 'This test case made no assertions. Test cases must make at '. | ||||
| ▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines | |||||