Merge pull request #2741 from simonwelsh/hhvm-test

Changes to error message detection to handle the differences in HHVM
This commit is contained in:
Will Rossiter 2013-12-20 16:55:14 -08:00
commit 3d2875a111

View File

@ -13,7 +13,7 @@ class ErrorControlChainTest_Chain extends ErrorControlChain {
return parent::translateMemstring($memstring); return parent::translateMemstring($memstring);
} }
function executeInSubprocess() { function executeInSubprocess($includeStderr = false) {
// Get the path to the ErrorControlChain class // Get the path to the ErrorControlChain class
$classpath = SS_ClassLoader::instance()->getItemPath('ErrorControlChain'); $classpath = SS_ClassLoader::instance()->getItemPath('ErrorControlChain');
$suppression = $this->suppression ? 'true' : 'false'; $suppression = $this->suppression ? 'true' : 'false';
@ -47,10 +47,14 @@ require_once '$classpath';
// Now stick it in a temporary file & run it // Now stick it in a temporary file & run it
$codepath = TEMP_FOLDER.'/ErrorControlChainTest_'.sha1($src).'.php'; $codepath = TEMP_FOLDER.'/ErrorControlChainTest_'.sha1($src).'.php';
$null = is_writeable('/dev/null') ? '/dev/null' : 'NUL'; if($includeStderr) {
$null = '&1';
} else {
$null = is_writeable('/dev/null') ? '/dev/null' : 'NUL';
}
file_put_contents($codepath, $src); file_put_contents($codepath, $src);
exec("php $codepath 2> $null", $stdout, $errcode); exec("php $codepath 2>$null", $stdout, $errcode);
unlink($codepath); unlink($codepath);
return array(implode("\n", $stdout), $errcode); return array(implode("\n", $stdout), $errcode);
@ -185,9 +189,10 @@ class ErrorControlChainTest extends SapphireTest {
->then(function($chain){ ->then(function($chain){
Foo::bar(); // Non-existant class causes fatal error Foo::bar(); // Non-existant class causes fatal error
}) })
->executeInSubprocess(); ->executeInSubprocess(true);
$this->assertContains("Fatal error: Class 'Foo' not found", $out); $this->assertContains('Fatal error', $out);
$this->assertContains('Foo', $out);
// Turning off suppression during execution // Turning off suppression during execution
@ -198,9 +203,10 @@ class ErrorControlChainTest extends SapphireTest {
$chain->setSuppression(false); $chain->setSuppression(false);
Foo::bar(); // Non-existent class causes fatal error Foo::bar(); // Non-existent class causes fatal error
}) })
->executeInSubprocess(); ->executeInSubprocess(true);
$this->assertContains("Fatal error: Class 'Foo' not found", $out); $this->assertContains('Fatal error', $out);
$this->assertContains('Foo', $out);
} }
function testDoesntAffectNonFatalErrors() { function testDoesntAffectNonFatalErrors() {