xref: /PHP-7.3/sapi/cli/tests/016.phpt (revision 782352c5)
1--TEST--
2CLI -a and readline
3--SKIPIF--
4<?php
5include "skipif.inc";
6if (!extension_loaded('readline') || readline_info('done') === NULL) {
7	die ("skip need readline support");
8}
9?>
10--FILE--
11<?php
12$php = getenv('TEST_PHP_EXECUTABLE');
13
14// disallow console escape sequences that may break the output
15putenv('TERM=VT100');
16
17$codes = array();
18
19$codes[1] = <<<EOT
20echo 'Hello world';
21exit
22EOT;
23
24$codes[] = <<<EOT
25echo 'multine
26single
27quote';
28exit
29EOT;
30
31$codes[] = <<<EOT
32echo <<<HEREDOC
33Here
34comes
35the
36doc
37HEREDOC;
38EOT;
39
40$codes[] = <<<EOT
41if (0) {
42    echo "I'm not there";
43}
44echo "Done";
45EOT;
46
47$codes[] = <<<EOT
48function a_function_with_some_name() {
49    echo "I was called!";
50}
51a_function_w	);
52EOT;
53
54foreach ($codes as $key => $code) {
55	echo "\n--------------\nSnippet no. $key:\n--------------\n";
56	$code = escapeshellarg($code);
57	echo `echo $code | "$php" -a`, "\n";
58}
59
60echo "\nDone\n";
61?>
62--EXPECT--
63--------------
64Snippet no. 1:
65--------------
66Interactive shell
67
68php > echo 'Hello world';
69Hello world
70php > exit
71
72
73--------------
74Snippet no. 2:
75--------------
76Interactive shell
77
78php > echo 'multine
79php ' single
80php ' quote';
81multine
82single
83quote
84php > exit
85
86
87--------------
88Snippet no. 3:
89--------------
90Interactive shell
91
92php > echo <<<HEREDOC
93<<< > Here
94<<< > comes
95<<< > the
96<<< > doc
97<<< > HEREDOC;
98Here
99comes
100the
101doc
102php >
103
104--------------
105Snippet no. 4:
106--------------
107Interactive shell
108
109php > if (0) {
110php {     echo "I'm not there";
111php { }
112php > echo "Done";
113Done
114php >
115
116--------------
117Snippet no. 5:
118--------------
119Interactive shell
120
121php > function a_function_with_some_name() {
122php {     echo "I was called!";
123php { }
124php > a_function_with_some_name();
125I was called!
126php >
127
128Done
129