Skip to content

Commit

Permalink
Add old bcompiler test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nanosonde committed May 17, 2018
1 parent 21b56af commit d57f933
Show file tree
Hide file tree
Showing 43 changed files with 1,581 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/a10-include.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test include() with PHP code
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_phpcode($dir.'a10-include.phpt', $dir.'a10-include.phb');
?>
--FILE--
<?php
include("a10-include.phb");
unlink(dirname(__FILE__).'/a10-include.phb');
exit;
//--CODE--
echo "ok\n";
?>
--EXPECT--
ok
16 changes: 16 additions & 0 deletions tests/a11-include_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test include() with empty file
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
touch($dir.'a11-include.phb');
?>
--FILE--
<?php
include("a11-include.phb");
unlink(dirname(__FILE__).'/a11-include.phb');
exit;
//--CODE--
?>
--EXPECT--
18 changes: 18 additions & 0 deletions tests/a12-include_bc.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test include() with simple bytecode
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a12-include_bc.phpt', $dir.'a12-include_bc.phb');
?>
--FILE--
<?php
include("a12-include_bc.phb");
unlink(dirname(__FILE__).'/a12-include_bc.phb');
exit;
//--CODE--
echo "ok\n";
?>
--EXPECT--
ok
26 changes: 26 additions & 0 deletions tests/a15-included_files.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test get_included_files()
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a15-included_files.phpt', $dir.'a15-included_files.phb');
?>
--FILE--
<?php
$i = 0;
include("a15-included_files.phb");
print_r( get_included_files() );
include_once("a15-included_files.phb");
unlink(dirname(__FILE__).'/a15-included_files.phb');
exit;
//--CODE--
echo $i++ ? "error\n" : " ok\n";
?>
--EXPECTREGEX--
ok
Array
\(
\[0\] => \S+a15-included_files\.php
\[1\] => \S+a15-included_files\.phb
\)
22 changes: 22 additions & 0 deletions tests/a20-basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test basic syntax
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a20-basic.phpt', $dir.'a20-basic.phb');
?>
--FILE--
<?php
include("a20-basic.phb");
unlink(dirname(__FILE__).'/a20-basic.phb');
exit;
//--CODE--
echo "test line 1\n";
echo "test line".' ', 4 / 2, "\n";
?>
test line 3
--EXPECT--
test line 1
test line 2
test line 3
32 changes: 32 additions & 0 deletions tests/a21-const.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Test constants
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a21-const.phpt', $dir.'a21-const.phb');
?>
--FILE--
<?php
include("a21-const.phb");
unlink(dirname(__FILE__).'/a21-const.phb');
exit;
//--CODE--
define("AAA", '1');
define("BBB", '222', 1);
define("PI", 3.1415926);
define("True", True);
error_reporting(E_ALL & !E_NOTICE);
echo AAA, "\n", aaa, "\n", BBB, "\n", bbb."\n";
echo "Pi=".PI, "\n";
var_dump(True);
echo __LINE__, "\n";
?>
--EXPECT--
1
aaa
222
222
Pi=3.1415926
bool(true)
10
47 changes: 47 additions & 0 deletions tests/a22-vars.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
Test variables
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a22-vars.phpt', $dir.'a22-vars.phb');
?>
--FILE--
<?php
include("a22-vars.phb");
unlink(dirname(__FILE__).'/a22-vars.phb');
exit;
//--CODE--
$a = 2;
$b = $a * $a;
$c = ++$a;
$d = $c * $a / 5;
$s = "A string\n2nd line";
$arr = array($a, $b, $d);
$x = 'c';
$$x *= 10;
var_dump($c);
var_dump($d);
echo "$s\n";
var_dump($arr);
$arr2[ $s{0} ] = &$a;
$a = ($c % 10) ? "yes" : "no";
echo $arr2['A'], "\n";
$z = "_SELF";
echo $_SERVER["PHP{$z}"], "\n";
?>
--EXPECTREGEX--
int\(30\)
float\(1\.8\)
A string
2nd line
array\(3\) \{
\[0\]=>
int\(3\)
\[1\]=>
int\(4\)
\[2\]=>
float\(1\.8\)
\}
no
.*a22-vars\.php$
48 changes: 48 additions & 0 deletions tests/a23-func.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Test functions
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a23-func.phpt', $dir.'a23-func.phb');
?>
--FILE--
<?php
include("a23-func.phb");
unlink(dirname(__FILE__).'/a23-func.phb');
exit;
--CODE--
function Add($a, $b) {
function Div($x, $y = 100) { return $x / $y; }

return $a + Div($b);
}

