mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-09 16:32:39 +01:00
[Wilds] Tailor the behavior of some unit tests which print_r($the_entire_world, true)
Summary: Ref T13098. I've eventually made `arc unit` at least sort of run, but a few unit tests have an issue under the new code. We have a couple of cases where we `print_r($stack, true)` or `print_r($exception, true)`, which is effectively the same because exceptions include a stack. In one case, we search in the stack for values to make sure `PhutilOpaqueEnvelope` is really masking secrets. In another case, we just use `print_r(...)` to label test cases, but some test data is exceptions. Under the new code, the `arc unit` stack has access to a much larger "world" via variables reachable in stack frames, since it's connected to all toolsets/workflows and those objects are more deeply interconnected. This makes the output from `print_r($stack)` enormous and slow (20+ seconds) because of all the recursive referencing of complex variables. In the case where we're looking at the stack, just print the last couple frames. Also add some positive code that searches for a known value in the stack. In the case where we're describing variables, just drop the code. We don't really need to label these test cases, the "expect" value is sufficiently clear on its own. Test Plan: Later, ran `arc unit` and saw it finish in a reasonable amount of time instead of hanging forever on these tests. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13098 Differential Revision: https://secure.phabricator.com/D19709
This commit is contained in:
parent
97651311bd
commit
12722b9ea9
2 changed files with 22 additions and 8 deletions
|
@ -8,9 +8,13 @@ final class PhutilOpaqueEnvelopeTestCase extends PhutilTestCase {
|
|||
// the diff itself, and thus this source code. Since we look for the secret
|
||||
// in traces later on, split it apart here so that invocation via
|
||||
// "arc diff" doesn't create a false test failure.
|
||||
|
||||
$secret = 'hunter'.'2';
|
||||
|
||||
// Also split apart this "signpost" value which we are not going to put in
|
||||
// an envelope. We expect to be able to find it in the argument lists in
|
||||
// stack traces, and don't want a false positive.
|
||||
$signpost = 'shaman'.'3';
|
||||
|
||||
$envelope = new PhutilOpaqueEnvelope($secret);
|
||||
|
||||
$this->assertFalse(strpos(var_export($envelope, true), $secret));
|
||||
|
@ -24,23 +28,34 @@ final class PhutilOpaqueEnvelopeTestCase extends PhutilTestCase {
|
|||
$this->assertFalse(strpos($dump, $secret));
|
||||
|
||||
try {
|
||||
$this->throwTrace($envelope);
|
||||
$this->throwTrace($envelope, $signpost);
|
||||
} catch (Exception $ex) {
|
||||
$trace = $ex->getTrace();
|
||||
$this->assertFalse(strpos(print_r($trace, true), $secret));
|
||||
|
||||
// NOTE: The entire trace may be very large and contain complex
|
||||
// recursive datastructures. Look at only the last few frames: we expect
|
||||
// to see the signpost value but not the secret.
|
||||
$trace = array_slice($trace, 0, 2);
|
||||
$trace = print_r($trace, true);
|
||||
|
||||
$this->assertTrue(strpos($trace, $signpost) !== false);
|
||||
$this->assertFalse(strpos($trace, $secret));
|
||||
}
|
||||
|
||||
$backtrace = $this->getBacktrace($envelope);
|
||||
$backtrace = $this->getBacktrace($envelope, $signpost);
|
||||
$backtrace = array_slice($backtrace, 0, 2);
|
||||
|
||||
$this->assertTrue(strpos($trace, $signpost) !== false);
|
||||
$this->assertFalse(strpos(print_r($backtrace, true), $secret));
|
||||
|
||||
$this->assertEqual($secret, $envelope->openEnvelope());
|
||||
}
|
||||
|
||||
private function throwTrace($v) {
|
||||
private function throwTrace($v, $w) {
|
||||
throw new Exception('!');
|
||||
}
|
||||
|
||||
private function getBacktrace($v) {
|
||||
private function getBacktrace($v, $w) {
|
||||
return debug_backtrace();
|
||||
}
|
||||
|
||||
|
|
|
@ -150,8 +150,7 @@ final class PhutilTypeSpecTestCase extends PhutilTestCase {
|
|||
foreach ($map as $expect => $input) {
|
||||
$this->assertEqual(
|
||||
$expect,
|
||||
PhutilTypeSpec::getTypeOf($input),
|
||||
print_r($input, true));
|
||||
PhutilTypeSpec::getTypeOf($input));
|
||||
|
||||
PhutilTypeSpec::newFromString($expect)->check($input);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue