diff --git a/setup/cli/package.php b/setup/cli/package.php index 83a63d27dc4fda0cde37f69e566613df224d42d9..f61d9792d934b6585c42438ee531c529bd82efcf 100755 --- a/setup/cli/package.php +++ b/setup/cli/package.php @@ -17,6 +17,10 @@ function get_osticket_root_path() { return realpath($start); } +function run_tests($root) { + return (require "$root/setup/test/run-tests.php"); +} + # Check PHP syntax across all php files function glob_recursive($pattern, $flags = 0) { $files = glob($pattern, $flags); @@ -64,6 +68,10 @@ function package($pattern, $destination, $recurse=false, $exclude=false) { } } +# Run tests before continuing +if (run_tests($root) > 0) + die("Regression tests failed. Cowardly refusing to package\n"); + # Create the stage folder for the install files if (!is_dir($stage_path)) mkdir($stage_path); diff --git a/setup/test/run-tests.php b/setup/test/run-tests.php index 0f42dd7d024f04bf03d87a8b5611a3b658c6953e..3a3df3a1dd09702d7f74bf770b080928dae5bf43 100644 --- a/setup/test/run-tests.php +++ b/setup/test/run-tests.php @@ -4,25 +4,29 @@ if (php_sapi_name() != 'cli') exit(); require_once "tests/class.test.php"; -function get_osticket_root_path() { - # Hop up to the root folder - $start = dirname(__file__); - for (;;) { - if (file_exists($start . '/main.inc.php')) break; - $start .= '/..'; +if (!function_exists('get_osticket_root_path')) { + function get_osticket_root_path() { + # Hop up to the root folder + $start = dirname(__file__); + for (;;) { + if (file_exists($start . '/main.inc.php')) break; + $start .= '/..'; + } + return realpath($start); } - return realpath($start); } $root = get_osticket_root_path(); -# Check PHP syntax across all php files -function glob_recursive($pattern, $flags = 0) { - $files = glob($pattern, $flags); - foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { - $files = array_merge($files, - glob_recursive($dir.'/'.basename($pattern), $flags)); +if (!function_exists('glob_recursive')) { + # Check PHP syntax across all php files + function glob_recursive($pattern, $flags = 0) { + $files = glob($pattern, $flags); + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { + $files = array_merge($files, + glob_recursive($dir.'/'.basename($pattern), $flags)); + } + return $files; } - return $files; } $fails = array(); @@ -37,6 +41,7 @@ function show_fails() { $script = str_replace($root.'/', '', $script); print("$test: $message @ $script:$line\n"); } + return count($fails); } } if (function_exists('pcntl_signal')) { @@ -44,8 +49,7 @@ if (function_exists('pcntl_signal')) { function show_fails_on_ctrlc() { while (@ob_end_flush()); print("\n"); - show_fails(); - exit(); + exit(show_fails()); } pcntl_signal(SIGINT, 'show_fails_on_ctrlc'); } @@ -64,4 +68,10 @@ foreach (glob_recursive(dirname(__file__)."/tests/test.*.php") as $t) { } show_fails(); +// If executed directly expose the fail count to a shell script +global $argv; +if (!strcasecmp(basename($argv[0]), basename(__file__))) + exit(count($fails)); +else + return count($fails); ?> diff --git a/setup/test/tests/class.test.php b/setup/test/tests/class.test.php index 80a07b87b31acf34126712a132139c5c55c2f3ac..5ce1297619714533c19bdfd7f2c083b4b9d255b8 100644 --- a/setup/test/tests/class.test.php +++ b/setup/test/tests/class.test.php @@ -10,6 +10,7 @@ class Test { '/include/PasswordHash.php', '/include/pear/', '/include/Spyc.php', + '/setup/cli/stage/', ); function Test() {