OSDN Git Service

- moved ETHNA_UTF8_BRANCH to trunk.
[ethna/ethna.git] / bin / ethna_run_test.php
1 <?php
2 /**
3  *  ethna_run_test.php
4  *
5  *  Ethna Test Runner
6  *
7  *  @author     Kazuhiro Hosoi <hosoi@gree.co.jp>
8  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
9  *  @package    Ethna
10  *  @version    $Id$
11  */
12
13 /** アプリケーションベースディレクトリ */
14 define('BASE', dirname(dirname(__FILE__)));
15
16 /** include_pathの設定(このtest runnerがあるディレクトリを追加) */
17 ini_set('include_path', dirname(BASE) . PATH_SEPARATOR . ini_get('include_path'));
18
19 /** Ethna関連クラスのインクルード */
20 require_once 'Ethna/Ethna.php';
21
22 /** SimpleTestのインクルード */
23 require_once 'simpletest/unit_tester.php';
24 require_once 'simpletest/reporter.php';
25 require_once 'Ethna/test/TextDetailReporter.php';
26 require_once 'Ethna/test/Ethna_UnitTestBase.php';
27
28 /** テストケースがあるディレクトリ */
29 $test_dir = ETHNA_BASE . '/test';
30
31 $test = &new GroupTest('Ethna All tests');
32
33 // テストケースのファイルリストを取得
34 require_once 'Console/Getopt.php';
35 $args = Console_Getopt::readPHPArgv();
36 list($args, $opts) = Console_Getopt::getopt2($args, '', array());
37 array_shift($opts);
38 if (count($opts) > 0) {
39     $file_list = $opts;
40 } else {
41     $file_list = getFileList($test_dir);
42 }
43
44 // テストケースを登録
45 foreach ($file_list as $file) {
46     $test->addTestFile($file);
47 }
48
49 // 結果をコマンドラインに出力
50 //$test->run(new TextReporter());
51 $test->run(new TextDetailReporter());
52
53 //{{{ getFileList
54 /**
55  * getFileList
56  *
57  * @param string $dir_path
58  */
59 function getFileList($dir_path)
60 {
61     $file_list = array();
62
63     $dir = opendir($dir_path);
64
65     if ($dir == false) {
66         return false;
67     }
68
69     while($file_path = readdir($dir)) {
70
71         $full_path = $dir_path . '/'. $file_path;
72
73         if (is_file($full_path)){
74
75             // テストケースのファイルのみ読み込む
76             if (preg_match('/^(Ethna_)(.*)(_Test.php)$/',$file_path,$matches)) {
77                 $file_list[] = $full_path;
78             }
79
80         // サブディレクトリがある場合は,再帰的に読み込む.
81         // "."で始まるディレクトリは読み込まない.
82         } else if (is_dir($full_path) && !preg_match('/^\./',$file_path,$matches)) {
83
84             $file_list = array_merge($file_list,getFileList($full_path));
85         }
86     }
87
88     closedir($dir);
89     return $file_list;
90 }
91 //}}}
92 ?>