Skip to content

Commit ec1e854

Browse files
committed
Slightly deduplicate run-tests code
1 parent c2068e9 commit ec1e854

File tree

1 file changed

+54
-66
lines changed

1 file changed

+54
-66
lines changed

run-tests.php

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,11 @@ function main()
678678
// Run selected tests.
679679
$test_cnt = count($test_files);
680680

681+
verify_config();
682+
write_information();
683+
681684
if ($test_cnt) {
682685
putenv('NO_INTERACTION=1');
683-
verify_config();
684-
write_information();
685686
usort($test_files, "test_sort");
686687
$start_time = time();
687688

@@ -721,91 +722,78 @@ function main()
721722
if ($output_file != '' && $just_save_results) {
722723
save_or_mail_results();
723724
}
724-
725-
junit_save_xml();
726-
727-
if (getenv('REPORT_EXIT_STATUS') !== '0' &&
728-
getenv('REPORT_EXIT_STATUS') !== 'no' && ($sum_results['FAILED'] || $sum_results['BORKED'] || $sum_results['LEAKED'])) {
729-
exit(1);
725+
} else {
726+
// Compile a list of all test files (*.phpt).
727+
$test_files = array();
728+
$exts_tested = count($exts_to_test);
729+
$exts_skipped = 0;
730+
$ignored_by_ext = 0;
731+
sort($exts_to_test);
732+
$test_dirs = array();
733+
$optionals = array('Zend', 'tests', 'ext', 'sapi');
734+
735+
foreach ($optionals as $dir) {
736+
if (is_dir($dir)) {
737+
$test_dirs[] = $dir;
738+
}
730739
}
731740

732-
return;
733-
}
734-
735-
verify_config();
736-
write_information();
737-
738-
// Compile a list of all test files (*.phpt).
739-
$test_files = array();
740-
$exts_tested = count($exts_to_test);
741-
$exts_skipped = 0;
742-
$ignored_by_ext = 0;
743-
sort($exts_to_test);
744-
$test_dirs = array();
745-
$optionals = array('Zend', 'tests', 'ext', 'sapi');
746-
747-
foreach ($optionals as $dir) {
748-
if (is_dir($dir)) {
749-
$test_dirs[] = $dir;
741+
// Convert extension names to lowercase
742+
foreach ($exts_to_test as $key => $val) {
743+
$exts_to_test[$key] = strtolower($val);
750744
}
751-
}
752745

753-
// Convert extension names to lowercase
754-
foreach ($exts_to_test as $key => $val) {
755-
$exts_to_test[$key] = strtolower($val);
756-
}
746+
foreach ($test_dirs as $dir) {
747+
find_files(TEST_PHP_SRCDIR . "/{$dir}", $dir == 'ext');
748+
}
757749

758-
foreach ($test_dirs as $dir) {
759-
find_files(TEST_PHP_SRCDIR . "/{$dir}", $dir == 'ext');
760-
}
750+
foreach ($user_tests as $dir) {
751+
find_files($dir, $dir == 'ext');
752+
}
761753

762-
foreach ($user_tests as $dir) {
763-
find_files($dir, $dir == 'ext');
764-
}
754+
$test_files = array_unique($test_files);
755+
usort($test_files, "test_sort");
765756

766-
$test_files = array_unique($test_files);
767-
usort($test_files, "test_sort");
757+
$start_time = time();
758+
show_start($start_time);
768759

769-
$start_time = time();
770-
show_start($start_time);
760+
$test_cnt = count($test_files);
761+
$test_idx = 0;
762+
run_all_tests($test_files, $environment);
763+
$end_time = time();
771764

772-
$test_cnt = count($test_files);
773-
$test_idx = 0;
774-
run_all_tests($test_files, $environment);
775-
$end_time = time();
765+
if ($failed_tests_file) {
766+
fclose($failed_tests_file);
767+
}
776768

777-
if ($failed_tests_file) {
778-
fclose($failed_tests_file);
779-
}
769+
if ($result_tests_file) {
770+
fclose($result_tests_file);
771+
}
780772

781-
if ($result_tests_file) {
782-
fclose($result_tests_file);
783-
}
773+
// Summarize results
784774

785-
// Summarize results
775+
if (0 == count($test_results)) {
776+
echo "No tests were run.\n";
777+
return;
778+
}
786779

787-
if (0 == count($test_results)) {
788-
echo "No tests were run.\n";
789-
return;
790-
}
780+
compute_summary();
791781

792-
compute_summary();
782+
show_end($end_time);
783+
show_summary();
793784

794-
show_end($end_time);
795-
show_summary();
785+
if ($html_output) {
786+
fclose($html_file);
787+
}
796788

797-
if ($html_output) {
798-
fclose($html_file);
789+
save_or_mail_results();
799790
}
800791

801-
save_or_mail_results();
802-
803792
junit_save_xml();
804-
if (getenv('REPORT_EXIT_STATUS') !== '0' &&
805-
getenv('REPORT_EXIT_STATUS') !== 'no' && ($sum_results['FAILED'] || $sum_results['LEAKED'])) {
793+
if (getenv('REPORT_EXIT_STATUS') !== '0' && getenv('REPORT_EXIT_STATUS') !== 'no' &&
794+
($sum_results['FAILED'] || $sum_results['LEAKED'])) {
806795
exit(1);
807796
}
808-
exit(0);
809797
}
810798

811799
if (!function_exists("hrtime")) {

0 commit comments

Comments
 (0)