mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Testing updates: module testing and collect only (#8063)
* Testing updates module testing and collect only * cache clear no-longer needed.
This commit is contained in:
@@ -7,12 +7,13 @@ chdir($install_dir);
|
||||
|
||||
require $install_dir . '/vendor/autoload.php';
|
||||
|
||||
$short_opts = 'lsufpcho:';
|
||||
$short_opts = 'lsufpcho:m:';
|
||||
$long_opts = array(
|
||||
'lint',
|
||||
'style',
|
||||
'unit',
|
||||
'os:',
|
||||
'module:',
|
||||
'fail-fast',
|
||||
'passthru',
|
||||
'snmpsim',
|
||||
@@ -28,7 +29,8 @@ Running $filename without options runs all checks.
|
||||
-l, --lint Run php lint checks to test for valid syntax
|
||||
-s, --style Run phpcs check to check for PSR-2 compliance
|
||||
-u, --unit Run phpunit tests
|
||||
-o, --os Specific OS to run tests on. Implies --unit
|
||||
-o, --os Specific OS to run tests on. Implies --unit, --db, --snmpsim
|
||||
-m, --module Specific Module to run tests on. Implies --unit, --db, --snmpsim
|
||||
-f, --fail-fast Quit when any failure is encountered
|
||||
-p, --passthru Display output from checks as it comes
|
||||
--db Run unit tests that require a database
|
||||
@@ -56,6 +58,14 @@ if ($os = check_opt($options, 'os', 'o')) {
|
||||
$options['db'] = false;
|
||||
}
|
||||
|
||||
if ($module = check_opt($options, 'm', 'module')) {
|
||||
putenv("TEST_MODULES=$module");
|
||||
// enable unit tests, snmpsim, and db
|
||||
$options['u'] = false;
|
||||
$options['snmpsim'] = false;
|
||||
$options['db'] = false;
|
||||
}
|
||||
|
||||
$all = !check_opt($options, 'l', 'lint', 's', 'style', 'u', 'unit');
|
||||
if ($all) {
|
||||
// no test specified, run all tests in this order
|
||||
@@ -78,7 +88,7 @@ foreach (array_keys($options) as $opt) {
|
||||
} elseif ($opt == 's' || $opt == 'style') {
|
||||
$ret = run_check('style', $passthru, $command_only);
|
||||
} elseif ($opt == 'u' || $opt == 'unit') {
|
||||
$ret = run_check('unit', $passthru, $command_only, $fail_fast, $os);
|
||||
$ret = run_check('unit', $passthru, $command_only, compact('fail_fast', 'os', 'module'));
|
||||
}
|
||||
|
||||
if ($fail_fast && $ret !== 0 && $ret !== 250) {
|
||||
@@ -102,11 +112,10 @@ exit($return); //return the combined/single return value of tests
|
||||
* @param string $type type of check lint, style, or unit
|
||||
* @param bool $passthru display the output as comes in
|
||||
* @param bool $command_only only display the intended command, no checks
|
||||
* @param bool $fail_fast Quit as soon as possible if error or failure
|
||||
* @param string $os Only check a specific OS
|
||||
* @param array $options command specific options
|
||||
* @return int the return value from the check (0 = success)
|
||||
*/
|
||||
function run_check($type, $passthru, $command_only, $fail_fast = false, $os = null)
|
||||
function run_check($type, $passthru, $command_only, $options = array())
|
||||
{
|
||||
global $completed_tests;
|
||||
if (getenv('SKIP_' . strtoupper($type) . '_CHECK') || $completed_tests[$type]) {
|
||||
@@ -117,7 +126,7 @@ function run_check($type, $passthru, $command_only, $fail_fast = false, $os = nu
|
||||
$function = 'check_' . $type;
|
||||
if (function_exists($function)) {
|
||||
$completed_tests[$type] = true;
|
||||
return $function($passthru, $command_only, $fail_fast, $os);
|
||||
return $function($passthru, $command_only, $options);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -217,22 +226,25 @@ function check_style($passthru = false, $command_only = false)
|
||||
*
|
||||
* @param bool $passthru display the output as comes in
|
||||
* @param bool $command_only only display the intended command, no checks
|
||||
* @param bool $fail_fast Stop when any error or failure is encountered
|
||||
* @param string $os only check a specific OS
|
||||
* @param array $options Supported: fail_fast, os, module
|
||||
* @return int the return value from phpunit (0 = success)
|
||||
*/
|
||||
function check_unit($passthru = false, $command_only = false, $fail_fast = false, $os = null)
|
||||
function check_unit($passthru = false, $command_only = false, $options = array())
|
||||
{
|
||||
$phpunit_bin = check_exec('phpunit');
|
||||
|
||||
$phpunit_cmd = "$phpunit_bin --colors=always";
|
||||
|
||||
if ($fail_fast) {
|
||||
if ($options['fail_fast']) {
|
||||
$phpunit_cmd .= ' --stop-on-error --stop-on-failure';
|
||||
}
|
||||
|
||||
if (!is_null($os)) {
|
||||
$phpunit_cmd .= " --group os --filter \"@$os.*\"";
|
||||
if ($options['os']) {
|
||||
$phpunit_cmd .= " --group os --filter \"@{$options['os']}.*\"";
|
||||
}
|
||||
|
||||
if ($options['module']) {
|
||||
$phpunit_cmd .= ' tests/OSModulesTest.php';
|
||||
}
|
||||
|
||||
if ($command_only) {
|
||||
|
Reference in New Issue
Block a user