Do not return errors from decl - store them in heap and return from typing
[hiphop-php.git] / hphp / test / tools / fbmake_test_binary_wrapper.php
blob649e1d1407c7adf8748b62b22f67dbc482b1fa92
1 #!/bin/env php
2 <?php
4 /*
5 * Small utilities for wrapping tests to put output into fbmake.
7 * See hphp/hhvm/fbmake_test_ext_wrapper.php.
8 */
10 // Output is in the format expected by JsonTestRunner.
11 function say($val) {
12 fwrite(STDERR, json_encode($val, JSON_UNESCAPED_SLASHES) . "\n");
15 // Currently running test, and the results of each test.
16 $results = array();
17 $current = '';
19 function finish($status) {
20 global $results;
21 global $current;
23 say(array('op' => 'test_done',
24 'test' => $current,
25 'details' => '',
26 'status' => $status));
27 array_push($results, array('name' => $current,
28 'status' => $status));
29 $current = '';
32 function start($test) {
33 global $current;
35 $current = $test;
36 say(array('op' => 'start',
37 'test' => $current));
40 function test_is_running() {
41 return $GLOBALS['current'] != '';
44 function loop_tests($cmd, $line_func) {
45 global $results;
47 $ftest = popen($cmd, 'r');
48 if (!$ftest) {
49 echo "Couldn't run test script\n";
50 exit(1);
52 while (!feof($ftest)) {
53 $line = fgets($ftest);
54 $line_func($line);
56 if (!fclose($ftest)) {
57 global $current;
58 if ($current !== '') {
59 finish('failed');
61 start('test-binary');
62 finish('failed');
63 return;
66 say(array('op' => 'all_done',
67 'results' => $results));
71 chdir(__DIR__.'/../../../');
72 $cmd = "./hphp/tools/run_test_binary.sh " .
73 "'$argv[1]' '$argv[2]' '$argv[3]' '$argv[4]' ".
74 "2>/dev/null";
76 loop_tests($cmd, function ($line) {
77 if (preg_match('/^(Test[a-zA-Z]*)\.\.\.\.\.\.$/', $line, $m)) {
78 start($m[1]);
79 } else if (preg_match('/^Test[a-zA-Z]* (OK|\#\#\#\#\#\>\>\> FAILED)/',
80 $line,
81 $m)) {
82 finish($m[1] == 'OK' ? 'passed' : 'failed');
84 });