DIR : /home/kozerus/public_html/go/dgs/scripts/tests/DgsUnitTestRunner.php
/home/kozerus/public_html/go/dgs/scripts/tests
<?php
/*
Dragon Go Server
Copyright (C) 2001- Jens-Uwe Gaspar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'include/connect2mysql.php';
/*!
* \brief Test runner to run all DgsUnitTest tests in current directory.
*
* Conventions:
* - Test classes must extend from class DgsUnitTest, e.g. 'class MyClassTest extends DgsUnitTest'
* - Test methods must be public functions
* - Test method names must contain 'test_', e.g. 'my_test_bla', 'test_blub'
* - Test class files must end on 'Test.php', e.g. 'MyClassTest.php'
* - a test class can define a function 'setUp()' which will be executed before each test method
* - use $this->assert... functions (see DgsUnitTest-class) for testing expected values
*
* "php DgsUnitTestRunner.php" runs tests from all test classes
* in current directory extending from DgsUnitTest with file-name of "*Test.php".
*
* "php DgsUnitTestRunner.php BitSetTest" runs tests from given test class only,
* which must inherit from DgsUnitTest.
*
* Success and errors are printed to STDOUT.
* PHP runtime errors during the test run are collected in a file (see $FILE_ERRORS)
* and printed at the end.
*/
class DgsUnitTestRunner
{
private static $FILE_ERRORS = "./dgs-unit-tests-errors.txt";
// $args: [classname]
public static function runSuite( $args )
{
static::init_php();
$arr_tests = (count($args) > 0) ? array( $args[0] ) : static::find_test_class();
global $TheErrors;
$TheErrors->set_mode(ERROR_MODE_TEST);
connect2mysql();
$count_all_tests = 0;
$count_all_ok = 0;
$count_class_tests = 0;
$count_class_ok = 0;
printf("\nCheck error log file [%s], if something looks fishy (e.g. no summary printed).\n",
static::$FILE_ERRORS);
foreach ( $arr_tests as $test_class_name ) {
require_once "$test_class_name.php";
$test_class = new $test_class_name();
list( $tc_success, $tc_ok, $tc_all ) = $test_class->runTests();
if ( $tc_success )
$count_class_ok++;
$count_class_tests++;
$count_all_ok += $tc_ok;
$count_all_tests += $tc_all;
}
$test_pass = ($count_class_ok == $count_class_tests) ? 'PASS' : 'FAIL';
echo "\n#================================================================================\n";
printf("Contents of error log file [%s]:\n\n", static::$FILE_ERRORS);
echo file_get_contents(static::$FILE_ERRORS), "\n";
printf("[ALL] %s/%s test classes ok, %s/%s tests ok -> %s\n",
$count_class_ok, $count_class_tests, $count_all_ok, $count_all_tests, $test_pass);
echo "\n";
}//runSuite
private static function init_php() {
if ( file_exists(static::$FILE_ERRORS) )
unlink(static::$FILE_ERRORS);
ini_set('error_log', static::$FILE_ERRORS);
ini_set('display_errors', 'off');
}
private static function find_test_class() {
$arr_test_classes = array();
$grep_result = shell_exec("grep -h ^class *Test.php");
if ( is_null($grep_result) ) {
echo "\nERROR: no DgsUnitTest test classes found!\n";
} else {
$lines = explode("\n", $grep_result);
foreach ( $lines as $line ) {
if ( preg_match("/^class\s+(\S+).*?extends\s+.*?\\bDgsUnitTest\\b/", $line, $matches) )
array_push( $arr_test_classes, $matches[1] );
}
}
return $arr_test_classes;
}//find_test_class
}//end of 'DgsUnitTestRunner'
DgsUnitTestRunner::runSuite( array_slice($argv, 1) );
?>
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer