-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.php
96 lines (81 loc) · 2.48 KB
/
test.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
85
86
87
88
89
90
91
92
93
94
95
96
<?php
if (php_sapi_name() != 'cli') {
throw new \Exception();
}
$basePath = __DIR__;
$testPath = __DIR__.'/test';
require $basePath.'/vendor/autoload.php';
require $testPath.'/lib/TestCase.php';
require $testPath.'/lib/LanguageAgnosticTest.php';
require $testPath.'/lib/PythonPortedTest.php';
function dump($mixed = null) {
ob_start();
var_dump($mixed);
$content = ob_get_contents();
ob_end_clean();
return rtrim($content);
}
$pyTestFile = $basePath.'/py/testcases.docopt';
if (!file_exists($pyTestFile)) {
die("Please ensure you have loaded the git submodules\n");
}
$verbose = false;
$dumpMode = 'serialize'; // or vardump
$suite = [];
$suite[] = new \Docopt\Test\PythonPortedTest();
$suite = array_merge($suite, \Docopt\Test\LanguageAgnosticTest::createSuite($pyTestFile));
$suite = array_merge($suite, \Docopt\Test\LanguageAgnosticTest::createSuite("$basePath/test/extra.docopt"));
$tests = 0;
$passed = 0;
$failed = 0;
$details = [];
foreach ($suite as $test) {
$rc = new ReflectionClass($test);
foreach ($rc->getMethods() as $method) {
if (substr($method->getName(), 0, 4) !== "test") {
continue;
}
$tests++;
$name = substr($method->getName(), 4);
if (!$name) $name = $test->name;
try {
$method->invoke($test);
if ($verbose) {
echo "PASS: {$rc->getName()} {$name}\n";
}
$passed++;
} catch (\Docopt\Test\ExpectationFailed $e) {
echo "FAIL: {$rc->getName()} {$name} {$e->getMessage()}\n";
$details[] = [
"suite" => $rc->getName(),
"name" => $name,
"message" => $e->getMessage(),
"vardump" => [
"want" => dump($e->expected),
"got" => dump($e->value),
],
"serialize" => [
"want" => serialize($e->expected),
"got" => serialize($e->value),
],
];
$failed++;
}
}
}
if (count($details)) {
echo "\n";
echo "Failure details:\n";
foreach ($details as $failure) {
$dump = $failure[$dumpMode];
echo "{$failure['suite']} {$failure['name']}\n";
echo "message: {$failure['message']}\n";
echo "want: {$dump['want']}\n";
echo "got: {$dump['got']}\n";
echo "\n";
}
}
echo "{$tests} test(s), {$passed} passed, {$failed} failed\n";
if ($failed > 0) {
exit(2);
}