Index: coder_review/tests/coder_review_format.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder_review/tests/coder_review_format.test,v retrieving revision 1.1 diff -u -p -r1.1 coder_review_format.test --- coder_review/tests/coder_review_format.test 6 Mar 2009 17:05:41 -0000 1.1 +++ coder_review/tests/coder_review_format.test 31 Jul 2009 02:00:53 -0000 @@ -7,8 +7,58 @@ * residing in scripts/coder_format/tests/. */ +require_once dirname(__FILE__) . '/coder_review_test_case.tinc'; +require_once drupal_get_path('module', 'coder') . '/scripts/coder_format/coder_format.inc'; + /** - * Load coder_format unit tests. + * Coder Format tests. */ -require_once drupal_get_path('module', 'coder') . '/scripts/coder_format/tests/all.test'; +class CoderReviewFormatTest extends CoderReviewTestCase { + function __construct($id = NULL) { + parent::__construct('coder_format', $id); + $this->path = drupal_get_path('module', 'coder') . '/scripts/coder_format/tests'; + } + + public static function getInfo() { + if (file_exists(drupal_get_path('module', 'coder') . '/scripts/coder_format/tests/Text/Diff.php')) { + return array( + 'name' => 'coder_format tests', + 'description' => 'Tests all of the functionality of the coder_format script.', + 'group' => 'Coder', + ); + } + } + + protected function assertFormat($input, $expect) { + $result = coder_format_string_all($input); + $this->assertIdentical($result, $input); + } + + function testCoderFormat() { + if (file_exists($this->path . '/Text/Diff.php')) { + // Load PEAR Text_Diff library. + set_include_path(get_include_path() . PATH_SEPARATOR . $this->path); + include_once $this->path . '/Text/Diff.php'; + include_once $this->path . '/Text/Diff/Renderer.php'; + // Load coder_format test cases. + include_once $this->path . '/CoderTestFile.php'; + } + else { + return; + } + $files = array_keys(file_scan_directory($this->path . '/tests', '/\.phpt$/')); + // Order tests alphabetically, but use a weight > 0 to append them after + // overall test results. + $c = 10; + foreach ($files as $file) { + $case = new CoderFormatTestFile($file); + $this->assertTrue($case->test(), NULL, 'coder_format'); + return; + $result = $case->test(); + if (!$result) { + $this->_reporter->writeContent($case->render(), $c++); + } + } + } +} Index: coder_review/tests/coder_review_test_case.tinc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder_review/tests/coder_review_test_case.tinc,v retrieving revision 1.2 diff -u -p -r1.2 coder_review_test_case.tinc --- coder_review/tests/coder_review_test_case.tinc 6 Mar 2009 19:43:45 -0000 1.2 +++ coder_review/tests/coder_review_test_case.tinc 31 Jul 2009 02:24:56 -0000 @@ -18,7 +18,7 @@ class CoderReviewTestCase extends Drupal // Only do the setUp once per test case, not once per function call. static $run_once; if (!isset($run_once)) { - parent::setUp(); + parent::setUp('coder_review'); $run_once = TRUE; } } Index: scripts/coder_format/tests/CoderTestCase.php =================================================================== RCS file: scripts/coder_format/tests/CoderTestCase.php diff -N scripts/coder_format/tests/CoderTestCase.php --- scripts/coder_format/tests/CoderTestCase.php 24 Feb 2008 19:40:50 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,12 +0,0 @@ -assertIdentical($result, $input); - } -} - Index: scripts/coder_format/tests/CoderTestFile.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/tests/CoderTestFile.php,v retrieving revision 1.2 diff -u -p -r1.2 CoderTestFile.php --- scripts/coder_format/tests/CoderTestFile.php 24 Feb 2008 19:40:50 -0000 1.2 +++ scripts/coder_format/tests/CoderTestFile.php 31 Jul 2009 02:25:30 -0000 @@ -1,24 +1,23 @@ filename = $filename; + } + /** * Loads this class from a file. * * @param string $filename * A filename to load. */ - function load($filename) { - $this->filename = $filename; - $fh = fopen($filename, 'r'); - $state = ''; - $unit = 0; + function load() { + $fh = fopen($this->filename, 'r'); + $state = ''; + $unit = 0; - while (($line = fgets($fh)) !== false) { + while (($line = fgets($fh)) !== FALSE) { // Normalize newlines. $line = rtrim($line, "\n\r"); // Detect INPUT and EXPECT sections. if (substr($line, 0, 2) == '--') { $state = trim($line, ' -'); - + // If a new INPUT section begins, start a new unit. if ($state == 'INPUT') { // If previous section has been marked with the keyword 'ONLY', break @@ -58,7 +69,7 @@ class CoderTestFile extends SimpleExpect continue; } // Process other keywords only outside of INPUT and EXPECT sections. - if (!$state) { + if (empty($state) && is_string($line)) { list($keyword, $line) = explode(': ', $line, 2); } // Assign previous keyword, if there is no new one. @@ -71,7 +82,7 @@ class CoderTestFile extends SimpleExpect break; case 'FULL': - $this->full = (bool)$line; + $this->full = (bool) $line; break; case 'INPUT': @@ -107,15 +118,14 @@ class CoderTestFile extends SimpleExpect } /** - * Implements SimpleExpectation::test(). - * - * @param $filename Filename of test file to test. + * Test a coder_format test file. */ - function test($filename = false) { - if ($filename) { - $this->load($filename); + function test() { + if (empty($this->filename)) { + return FALSE; } - + $this->load(); + // Perform test. // Test passes until proven invalid. $valid = TRUE; @@ -128,7 +138,8 @@ class CoderTestFile extends SimpleExpect $valid = FALSE; } } - + + $this->result = $valid; return $valid; } @@ -136,15 +147,14 @@ class CoderTestFile extends SimpleExpect * Implements SimpleExpectation::testMessage(). */ function testMessage() { - $message = $this->test .' test in '. htmlspecialchars(basename($this->filename)); - return $message; + return $this->test .' test in '. htmlspecialchars(basename($this->filename)); } /** * Renders the test with an HTML diff table. */ function render() { - drupal_add_css(drupal_get_path('module', 'coder') .'/scripts/coder_format/tests/coder-diff.css', 'module', 'all', false); + drupal_add_css(drupal_get_path('module', 'coder') .'/scripts/coder_format/tests/coder-diff.css', array('preprocess' => FALSE)); foreach ($this->input as $unit => $content) { // Do not output passed units. Index: scripts/coder_format/tests/README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/coder/scripts/coder_format/tests/README.txt,v retrieving revision 1.3 diff -u -p -r1.3 README.txt --- scripts/coder_format/tests/README.txt 4 Dec 2008 02:43:34 -0000 1.3 +++ scripts/coder_format/tests/README.txt 30 Jul 2009 22:18:29 -0000 @@ -11,11 +11,7 @@ and a little bit of necessary setup. Her -- REQUIREMENTS -- -* SimpleTest module, along with the patch in - http://drupal.org/node/211823 - -* SimpleTest Framework - https://sourceforge.net/project/showfiles.php?group_id=76550 +* SimpleTest module * Text_Diff package from PEAR http://pear.php.net/package/Text_Diff @@ -23,14 +19,7 @@ and a little bit of necessary setup. Her -- INSTALLATION -- -* If not already done, install SimpleTest module and SimpleTest framework as - usual. - -* Apply above mentioned patch to SimpleTest module. See - http://drupal.org/patch/apply for further information. - - FYI: This patch fixes some incompatibilities with our heavy OOP testing - framework for coder_format. It should not break other tests. +* If not already done, install SimpleTest module as usual. * Download the Text_Diff package from PEAR into this directory, i.e. @@ -44,14 +33,14 @@ and a little bit of necessary setup. Her -- USAGE -- -* Go to admin/build/simpletest, and select Coder Format Tests, and run tests. +* Go to admin/development/testing, and run "Coder Format" tests. -- CUSTOMIZATIONS -- Currently, only the all.test is implemented, which is used to test the overall output of coder_format_string_all(). Appropriate .phpt test -files are located in the sub-directory all/. +files are located in the sub-directory tests/. The internal format for coder_format tests is: @@ -72,6 +61,7 @@ For temporary development work, you can case to make it the test runner only run that one. This is useful for test files that contain multiple tests. + -- CONTACT -- Current maintainers: Index: scripts/coder_format/tests/all.test =================================================================== RCS file: scripts/coder_format/tests/all.test diff -N scripts/coder_format/tests/all.test --- scripts/coder_format/tests/all.test 12 Jun 2009 22:23:42 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,45 +0,0 @@ - 'Full coder_format tests', - 'description' => t('Tests all of the functionality of the coder_format script.'), - 'group' => 'Coder Format Tests', - ); - } - - function test() { - $dir = drupal_get_path('module', 'coder') .'/scripts/coder_format/tests/tests'; - $files = array_keys(file_scan_directory($dir, '\.phpt$')); - // Order tests alphabetically, but use a weight > 0 to append them after - // overall test results. - $c = 10; - foreach ($files as $file) { - $expectation = new CoderReviewTestFile(); - $result = $this->assert($expectation, $file, '%s'); - if (!$result) { - $this->_reporter->writeContent($expectation->render(), $c++); - } - } - } -} - -}