1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-03-08 18:34:46 +01:00

Slightly improve Arcanist unit test output messages

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
This commit is contained in:
epriestley 2012-01-04 07:02:41 -08:00
parent 62e527482b
commit 91d273a7dd
2 changed files with 30 additions and 8 deletions

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -57,17 +57,36 @@ abstract class ArcanistPhutilTestCase {
return; return;
} }
if (is_array($expect)) { $expect = PhutilReadableSerializer::printableValue($expect);
$expect = print_r($expect, true); $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}";
} }
if (is_array($result)) { $output .= "\n";
$result = print_r($result, true);
if (strpos($expect, "\n") !== false) {
$expect = "\n{$expect}";
} }
$message = "Values {$expect} and {$result} differ: {$message}"; if (strpos($result, "\n") !== false) {
$this->failTest($message); $result = "\n{$result}";
throw new ArcanistPhutilTestTerminatedException($message); }
$output .= "Expected: {$expect}\n";
$output .= "Actual: {$result}";
$this->failTest($output);
throw new ArcanistPhutilTestTerminatedException($output);
} }

View file

@ -9,5 +9,8 @@
phutil_require_module('arcanist', 'unit/engine/phutil/testcase/exception'); phutil_require_module('arcanist', 'unit/engine/phutil/testcase/exception');
phutil_require_module('arcanist', 'unit/result'); phutil_require_module('arcanist', 'unit/result');
phutil_require_module('phutil', 'readableserializer');
phutil_require_module('phutil', 'utils');
phutil_require_source('ArcanistPhutilTestCase.php'); phutil_require_source('ArcanistPhutilTestCase.php');