]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Slightly improve Arcanist unit test output messages
authorepriestley <git@epriestley.com>
Wed, 4 Jan 2012 15:02:41 +0000 (07:02 -0800)
committerepriestley <git@epriestley.com>
Wed, 4 Jan 2012 22:14:34 +0000 (14:14 -0800)
Summary:
  - Show file/line so you can tell which assertion failed if there's a block
with a zillion of them and they don't have messages.
  - Try to format stuff a little better.

Test Plan:   - Ran some failing unit tests.

Reviewers: btrahan, jungejason

Reviewed By: btrahan

CC: aran, btrahan
Differential Revision: https://secure.phabricator.com/D1304

src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php
src/unit/engine/phutil/testcase/__init__.php

index 2b8b8c2736dcebcc60bc87725b36472eca67b047..a7e6e1f71d7a1db9bca2e6b2561c665b7ddeb1ad 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /*
- * Copyright 2011 Facebook, Inc.
+ * Copyright 2012 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -57,17 +57,36 @@ abstract class ArcanistPhutilTestCase {
       return;
     }
 
-    if (is_array($expect)) {
-      $expect = print_r($expect, true);
+    $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) {
+      $expect = "\n{$expect}";
     }
 
-    if (is_array($result)) {
-      $result = print_r($result, true);
+    if (strpos($result, "\n") !== false) {
+      $result = "\n{$result}";
     }
 
-    $message = "Values {$expect} and {$result} differ: {$message}";
-    $this->failTest($message);
-    throw new ArcanistPhutilTestTerminatedException($message);
+    $output .= "Expected: {$expect}\n";
+    $output .= "Actual: {$result}";
+
+    $this->failTest($output);
+    throw new ArcanistPhutilTestTerminatedException($output);
   }
 
 
index 7f7dbd12838fdfc3d49577571bcffa71d1dd30c3..6a8819e90b466a59fd8bc58e98e0295b2a76b09e 100644 (file)
@@ -9,5 +9,8 @@
 phutil_require_module('arcanist', 'unit/engine/phutil/testcase/exception');
 phutil_require_module('arcanist', 'unit/result');
 
+phutil_require_module('phutil', 'readableserializer');
+phutil_require_module('phutil', 'utils');
+
 
 phutil_require_source('ArcanistPhutilTestCase.php');