Page MenuHomePhabricator

D8465.id20075.diff
No OneTemporary

D8465.id20075.diff

diff --git a/src/unit/engine/phutil/ArcanistPhutilTestCase.php b/src/unit/engine/phutil/ArcanistPhutilTestCase.php
--- a/src/unit/engine/phutil/ArcanistPhutilTestCase.php
+++ b/src/unit/engine/phutil/ArcanistPhutilTestCase.php
@@ -7,8 +7,6 @@
* @task exceptions Exception Handling
* @task hook Hooks for Setup and Teardown
* @task internal Internals
- *
- * @group unitrun
*/
abstract class ArcanistPhutilTestCase {
@@ -25,8 +23,9 @@
/* -( Making Test Assertions )--------------------------------------------- */
+
/**
- * Assert that a value is false. The test fails if it is not.
+ * Assert that a value is `false`, strictly. The test fails if it is not.
*
* @param wild The empirically derived value, generated by executing the
* test.
@@ -42,21 +41,12 @@
return;
}
- $result = PhutilReadableSerializer::printableValue($result);
- $caller = self::getCallerInfo();
-
- $output = "Assertion failed at line {$caller['line']} in {$caller['file']}";
-
- if ($message) {
- $output .= ": {$message}";
- }
-
- $this->failTest($output);
- throw new ArcanistPhutilTestTerminatedException($output);
+ $this->failAssertionWithExpectedValue('false', $result, $message);
}
+
/**
- * Assert that a value is true. The test fails if it is not.
+ * Assert that a value is `true`, strictly. The test fails if it is not.
*
* @param wild The empirically derived value, generated by executing the
* test.
@@ -72,23 +62,14 @@
return;
}
- $result = PhutilReadableSerializer::printableValue($result);
- $caller = self::getCallerInfo();
-
- $output = "Assertion failed at line {$caller['line']} in {$caller['file']}";
-
- if ($message) {
- $output .= ": {$message}";
- }
-
- $this->failTest($output);
- throw new ArcanistPhutilTestTerminatedException($output);
+ $this->failAssertionWithExpectedValue('true', $result, $message);
}
+
/**
- * Assert that two values are equal. The test fails if they are not.
+ * 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
+ * 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.
*
@@ -111,11 +92,20 @@
$expect = PhutilReadableSerializer::printableValue($expect);
$result = PhutilReadableSerializer::printableValue($result);
$caller = self::getCallerInfo();
-
- $output = "Assertion failed at line {$caller['line']} in {$caller['file']}";
-
- if ($message) {
- $output .= ": {$message}";
+ $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";
@@ -665,4 +655,50 @@
);
}
+
+ /**
+ * Fail an assertion which checks that some result is equal to a specific
+ * value, like 'true' or 'false'. This prints a readable error message and
+ * fails the current test.
+ *
+ * This method throws and does not return.
+ *
+ * @param string Human readable description of the expected value.
+ * @param string The actual value.
+ * @param string|null Optional assertion message.
+ * @return void
+ * @task internal
+ */
+ private function failAssertionWithExpectedValue(
+ $expect_description,
+ $actual_result,
+ $message) {
+
+ $caller = self::getCallerInfo();
+ $file = $caller['file'];
+ $line = $caller['line'];
+
+ if ($message !== null) {
+ $description = pht(
+ "Assertion failed, expected '%s' (at %s:%d): %s",
+ $expect_description,
+ $file,
+ $line,
+ $message);
+ } else {
+ $description = pht(
+ "Assertion failed, expected '%s' (at %s:%d).",
+ $expect_description,
+ $file,
+ $line);
+ }
+
+ $actual_result = PhutilReadableSerializer::printableValue($actual_result);
+ $header = pht('ACTUAL VALUE');
+ $output = $description."\n\n".$header."\n".$actual_result;
+
+ $this->failTest($output);
+ throw new ArcanistPhutilTestTerminatedException($output);
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 17, 10:52 AM (5 d, 21 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7229625
Default Alt Text
D8465.id20075.diff (4 KB)

Event Timeline