xref: /php-src/sapi/cgi/tests/012.phpt (revision f16b34f1)
1--TEST--
2multiple files syntax check
3--SKIPIF--
4<?php include "skipif.inc"; ?>
5--INI--
6display_errors=stdout
7--FILE--
8<?php
9include "include.inc";
10
11function run_and_output($cmd) {
12    if (!defined("PHP_WINDOWS_VERSION_MAJOR")) {
13        $cmd .= " 2>/dev/null";
14    }
15    exec($cmd, $output, $exit_code);
16    print_r($output);
17    // Normalize Windows vs Linux exit codes. On Windows exit code -1 is actually -1 instead of 255.
18    if ($exit_code < 0) {
19        $exit_code += 256;
20    }
21    var_dump($exit_code);
22}
23
24$php = get_cgi_path();
25reset_env_vars();
26
27$filename_good = __DIR__."/012_good.test.php";
28$filename_good_escaped = escapeshellarg($filename_good);
29$filename_bad = __DIR__."/012_bad.test.php";
30$filename_bad_escaped = escapeshellarg($filename_bad);
31
32$code = '
33<?php
34
35echo "hi";
36';
37
38file_put_contents($filename_good, $code);
39
40$code = '
41<?php
42
43class test
44    private $var;
45}
46
47?>
48';
49
50file_put_contents($filename_bad, $code);
51
52run_and_output("$php -n -l $filename_good_escaped $filename_good_escaped");
53run_and_output("$php -n -l $filename_good_escaped some.unknown $filename_good_escaped");
54run_and_output("$php -n -l $filename_good_escaped $filename_bad_escaped $filename_good_escaped");
55run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped");
56run_and_output("$php -n -l $filename_bad_escaped some.unknown $filename_bad_escaped");
57run_and_output("$php -n -l $filename_bad_escaped $filename_bad_escaped some.unknown");
58
59echo "Done\n";
60?>
61--CLEAN--
62<?php
63@unlink($filename_good);
64@unlink($filename_bad);
65?>
66--EXPECTF--
67Array
68(
69    [0] => No syntax errors detected in %s012_good.test.php
70    [1] => No syntax errors detected in %s012_good.test.php
71)
72int(0)
73Array
74(
75    [0] => No syntax errors detected in %s012_good.test.php
76    [1] => No input file specified.
77)
78int(255)
79Array
80(
81    [0] => No syntax errors detected in %s012_good.test.php
82    [1] => <br />
83    [2] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
84    [3] => Errors parsing %s012_bad.test.php
85    [4] => No syntax errors detected in %s012_good.test.php
86)
87int(255)
88Array
89(
90    [0] => <br />
91    [1] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
92    [2] => Errors parsing %s012_bad.test.php
93    [3] => <br />
94    [4] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
95    [5] => Errors parsing %s012_bad.test.php
96)
97int(255)
98Array
99(
100    [0] => <br />
101    [1] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
102    [2] => Errors parsing %s012_bad.test.php
103    [3] => No input file specified.
104)
105int(255)
106Array
107(
108    [0] => <br />
109    [1] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
110    [2] => Errors parsing %s012_bad.test.php
111    [3] => <br />
112    [4] => <b>Parse error</b>:  syntax error, unexpected token &quot;private&quot;, expecting &quot;{&quot; in <b>%s012_bad.test.php</b> on line <b>5</b><br />
113    [5] => Errors parsing %s012_bad.test.php
114    [6] => No input file specified.
115)
116int(255)
117Done
118