OSDN Git Service

Merge branch 'feature/php5.3-compatible' into develop
[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 /** Ethnaインストールルートディレクトリ */
14 define('ETHNA_INSTALL_BASE', dirname(dirname(__FILE__)));
15
16 $symlink_filename = null;
17
18 /** シンボリックリンクをインストールディレクトリの親に張る */
19 /** symlink 関数は 5.3.0 以前では Windows 上で動作しない   */
20 /** が、Cygwinでテストするため問題はない。                 */
21 if (basename(ETHNA_INSTALL_BASE) != 'Ethna') {
22     $symlink_filename = dirname(ETHNA_INSTALL_BASE) . "/Ethna";
23     if (!file_exists($symlink_filename)) {
24         symlink(ETHNA_INSTALL_BASE, $symlink_filename);
25     } else {
26         if (!is_link($symlink_filename)
27             || realpath($symlink_filename) != ETHNA_INSTALL_BASE) {
28             echo "Base dir 'Ethna' exists and it's not ETHNA_INSTALL_BASE.\n";
29             exit(1);
30         }
31         else {
32             // もとから存在した symlink は削除しない
33             $symlink_filename = null;
34         }
35     }
36 }
37
38 /** テストケースがあるディレクトリ */
39 $test_dir = ETHNA_INSTALL_BASE . '/test';
40
41 /** include_pathの設定(このtest runnerがあるディレクトリを追加) */
42 //ini_set('include_path', realpath(ETHNA_INSTALL_BASE . '/class') . PATH_SEPARATOR . ini_get('include_path'));
43 ini_set('include_path', realpath(dirname(ETHNA_INSTALL_BASE)) . PATH_SEPARATOR . ini_get('include_path'));
44
45 /** Ethna関連クラスのインクルード */
46 require_once 'Ethna/Ethna.php';
47
48 /** SimpleTestのインクルード */
49 require_once 'simpletest/unit_tester.php';
50 require_once 'simpletest/reporter.php';
51 require_once $test_dir . '/TextDetailReporter.php';
52 require_once $test_dir . '/Ethna_UnitTestBase.php';
53
54 $test = new GroupTest('Ethna All tests');
55
56 // テストケースのファイルリストを取得
57 require_once 'Ethna/class/Ethna_Getopt.php';
58 $opt = new Ethna_Getopt();
59 $args = $opt->readPHPArgv();
60 list($args, $opts) = $opt->getopt($args, '', array());
61 array_shift($opts);
62 if (count($opts) > 0) {
63     $file_list = $opts;
64 } else {
65     $file_list = getFileList($test_dir);
66 }
67
68 // テストケースを登録
69 foreach ($file_list as $file) {
70     $test->addTestFile($file);
71 }
72
73 // 結果をコマンドラインに出力
74 $test->run(new TextDetailReporter());
75
76 if ($symlink_filename !== null && is_link($symlink_filename)) {
77     unlink($symlink_filename);
78 }
79
80 //{{{ getFileList
81 /**
82  * getFileList
83  *
84  * @param string $dir_path
85  */
86 function getFileList($dir_path)
87 {
88     $file_list = array();
89
90     $dir = opendir($dir_path);
91
92     if ($dir == false) {
93         return false;
94     }
95
96     while($file_path = readdir($dir)) {
97
98         $full_path = $dir_path . '/'. $file_path;
99
100         if (is_file($full_path)){
101
102             // テストケースのファイルのみ読み込む
103             if (preg_match('/^(Ethna_)(.*)(_Test.php)$/',$file_path,$matches)) {
104                 $file_list[] = $full_path;
105             }
106
107         // サブディレクトリがある場合は,再帰的に読み込む.
108         // "."で始まるディレクトリは読み込まない.
109         } else if (is_dir($full_path) && !preg_match('/^\./',$file_path,$matches)) {
110
111             $file_list = array_merge($file_list,getFileList($full_path));
112         }
113     }
114
115     closedir($dir);
116     return $file_list;
117 }
118 //}}}
119