From edcbbb44c0b12501b08dd3206dc77faca13bdf8e Mon Sep 17 00:00:00 2001 From: tswicegood Date: Sat, 5 Jan 2008 02:33:10 +0000 Subject: [PATCH] make sure that ===DONE=== isn't completely ignored when comparing a checking a regex - fixes #29 git-svn-id: https://svn.phpt.info/Core/trunk@620 54d25d7b-d40e-47af-a99d-8d4037bc02b6 --- src/PHPT/Section/EXPECTREGEX.php | 8 ++++++ .../done-keyword-must-be-present-if-specified.phpt | 29 ++++++++++++++++++++++ tests/Section/Expectregex/ignore-DONE-keyword.phpt | 3 ++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/Section/Expectregex/done-keyword-must-be-present-if-specified.phpt diff --git a/src/PHPT/Section/EXPECTREGEX.php b/src/PHPT/Section/EXPECTREGEX.php index aad6852..5907c4b 100644 --- a/src/PHPT/Section/EXPECTREGEX.php +++ b/src/PHPT/Section/EXPECTREGEX.php @@ -7,6 +7,7 @@ class PHPT_Section_EXPECTREGEX extends PHPT_Section_ExpectationAbstract $pattern = $this->_expected; if (substr($pattern, -10) == '===DONE===') { $pattern = substr($pattern, 0, -10); + $this->_checkForDoneToken($case); } if ($pattern[0] != '/') { $pattern = '/' . trim($pattern) . '/'; @@ -20,4 +21,11 @@ class PHPT_Section_EXPECTREGEX extends PHPT_Section_ExpectationAbstract } return $result; } + + private function _checkForDoneToken(PHPT_Case $case) + { + if (substr($case->output, -10) != '===DONE===') { + throw new PHPT_Section_EXPECTREGEX_UnexpectedOutputException($case, $this->_expected); + } + } } diff --git a/tests/Section/Expectregex/done-keyword-must-be-present-if-specified.phpt b/tests/Section/Expectregex/done-keyword-must-be-present-if-specified.phpt new file mode 100644 index 0000000..00e9008 --- /dev/null +++ b/tests/Section/Expectregex/done-keyword-must-be-present-if-specified.phpt @@ -0,0 +1,29 @@ +--TEST-- +If ===DONE=== is present, that must be the final ten characters of the +provided test output +--FILE-- +output = 'foobar' . rand(100, 200); + +$data = "foobar[12][0-9]{2}" . "\n===DONE==="; +$section = new PHPT_Section_EXPECTREGEX($data); +try { + $section->run($case); + trigger_error('exception not caught'); +} catch (PHPT_Case_FailureException $e) { + +} + +$case->output = 'foobar' . rand(100, 200) . "\n===DONE==="; +$section->run($case); + +?> +===DONE=== +--EXPECT-- +===DONE=== + diff --git a/tests/Section/Expectregex/ignore-DONE-keyword.phpt b/tests/Section/Expectregex/ignore-DONE-keyword.phpt index 3ff524f..8117dd8 100644 --- a/tests/Section/Expectregex/ignore-DONE-keyword.phpt +++ b/tests/Section/Expectregex/ignore-DONE-keyword.phpt @@ -8,7 +8,8 @@ require_once dirname(__FILE__) . '/../../_setup.inc'; require_once dirname(__FILE__) . '/../_simple-test-case.inc'; $case = new PHPT_SimpleTestCase(); -$case->output = "foobar" . rand(100, 199); +$case->output = "foobar" . rand(100, 199) . + "\n===DONE==="; $data = <<