root/test_suite/trunk/import-php-tests

Revision 186, 3.2 kB (checked in by bart, 3 years ago)

Import of first version of the test suite. Only scripts are available,
no docs and the tests can be obtained here: http://bart.eaccelerator.net/tests

  • Property svn:executable set to *
Line 
1 #!/usr/bin/php
2 <?php
3 /*
4  * Script to import the php phpt test files
5  */
6
7 /** parse the commandline options **/
8 if ($_SERVER['argc'] > 1) {
9     $arguments = $_SERVER['argv'];
10     unset($arguments[0]);
11     // arg 0 is the script name
12     foreach ($arguments as $arg) {
13         if (strlen($arg) > 2 && $arg{0} == '-' && $arg{1} == '-') {
14             if (strstr($arg, '=')) {
15                 $arr = explode('=', $arg);
16                 $options[substr($arr[0], 2)] = $arr[1];
17             } else {
18                 $options[substr($arg, 2)] = true;
19             }
20         }
21     }
22 }
23
24 /** --help */
25 if (isset($options['help'])) {
26     show_help();
27 }
28
29 /** check the options */
30 if (isset($options['zend-tests'])) {
31     $test_dir = $options['zend-tests'];
32 } else {
33     show_help();
34 }
35
36 if (isset($options['dest'])) {
37     $destination = $options['dest'];
38 } else {
39     show_help();
40 }
41
42 /* check source dir */
43 if (!is_dir($test_dir)) {
44     die("$test_dir isn't a directory!");
45 }
46
47 /* check dest dir */
48 if (!is_dir($destination)) {
49     die("$destination isn't a directory!");
50 }
51
52 if (!is_writable($destination)) {
53     die("$destination isn't writable");
54 }
55
56 $odir = opendir($test_dir);
57 while ($file = readdir($odir)) {
58     if (is_file ("$test_dir/$file")) {
59         $info = pathinfo("$test_dir/$file");
60         if ($info['extension'] == 'phpt') {
61             addTest($test_dir, $file);
62         }
63     }
64 }
65 closedir($odir);
66
67 /*
68  * write a test
69  */
70 function addTest ($dir, $file) {
71     global $db, $destination;
72
73     $test = parse_test("$dir/$file");
74
75     /* write the files */
76     $file = basename($file);
77     $test['FILE'] = "! eAccelerator test\n" . $test['FILE'];
78     file_put_contents("$destination/$file.txt", $test['FILE']);
79 }
80
81 /**
82  * Parse test file in it's different parts
83  */
84 function parse_test($file) {
85     // Load the sections of the test file.
86     $section_text = array(
87             'TEST'   => '',
88             'SKIPIF' => '',
89             'GET'    => '',
90             'ARGS'   => '',
91             );
92
93     $fp = @fopen($file, "r") or die("Cannot open test file: $file\n");
94
95     if (!feof($fp)) {
96         $line = fgets($fp);
97     } else {
98         echo "BORK empty test [$file]\n";
99         return 'BORKED';
100     }
101     if (!ereg('^--TEST--',$line,$r)) {
102         echo "BORK tests must start with --TEST-- [$file]\n";
103         return 'BORKED';
104     }
105     $section = 'TEST';
106     while (!feof($fp)) {
107         $line = fgets($fp);
108
109         // Match the beginning of a section.
110         if (ereg('^--([A-Z]+)--',$line,$r)) {
111             $section = $r[1];
112             $section_text[$section] = '';
113             continue;
114         }
115
116         // Add to the section text.
117         $section_text[$section] .= $line;
118     }
119     if (@count($section_text['FILE']) != 1) {
120         echo "BORK missing section --FILE-- [$file]\n";
121         return 'BORKED';
122     }
123     if ((@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX'])) != 1) {
124         echo "BORK missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX-- [$file]\n";
125         return 'BORKED';
126     }
127     fclose($fp);
128
129     return $section_text;
130 }
131
132 function show_help() {
133     die("Usage: import-php-tests --zend-tests=zend-test-dir --dest=dir \n" .
134         "\tImport php tests.\n");
135 }
136
137 ?>
138
Note: See TracBrowser for help on using the browser.