function uc(&$string) {
ucfirst($string);
return array(7, 8, 1000);
}

function max2() {
$m = NULL;
for ($i = 0; $i < func_num_args(); $i++) {
$v = func_get_arg($i);
if (is_array($v)) $v = call_user_func_array(__FUNCTION__, $v);
if ($v > $m) $m = $v;
}
return $m;
}

var_dump( Add(2, 78) );
$s = "hello world\n";
$arr = uc($s);
echo $s;
$f = "max2";
echo $f(2, 7, $s, False, $arr, "56", ord('z')-1), "\n";
var_dump( max2() );
?>
--EXPECT--
float(2.78)
hello world
1000
NULL
29 changes: 29 additions & 0 deletions tests/a25-goto.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Test goto
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.3', '<')) die("skip PHP 5.3 or later is required");
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a25-goto.phpt', $dir.'a25-goto.phb');
?>
--FILE--
<?php
include("a25-goto.phb");
unlink(dirname(__FILE__).'/a25-goto.phb');
exit;
//--CODE--
for ($i = 0; $i < 10; $i++) {
echo "$i\n";
if ($i == 3) goto Label;
}

Label:
echo ".\n";
?>
--EXPECT--
0
1
2
3
.
32 changes: 32 additions & 0 deletions tests/a26-brk_cont.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Test break & continue
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a26-brk_cont.phpt', $dir.'a26-brk_cont.phb');
?>
--FILE--
<?php
include("a26-brk_cont.phb");
unlink(dirname(__FILE__).'/a26-brk_cont.phb');
exit;
//--CODE--
for ($i = 5; $i > 0; $i--) {
if ($i == 3) break;
echo "$i\n";
$j = -$i;
while ($j) {
if (++$j % 2) continue;
echo "$i $j\n";
}
}
?>
--EXPECT--
5
5 -4
5 -2
5 0
4
4 -2
4 0
36 changes: 36 additions & 0 deletions tests/a29-exceptions.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Test exceptions
--SKIPIF--
<?php
if (version_compare(PHP_VERSION, '5.0.0', '<')) die("skip PHP 5 or later is required");
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a29-exceptions.phpt', $dir.'a29-exceptions.phb');
?>
--FILE--
<?php
include("a29-exceptions.phb");
unlink(dirname(__FILE__).'/a29-exceptions.phb');
exit;
--CODE--
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
else return 1/$x;
}

try {
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>
--EXPECT--
0.2
Caught exception: Division by zero.
Hello World
57 changes: 57 additions & 0 deletions tests/a30-class.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--TEST--
Test class basics
--SKIPIF--
<?php
$dir = dirname(__FILE__).'/';
require($dir.'test-helper.php');
make_bytecode($dir.'a30-class.phpt', $dir.'a30-class.phb');
?>
--FILE--
<?php
include("a30-class.phb");
unlink(dirname(__FILE__).'/a30-class.phb');
exit;
--CODE--
class A {
var $x;
function A($v) {
$this->x = $v;
}
function foo() {
if (isset($this)) {
echo '$this is defined (', get_class($this), ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}

class B {
var $x;
function B($v) {
$this->x = $v;
}
function bar() {
A::foo();
}
}

if (PHP_VERSION >= 5) error_reporting(E_ALL & !E_STRICT);

$a = new A('x');
$b = new B(5.5);
echo $a->x, "\n";
var_dump($b->{$a->x});

$a->foo();
A::foo();
$b->bar();
B::bar();
?>
--EXPECTREGEX--
x
float\(5\.5\)
\$this is defined \([Aa]\)
\$this is not defined\.
\$this is defined \([Bb]\)
\$this is not defined\.
Loading

0 comments on commit d57f933

Please sign in to comment.