From ee3f2ca9d3541b8a0b44308076186eee2c0b5602 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 16 May 2014 18:55:52 +0200 Subject: [PATCH] Added help to test runner --- tests/SzurubooruTestOptions.php | 1 + tests/SzurubooruTestRunner.php | 15 ++++++++++++++- tests/help.txt | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/help.txt diff --git a/tests/SzurubooruTestOptions.php b/tests/SzurubooruTestOptions.php index 889b313c..38a96e11 100644 --- a/tests/SzurubooruTestOptions.php +++ b/tests/SzurubooruTestOptions.php @@ -4,4 +4,5 @@ class SzurubooruTestOptions public $cleanDatabase; public $filter; public $dbDriver; + public $help; } diff --git a/tests/SzurubooruTestRunner.php b/tests/SzurubooruTestRunner.php index c379b0e8..0a787a31 100644 --- a/tests/SzurubooruTestRunner.php +++ b/tests/SzurubooruTestRunner.php @@ -5,6 +5,12 @@ class SzurubooruTestRunner implements ITestRunner { $options = $this->getOptions(); + if ($options->help) + { + $this->printHelp(); + exit(0); + } + $this->resetEnvironment($options); if ($options->cleanDatabase) $this->cleanDatabase(); @@ -36,12 +42,19 @@ class SzurubooruTestRunner implements ITestRunner $testRunner->run(); } + private function printHelp() + { + readfile(__DIR__ . DIRECTORY_SEPARATOR . 'help.txt'); + } + private function getOptions() { - $options = getopt('cf:', ['clean', 'filter:', 'driver:']); + $options = getopt('cf:h', ['clean', 'filter:', 'driver:', 'help']); $ret = new SzurubooruTestOptions; + $ret->help = (isset($options['h']) or isset($options['h'])); + $ret->cleanDatabase = (isset($options['c']) or isset($options['clean'])); $ret->dbDriver = 'sqlite'; diff --git a/tests/help.txt b/tests/help.txt new file mode 100644 index 00000000..540664b3 --- /dev/null +++ b/tests/help.txt @@ -0,0 +1,18 @@ +Usage: php run-all.php [OPTIONS] + +Available options: + +-c, --clean Clears the database. Used for upgrade testing. +-d, --driver DRIVER Sets database driver to DRIVER, where DRIVER can be + sqlite or mysql. +-f, --filter FILTER Runs only tests matching given FILTER. +-h, --help Shows this help. + +Syntax of FILTER: + +CLASS runs only tests from classes containing CLASS. +CLASS:: same as above. +::METHOD runs only tests from methods containing METHOD. +CLASS::METHOD combination of CLASS and ::METHOD filters. + +Filters are case-insensitive.