Révision b0dc3a2e
Ajouté par Julien Enselme il y a plus de 7 ans
drupal7/scripts/run-tests.sh | ||
---|---|---|
8 | 8 |
define('SIMPLETEST_SCRIPT_COLOR_FAIL', 31); // Red. |
9 | 9 |
define('SIMPLETEST_SCRIPT_COLOR_EXCEPTION', 33); // Brown. |
10 | 10 |
|
11 |
define('SIMPLETEST_SCRIPT_EXIT_SUCCESS', 0); |
|
12 |
define('SIMPLETEST_SCRIPT_EXIT_FAILURE', 1); |
|
13 |
define('SIMPLETEST_SCRIPT_EXIT_EXCEPTION', 2); |
|
14 |
|
|
11 | 15 |
// Set defaults and get overrides. |
12 | 16 |
list($args, $count) = simpletest_script_parse_args(); |
13 | 17 |
|
14 | 18 |
if ($args['help'] || $count == 0) { |
15 | 19 |
simpletest_script_help(); |
16 |
exit; |
|
20 |
exit(($count == 0) ? SIMPLETEST_SCRIPT_EXIT_FAILURE : SIMPLETEST_SCRIPT_EXIT_SUCCESS);
|
|
17 | 21 |
} |
18 | 22 |
|
19 | 23 |
if ($args['execute-test']) { |
... | ... | |
30 | 34 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
31 | 35 |
if (!module_exists('simpletest')) { |
32 | 36 |
simpletest_script_print_error("The simpletest module must be enabled before this script can run."); |
33 |
exit; |
|
37 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
34 | 38 |
} |
35 | 39 |
|
36 | 40 |
if ($args['clean']) { |
... | ... | |
43 | 47 |
foreach ($messages as $text) { |
44 | 48 |
echo " - " . $text . "\n"; |
45 | 49 |
} |
46 |
exit; |
|
50 |
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
|
|
47 | 51 |
} |
48 | 52 |
|
49 | 53 |
// Load SimpleTest files. |
... | ... | |
64 | 68 |
echo " - " . $info['name'] . ' (' . $class . ')' . "\n"; |
65 | 69 |
} |
66 | 70 |
} |
67 |
exit; |
|
71 |
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
|
|
68 | 72 |
} |
69 | 73 |
|
70 | 74 |
$test_list = simpletest_script_get_test_list(); |
... | ... | |
78 | 82 |
$test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute(); |
79 | 83 |
|
80 | 84 |
// Execute tests. |
81 |
simpletest_script_execute_batch($test_id, simpletest_script_get_test_list()); |
|
85 |
$status = simpletest_script_execute_batch($test_id, simpletest_script_get_test_list());
|
|
82 | 86 |
|
83 | 87 |
// Retrieve the last database prefix used for testing and the last test class |
84 | 88 |
// that was run from. Use the information to read the lgo file in case any |
... | ... | |
100 | 104 |
simpletest_clean_results_table($test_id); |
101 | 105 |
|
102 | 106 |
// Test complete, exit. |
103 |
exit; |
|
107 |
exit($status);
|
|
104 | 108 |
|
105 | 109 |
/** |
106 | 110 |
* Print help text. |
... | ... | |
142 | 146 |
--file Run tests identified by specific file names, instead of group names. |
143 | 147 |
Specify the path and the extension (i.e. 'modules/user/user.test'). |
144 | 148 |
|
149 |
--directory Run all tests found within the specified file directory. |
|
150 |
|
|
145 | 151 |
--xml <path> |
146 | 152 |
|
147 | 153 |
If provided, test results will be written as xml files to this path. |
... | ... | |
190 | 196 |
'all' => FALSE, |
191 | 197 |
'class' => FALSE, |
192 | 198 |
'file' => FALSE, |
199 |
'directory' => '', |
|
193 | 200 |
'color' => FALSE, |
194 | 201 |
'verbose' => FALSE, |
195 | 202 |
'test_names' => array(), |
... | ... | |
222 | 229 |
else { |
223 | 230 |
// Argument not found in list. |
224 | 231 |
simpletest_script_print_error("Unknown argument '$arg'."); |
225 |
exit; |
|
232 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
226 | 233 |
} |
227 | 234 |
} |
228 | 235 |
else { |
... | ... | |
235 | 242 |
// Validate the concurrency argument |
236 | 243 |
if (!is_numeric($args['concurrency']) || $args['concurrency'] <= 0) { |
237 | 244 |
simpletest_script_print_error("--concurrency must be a strictly positive integer."); |
238 |
exit; |
|
245 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
239 | 246 |
} |
240 | 247 |
|
241 | 248 |
return array($args, $count); |
... | ... | |
265 | 272 |
else { |
266 | 273 |
simpletest_script_print_error('Unable to automatically determine the path to the PHP interpreter. Supply the --php command line argument.'); |
267 | 274 |
simpletest_script_help(); |
268 |
exit(); |
|
275 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
269 | 276 |
} |
270 | 277 |
|
271 | 278 |
// Get URL from arguments. |
... | ... | |
310 | 317 |
function simpletest_script_execute_batch($test_id, $test_classes) { |
311 | 318 |
global $args; |
312 | 319 |
|
320 |
$total_status = SIMPLETEST_SCRIPT_EXIT_SUCCESS; |
|
321 |
|
|
313 | 322 |
// Multi-process execution. |
314 | 323 |
$children = array(); |
315 | 324 |
while (!empty($test_classes) || !empty($children)) { |
... | ... | |
325 | 334 |
|
326 | 335 |
if (!is_resource($process)) { |
327 | 336 |
echo "Unable to fork test process. Aborting.\n"; |
328 |
exit; |
|
337 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
329 | 338 |
} |
330 | 339 |
|
331 | 340 |
// Register our new child. |
... | ... | |
345 | 354 |
if (empty($status['running'])) { |
346 | 355 |
// The child exited, unregister it. |
347 | 356 |
proc_close($child['process']); |
348 |
if ($status['exitcode']) { |
|
357 |
if ($status['exitcode'] == SIMPLETEST_SCRIPT_EXIT_FAILURE) { |
|
358 |
if ($status['exitcode'] > $total_status) { |
|
359 |
$total_status = $status['exitcode']; |
|
360 |
} |
|
361 |
} |
|
362 |
elseif ($status['exitcode']) { |
|
363 |
$total_status = $status['exitcode']; |
|
349 | 364 |
echo 'FATAL ' . $test_class . ': test runner returned a non-zero error code (' . $status['exitcode'] . ').' . "\n"; |
350 | 365 |
} |
366 |
|
|
367 |
// Remove this child. |
|
351 | 368 |
unset($children[$cid]); |
352 | 369 |
} |
353 | 370 |
} |
354 | 371 |
} |
372 |
return $total_status; |
|
355 | 373 |
} |
356 | 374 |
|
357 | 375 |
/** |
... | ... | |
374 | 392 |
simpletest_script_print($info['name'] . ' ' . _simpletest_format_summary_line($test->results) . "\n", simpletest_script_color_code($status)); |
375 | 393 |
|
376 | 394 |
// Finished, kill this runner. |
377 |
exit(0); |
|
395 |
if ($had_fails || $had_exceptions) { |
|
396 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE); |
|
397 |
} |
|
398 |
exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); |
|
378 | 399 |
} |
379 | 400 |
catch (Exception $e) { |
380 | 401 |
echo (string) $e; |
381 |
exit(1);
|
|
402 |
exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION);
|
|
382 | 403 |
} |
383 | 404 |
} |
384 | 405 |
|
... | ... | |
432 | 453 |
} |
433 | 454 |
simpletest_script_print_error('Test class not found: ' . $test_class); |
434 | 455 |
simpletest_script_print_alternatives($test_class, $all_classes, 6); |
435 |
exit(1);
|
|
456 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
436 | 457 |
} |
437 | 458 |
} |
438 | 459 |
} |
... | ... | |
451 | 472 |
} |
452 | 473 |
} |
453 | 474 |
} |
475 |
elseif ($args['directory']) { |
|
476 |
// Extract test case class names from specified directory. |
|
477 |
// Find all tests in the PSR-X structure; Drupal\$extension\Tests\*.php |
|
478 |
// Since we do not want to hard-code too many structural file/directory |
|
479 |
// assumptions about PSR-0/4 files and directories, we check for the |
|
480 |
// minimal conditions only; i.e., a '*.php' file that has '/Tests/' in |
|
481 |
// its path. |
|
482 |
// Ignore anything from third party vendors, and ignore template files used in tests. |
|
483 |
// And any api.php files. |
|
484 |
$ignore = array('nomask' => '/vendor|\.tpl\.php|\.api\.php/'); |
|
485 |
$files = array(); |
|
486 |
if ($args['directory'][0] === '/') { |
|
487 |
$directory = $args['directory']; |
|
488 |
} |
|
489 |
else { |
|
490 |
$directory = DRUPAL_ROOT . "/" . $args['directory']; |
|
491 |
} |
|
492 |
$file_list = file_scan_directory($directory, '/\.php|\.test$/', $ignore); |
|
493 |
foreach ($file_list as $file) { |
|
494 |
// '/Tests/' can be contained anywhere in the file's path (there can be |
|
495 |
// sub-directories below /Tests), but must be contained literally. |
|
496 |
// Case-insensitive to match all Simpletest and PHPUnit tests: |
|
497 |
// ./lib/Drupal/foo/Tests/Bar/Baz.php |
|
498 |
// ./foo/src/Tests/Bar/Baz.php |
|
499 |
// ./foo/tests/Drupal/foo/Tests/FooTest.php |
|
500 |
// ./foo/tests/src/FooTest.php |
|
501 |
// $file->filename doesn't give us a directory, so we use $file->uri |
|
502 |
// Strip the drupal root directory and trailing slash off the URI |
|
503 |
$filename = substr($file->uri, strlen(DRUPAL_ROOT)+1); |
|
504 |
if (stripos($filename, '/Tests/')) { |
|
505 |
$files[drupal_realpath($filename)] = 1; |
|
506 |
} else if (stripos($filename, '.test')){ |
|
507 |
$files[drupal_realpath($filename)] = 1; |
|
508 |
} |
|
509 |
} |
|
510 |
|
|
511 |
// Check for valid class names. |
|
512 |
foreach ($all_tests as $class_name) { |
|
513 |
$refclass = new ReflectionClass($class_name); |
|
514 |
$classfile = $refclass->getFileName(); |
|
515 |
if (isset($files[$classfile])) { |
|
516 |
$test_list[] = $class_name; |
|
517 |
} |
|
518 |
} |
|
519 |
} |
|
454 | 520 |
else { |
455 | 521 |
// Check for valid group names and get all valid classes in group. |
456 | 522 |
foreach ($args['test_names'] as $group_name) { |
... | ... | |
460 | 526 |
else { |
461 | 527 |
simpletest_script_print_error('Test group not found: ' . $group_name); |
462 | 528 |
simpletest_script_print_alternatives($group_name, array_keys($groups)); |
463 |
exit(1);
|
|
529 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
464 | 530 |
} |
465 | 531 |
} |
466 | 532 |
} |
... | ... | |
468 | 534 |
|
469 | 535 |
if (empty($test_list)) { |
470 | 536 |
simpletest_script_print_error('No valid tests were specified.'); |
471 |
exit; |
|
537 |
exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
|
|
472 | 538 |
} |
473 | 539 |
return $test_list; |
474 | 540 |
} |
Formats disponibles : Unified diff
Update to Drupal 7.52