1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 22:10:54 +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
/*
* 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}";
}
if (is_array($result)) {
$result = print_r($result, true);
$output .= "\n";
if (strpos($expect, "\n") !== false) {
$expect = "\n{$expect}";
}
$message = "Values {$expect} and {$result} differ: {$message}";
$this->failTest($message);
throw new ArcanistPhutilTestTerminatedException($message);
if (strpos($result, "\n") !== false) {
$result = "\n{$result}";
}
$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/result');
phutil_require_module('phutil', 'readableserializer');
phutil_require_module('phutil', 'utils');
phutil_require_source('ArcanistPhutilTestCase.php');