texttest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. require_once 'Tests/TestDriver.php';
  3. require_once 'PHPUnit/Framework.php';
  4. require_once 'Console/Getopt.php';
  5. class TextTestResult extends PHPUnit_Framework_TestResult {
  6. function addError(&$test, &$t, $time=0)
  7. {
  8. parent::addError($test, $t, $time);
  9. echo "E";
  10. }
  11. function addFailure(&$test, &$t, $time=0)
  12. {
  13. parent::addFailure($test, $t, $time);
  14. echo "F";
  15. }
  16. function addPassedTest(&$test)
  17. {
  18. parent::addPassedTest($test);
  19. echo ".";
  20. }
  21. function dumpBadResults()
  22. {
  23. foreach ($this->failures() as $failure) {
  24. echo $failure->toString();
  25. }
  26. foreach ($this->errors() as $failure) {
  27. echo $failure->toString();
  28. }
  29. }
  30. }
  31. function microtime_float()
  32. {
  33. list($usec, $sec) = explode(" ", microtime());
  34. return ((float)$usec + (float)$sec);
  35. }
  36. $longopts = array('no-math',
  37. 'buggy-gmp',
  38. 'no-curl',
  39. 'math-lib=',
  40. 'insecure-rand',
  41. 'thorough',
  42. 'extra-tests=');
  43. $con = new Console_Getopt;
  44. $args = $con->readPHPArgv();
  45. array_shift($args);
  46. $options = $con->getopt2($args, "", $longopts);
  47. if (PEAR::isError($options)) {
  48. print $options->message . "\n";
  49. exit(1);
  50. }
  51. list($flags, $tests_to_run) = $options;
  52. $math_type = array();
  53. $extra_test_modules = array();
  54. $thorough = false;
  55. foreach ($flags as $flag) {
  56. list($option, $value) = $flag;
  57. switch ($option) {
  58. case '--insecure-rand':
  59. define('Auth_OpenID_RAND_SOURCE', null);
  60. break;
  61. case '--no-math':
  62. define('Auth_OpenID_NO_MATH_SUPPORT', true);
  63. break;
  64. case '--buggy-gmp':
  65. define('Auth_OpenID_BUGGY_GMP', true);
  66. break;
  67. case '--no-curl':
  68. define('Auth_Yadis_CURL_OVERRIDE', true);
  69. break;
  70. case '--thorough':
  71. define('Tests_Auth_OpenID_thorough', true);
  72. break;
  73. case '--extra-tests':
  74. $extra_test_modules[] = $value;
  75. break;
  76. default:
  77. print "Unrecognized option: $option\n";
  78. exit(1);
  79. }
  80. }
  81. // ******** Math library selection ***********
  82. // XXX FIXME
  83. // case '--math-lib':
  84. // $math_type[] = $value;
  85. // break;
  86. if ($math_type && false) {
  87. if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
  88. print "--no-math and --math-lib are mutually exclusive\n";
  89. exit(1);
  90. }
  91. require_once('Auth/OpenID/BigMath.php');
  92. $new_extensions = array();
  93. foreach ($math_type as $lib) {
  94. $found = false;
  95. foreach (Auth_OpenID_math_extensions() as $ext) {
  96. if ($ext['extension'] == $lib) {
  97. $new_extensions[] = $ext;
  98. $found = true;
  99. break;
  100. }
  101. }
  102. if (!$found) {
  103. print "Unknown math library specified: $lib\n";
  104. exit(1);
  105. }
  106. }
  107. $_Auth_OpenID_math_extensions = $new_extensions;
  108. }
  109. // ******** End math library selection **********
  110. $suites = loadSuite($tests_to_run);
  111. // ******** Load additional test suites ********
  112. foreach ($extra_test_modules as $filename) {
  113. if (!global_require_once($filename)) {
  114. continue;
  115. }
  116. $module_name = basename($filename, '.php');
  117. $class_name = "Tests_Auth_OpenID_${module_name}_Test";
  118. $suites[] = makeSuite($class_name);
  119. }
  120. $totals = array(
  121. 'run' => 0,
  122. 'error' => 0,
  123. 'failure' => 0,
  124. 'time' => 0
  125. );
  126. foreach ($suites as $suite) {
  127. $name = $suite->getName();
  128. echo "==========================================
  129. Test suite: $name
  130. ------------------------------------------
  131. ";
  132. $result = new TextTestResult();
  133. $before = microtime_float();
  134. $suite->run($result);
  135. $after = microtime_float();
  136. $run = $result->count();
  137. $error = $result->errorCount();
  138. $failure = $result->failureCount();
  139. $delta = $after - $before;
  140. $totals['run'] += $run;
  141. $totals['error'] += $error;
  142. $totals['failure'] += $failure;
  143. $totals['time'] += $delta;
  144. $human_delta = round($delta, 3);
  145. echo "\nRan $run tests in $human_delta seconds";
  146. if ($error || $failure) {
  147. echo " with $error errors, $failure failures";
  148. }
  149. echo "
  150. ==========================================
  151. ";
  152. $failures = $result->failures();
  153. foreach($failures as $failure) {
  154. $test = $failure->failedTest();
  155. $testName = $test->getName();
  156. $exception = $failure->thrownException();
  157. echo "* Failure in $testName: $exception
  158. ";
  159. }
  160. }
  161. $before = microtime_float();
  162. $run = $totals['run'];
  163. $error = $totals['error'];
  164. $failure = $totals['failure'];
  165. $time = round($totals['time'], 3);
  166. echo "Ran a total of $run tests in $time seconds with $error errors, $failure failures\n";
  167. if ($totals['error'] || $totals['failure']) {
  168. exit(1);
  169. }
  170. ?>