Skip to content

Instantly share code, notes, and snippets.

@hikari-no-yume
Created October 5, 2014 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hikari-no-yume/a15bc06a8f170cbb0a37 to your computer and use it in GitHub Desktop.
Save hikari-no-yume/a15bc06a8f170cbb0a37 to your computer and use it in GitHub Desktop.
php-langspec test conversion script
<?php
function fixDir($dir) {
$files = glob($dir . '/*');
foreach ($files as $file) {
if (is_dir($file)) {
fixDir($file);
} else {
fixFile($file);
}
}
}
function fixFile($file) {
$parts = explode('.', $file);
$ext = $parts[count($parts)-1];
if ($ext === 'php') {
$test = "--TEST--\n$parts[0]\n--FILE--\n";
$test .= file_get_contents($file) or die("couldn't open test file");
if (file_exists($expectfile = $file . '.expect')) {
$test .= "\n--EXPECT--\n";
$test .= file_get_contents($file . '.expect') or die("couldn't open expect file");
} else if (file_exists($expectfile = $file . '.expectf')) {
$test .= "\n--EXPECTF--\n";
$test .= file_get_contents($file . '.expectf') or die("couldn't open expectf file");
} else {
echo "Skipped test $file (couldn't find .expect or .expectf)\n";
return;
}
file_put_contents($parts[0] . '.phpt', $test) or die("couldn't save test file");
unlink($expectfile) or die("couldn't delete $expectfile");
echo "Converted test $parts[0].phpt\n";
}
}
fixDir("tests");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment