Created
October 5, 2014 19:07
-
-
Save hikari-no-yume/a15bc06a8f170cbb0a37 to your computer and use it in GitHub Desktop.
php-langspec test conversion script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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