1<?php
2
3if ($argc >= 2) {
4    $testsDir = $argv[1];
5} else {
6    $testsDir = __DIR__ . '/../../Zend/tests';
7}
8if ($argc >= 3) {
9    $corpusDir = $argv[2];
10} else {
11    $corpusDir = __DIR__ . '/corpus/execute';
12}
13if ($argc >= 4) {
14    $maxLen = (int) $argv[3];
15} else {
16    $maxLen = 8 * 1024;
17}
18
19$it = new RecursiveIteratorIterator(
20    new RecursiveDirectoryIterator($testsDir),
21    RecursiveIteratorIterator::LEAVES_ONLY
22);
23
24@mkdir($corpusDir);
25
26foreach ($it as $file) {
27    if (!preg_match('/\.phpt$/', $file)) continue;
28    $fullCode = file_get_contents($file);
29    if (!preg_match('/--FILE--\R(.*?)\R--([_A-Z]+)--/s', $fullCode, $matches)) continue;
30    $code = $matches[1];
31    if (strlen($code) > $maxLen) continue;
32
33    $outFile = str_replace($testsDir, '', $file);
34    $outFile = str_replace('/', '_', $outFile);
35    if (!preg_match('/SKIP_SLOW_TESTS|SKIP_PERF_SENSITIVE|USE_ZEND_ALLOC/', $fullCode)) {
36        file_put_contents($corpusDir . '/' . $outFile, $code);
37    }
38}
39