/**
  * Assert that two values are equal. The test fails if they are not.
  *
  * NOTE: This method uses PHP's strict equality test operator ("===") to
  * compare values. This means values and types must be equal, key order must
  * be identical in arrays, and objects must be referentially identical.
  *
  * @param wild    The theoretically expected value, generated by careful
  *                reasoning about the properties of the system.
  * @param wild    The empirically derived value, generated by executing the
  *                test.
  * @param string  A human-readable description of what these values represent,
  *                and particularly of what a discrepancy means.
  *
  * @return void
  * @task assert
  */
 protected final function assertEqual($expect, $result, $message = null)
 {
     if ($expect === $result) {
         $this->assertions++;
         return;
     }
     $expect = PhutilReadableSerializer::printableValue($expect);
     $result = PhutilReadableSerializer::printableValue($result);
     $where = debug_backtrace();
     $where = array_shift($where);
     $line = idx($where, 'line');
     $file = basename(idx($where, 'file'));
     $output = "Assertion failed at line {$line} in {$file}";
     if ($message) {
         $output .= ": {$message}";
     }
     $output .= "\n";
     if (strpos($expect, "\n") === false && strpos($result, "\n") === false) {
         $output .= "Expected: {$expect}\n";
         $output .= "Actual: {$result}";
     } else {
         $output .= "Expected vs Actual Output Diff\n";
         $output .= ArcanistDiffUtils::renderDifferences($expect, $result, $lines = 0xffff);
     }
     $this->failTest($output);
     throw new ArcanistPhutilTestTerminatedException($output);
 }
 public final function lintPath($path)
 {
     if (!isset($this->rawLintOutput[$path])) {
         return;
     }
     list($new_content) = $this->rawLintOutput[$path];
     $old_content = $this->getData($path);
     if ($new_content != $old_content) {
         $diff = ArcanistDiffUtils::renderDifferences($old_content, $new_content);
         $this->raiseLintAtOffset(0, self::LINT_FORMATTING, $this->getLintMessage($diff), $old_content, $new_content);
     }
 }
Exemple #3
0
 /**
  * Assert that two values are equal, strictly. The test fails if they are not.
  *
  * NOTE: This method uses PHP's strict equality test operator (`===`) to
  * compare values. This means values and types must be equal, key order must
  * be identical in arrays, and objects must be referentially identical.
  *
  * @param wild    The theoretically expected value, generated by careful
  *                reasoning about the properties of the system.
  * @param wild    The empirically derived value, generated by executing the
  *                test.
  * @param string  A human-readable description of what these values represent,
  *                and particularly of what a discrepancy means.
  *
  * @return void
  * @task assert
  */
 protected final function assertEqual($expect, $result, $message = null)
 {
     if ($expect === $result) {
         $this->assertions++;
         return;
     }
     $expect = PhutilReadableSerializer::printableValue($expect);
     $result = PhutilReadableSerializer::printableValue($result);
     $caller = self::getCallerInfo();
     $file = $caller['file'];
     $line = $caller['line'];
     if ($message !== null) {
         $output = pht('Assertion failed, expected values to be equal (at %s:%d): %s', $file, $line, $message);
     } else {
         $output = pht('Assertion failed, expected values to be equal (at %s:%d).', $file, $line);
     }
     $output .= "\n";
     if (strpos($expect, "\n") === false && strpos($result, "\n") === false) {
         $output .= pht("Expected: %s\n  Actual: %s", $expect, $result);
     } else {
         $output .= pht("Expected vs Actual Output Diff\n%s", ArcanistDiffUtils::renderDifferences($expect, $result, $lines = 0xffff));
     }
     $this->failTest($output);
     throw new PhutilTestTerminatedException($output);
 }