forked from dahlia/lisphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
52 lines (46 loc) · 1.26 KB
/
test.php
File metadata and controls
52 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require dirname(__FILE__) . '/Lisphp.php';
$options = getopt('v', array('verbose'));
function displayStrings() {
global $result;
$args = func_get_args();
$result .= join('', array_map('strval', $args));
}
$testFiles = glob(dirname(__FILE__) . '/tests/*.lisphp');
$fails = array();
foreach ($testFiles as $file) {
$program = Lisphp_Program::load($file);
$result = '';
$scope = Lisphp_Environment::full();
$scope['echo'] = new Lisphp_Runtime_PHPFunction('displayStrings');
$program->execute($scope);
$expected = file_get_contents(preg_replace('/\.lisphp$/', '.out', $file));
if (trim($result) == trim($expected)) {
echo '.';
} else {
echo 'F';
$fails[$file] = $result;
}
}
if ($fails) {
echo "\nFailed: ";
} else {
echo "\nOK ";
}
echo '(', count($testFiles), ' tests';
if ($fails) {
echo ', ', count($fails), ' failed';
}
echo ")\n";
if ($fails) {
if (isset($options['verbose']) || isset($options['v'])) {
$br = str_repeat('-', 80);
foreach ($fails as $file => $actual) {
echo "$br\n$file\n$br\n$actual\n";
}
echo "$br\n";
} else {
$files = array_map('basename', array_keys($fails));
echo "Failed tests: ", join(', ', $files), "\n";
}
}