From e78df4dc9f3dc78fdf0bc3c2ae0e86c3f1437b0b Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 3 Apr 2008 21:24:16 +0000 Subject: [PATCH] [3.1.0] When flush fails, fail SimpleTest git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1641 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 2 ++ TODO | 3 --- tests/common.php | 30 ++++++++++++++++++++++++++++++ tests/index.php | 24 ++++++++++-------------- tests/multitest.php | 19 ++++++++++--------- 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index 7b835ea3..2e7ce690 100644 --- a/NEWS +++ b/NEWS @@ -80,6 +80,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier . HTMLPURIFIER_STRICT removed; no validation is performed on runtime, only during cache generation . Reordered script calls in maintenance/flush.php +. Command line scripts now honor exit codes +. When --flush fails in unit testers, abort tests and print message 3.0.0, released 2008-01-06 # HTML Purifier is PHP 5 only! The 2.1.x branch will be maintained diff --git a/TODO b/TODO index 097a7cfb..a26271e1 100644 --- a/TODO +++ b/TODO @@ -27,9 +27,6 @@ DOCUMENTATION IMPORTANT FEATURES - Get everything into configuration objects (filters, I'm looking at you) - Factor out command line parser into its own class, and unit test it - - Verbose mode for webtester that includes transcript from command line - - Command line maintenance scripts must complain with exit(1) if there are - fatal errors - Emit notices when aliases are used (allow muting these errors) CONFIGDOC diff --git a/tests/common.php b/tests/common.php index 9fc987ff..773761c9 100644 --- a/tests/common.php +++ b/tests/common.php @@ -178,3 +178,33 @@ function printTokens($tokens, $index = null) { $string .= ''; echo $string; } + +/** + * Convenient "insta-fail" test-case to add if any outside things fail + */ +class FailedTest extends UnitTestCase { + protected $msg, $details; + public function __construct($msg, $details = null) { + $this->msg = $msg; + $this->details = $details; + } + public function test() { + $this->fail($this->msg); + if ($this->details) $this->_reporter->paintFormattedMessage($this->details); + } +} + +/** + * Flushes all caches, and fatally errors out if there's a problem. + */ +function htmlpurifier_flush($php, $reporter) { + exec($php . ' ../maintenance/flush.php', $out, $status); + if ($status) { + $test = new FailedTest( + 'maintenance/flush.php returned non-zero exit status', + wordwrap(implode("\n", $out), 80) + ); + $test->run($reporter); + exit(1); + } +} diff --git a/tests/index.php b/tests/index.php index 3a164d5e..f9a3ab3e 100755 --- a/tests/index.php +++ b/tests/index.php @@ -59,12 +59,17 @@ if ($AC['disable-phpt'] && $AC['only-phpt']) { // Shell-script code is executed +if ($AC['xml']) { + if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8'); + $reporter = new XmlReporter(); +} elseif (SimpleReporter::inCli()) { + $reporter = new TextReporter(); +} else { + $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC); +} + if ($AC['flush']) { - if (SimpleReporter::inCli() && !$AC['xml']) { - passthru($AC['php'] . ' ../maintenance/flush.php'); - } else { - shell_exec($AC['php'] . ' ../maintenance/flush.php'); - } + htmlpurifier_flush($AC['php'], $reporter); } // initialize and load HTML Purifier @@ -157,15 +162,6 @@ if ($AC['file']) { } -if ($AC['xml']) { - if (!SimpleReporter::inCli()) header('Content-Type: text/xml;charset=UTF-8'); - $reporter = new XmlReporter(); -} elseif (SimpleReporter::inCli()) { - $reporter = new TextReporter(); -} else { - $reporter = new HTMLPurifier_SimpleTest_Reporter('UTF-8', $AC); -} - if ($AC['dry']) $reporter->makeDry(); $test->run($reporter); diff --git a/tests/multitest.php b/tests/multitest.php index 0ffdccbb..7a14b821 100644 --- a/tests/multitest.php +++ b/tests/multitest.php @@ -46,10 +46,15 @@ $aliases = array( ); htmlpurifier_parse_args($AC, $aliases); +if ($AC['xml']) { + $reporter = new XmlReporter(); +} else { + $reporter = new TextReporter(); +} + // Regenerate any necessary files -shell_exec($AC['php'] . ' ../maintenance/flush.php'); +htmlpurifier_flush($AC['php'], $reporter); -$test = new TestSuite('HTML Purifier Multiple Versions Test'); $file = ''; $test_files = array(); @@ -59,13 +64,14 @@ if ($AC['file']) { if (isset($test_files_lookup[$AC['file']])) { $file = '--file=' . $AC['file']; } else { - echo "Invalid file passed\n"; - exit; + throw new Exception("Invalid file passed"); } } // This allows us to get out of having to do dry runs. $size = count($test_files); +// Setup the test +$test = new TestSuite('HTML Purifier Multiple Versions Test'); foreach ($versions_to_test as $version) { $flush = ''; if (is_array($version)) { @@ -104,11 +110,6 @@ foreach ($versions_to_test as $version) { // add more websites, i.e. more configurations to test. $test->addTestCase(new RemoteTestCase('http://htmlpurifier.org/dev/tests/?xml=1', 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1')); -if ($AC['xml']) { - $reporter = new XmlReporter(); -} else { - $reporter = new TextReporter(); -} $test->run($reporter); shell_exec($AC['php'] . ' ../maintenance/flush-definition-cache.php'); -- 2.11.4.GIT