-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sbp.php
84 lines (72 loc) · 2.27 KB
/
sbp.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once 'vendor/autoload.php';
use Sbp\Sbp;
class SbpTestParse extends Sbp
{
public static function getLastParsedFile()
{
}
}
define('CREATE_TEST', 'create-test');
define('COMPILE_TEST', 'compile-test');
define('COMPILE', 'compile');
function argn($i)
{
global $argv;
return isset($argv[$i]) ? $argv[$i] : null;
}
$script = argn(0);
if (substr($script, -4) === '.php') {
$script = "php $script";
}
switch ($command = argn(1)) {
case CREATE_TEST:
$name = argn(2);
$path = __DIR__.'/tests/sbp/files/.src/'.$name.'.php';
touch($path);
$path = realpath($path);
echo "You can now edit the SBP test file:\n";
echo "$path\n";
echo "Then enter the following command to compile the PHP file:\n";
echo "$script ".COMPILE_TEST." $name\n";
break;
case COMPILE_TEST:
$name = argn(2);
$names = $name === '--all'
? array_map(function ($file) {
return substr($file, -4) === '.php' ? substr(basename($file), 0, -4) : null;
}, scandir(__DIR__.'/tests/sbp/files'))
: array($name);
foreach ($names as $name) {
$from = realpath(__DIR__.'/tests/sbp/files/.src').DIRECTORY_SEPARATOR.$name.'.php';
if (file_exists($from)) {
$to = __DIR__.'/tests/sbp/files/'.$name.'.php';
SbpTestParse::fileParse($from, $to);
echo "Compilation done in:\n";
echo realpath($to)."\n";
echo filesize($to)." bytes\n";
continue;
}
echo "File not found at:\n";
echo "$from\n";
echo "To create a new test with this name, enter:\n";
echo "$script ".CREATE_TEST." $name \n";
}
break;
case COMPILE:
$from = argn(2);
if (file_exists($from)) {
$to = tempnam(sys_get_temp_dir(), 'sbp-compile');
Sbp::fileParse($from, $to);
readfile($to);
unlink($to);
break;
}
echo "File not found at:\n";
echo "$from\n";
break;
default:
echo "Usage:\n php $script <command>\n\n";
echo "Commands:\n ".CREATE_TEST."\n ".COMPILE_TEST."\n ".COMPILE;
break;
}