minor #15621 [appveyor] minor enhancements (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[appveyor] minor enhancements

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

ea9780e [appveyor] minor enhancements
This commit is contained in:
Nicolas Grekas 2015-08-26 16:13:30 +02:00
commit 0df822d466
1 changed files with 36 additions and 26 deletions

62
phpunit
View File

@ -7,7 +7,7 @@ $PHPUNIT_VERSION = 4.8;
$PHPUNIT_DIR = __DIR__.'/.phpunit'; $PHPUNIT_DIR = __DIR__.'/.phpunit';
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) { if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
# Build a standalone phpunit without symfony/yaml // Build a standalone phpunit without symfony/yaml
$oldPwd = getcwd(); $oldPwd = getcwd();
mkdir($PHPUNIT_DIR); mkdir($PHPUNIT_DIR);
@ -31,7 +31,7 @@ $cmd = array_map('escapeshellarg', $argv);
$exit = 0; $exit = 0;
if (isset($argv[1]) && 'symfony' === $argv[1]) { if (isset($argv[1]) && 'symfony' === $argv[1]) {
# Find Symfony components in plain php for Windows portability // Find Symfony components in plain php for Windows portability
$finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS); $finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
$finder = new RecursiveIteratorIterator($finder); $finder = new RecursiveIteratorIterator($finder);
@ -45,7 +45,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
if ('phpunit.xml.dist' === $file) { if ('phpunit.xml.dist' === $file) {
$component = dirname($fileInfo->getPathname()); $component = dirname($fileInfo->getPathname());
# Run phpunit tests in parallel // Run phpunit tests in parallel
$c = escapeshellarg($component); $c = escapeshellarg($component);
@ -58,20 +58,34 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
} }
} }
// Fixes for colors support on appveyor
// See http://help.appveyor.com/discussions/suggestions/197-support-ansi-color-codes
$colorFixes = array(
array("S\033[0m\033[0m\033[36m\033[1mS", "E\033[0m\033[0m\033[31m\033[1mE", "I\033[0m\033[0m\033[33m\033[1mI", "F\033[0m\033[0m\033[41m\033[37mF"),
array("SS", "EE", "II", "FF"),
);
$colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
$colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
foreach ($procs as $component => $proc) { foreach ($procs as $component => $proc) {
$procStatus = proc_close($proc); $procStatus = proc_close($proc);
foreach (array('out', 'err') as $file) { foreach (array('out', 'err') as $file) {
$file = "$component/phpunit.std$file"; $file = "$component/phpunit.std$file";
$h = fopen($file, 'rb');
while (false !== $line = fgets($h)) { if ('\\' === DIRECTORY_SEPARATOR) {
echo preg_replace_callback( $h = fopen($file, 'rb');
'/\033\[[0-9]++(?:;[0-9]++)++m/', while (false !== $line = fgets($h)) {
function ($m) {return str_replace(';', "m\033[", $m[0]);}, echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
$line '/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
); "$1m\033[$2$3$4$4",
$line
));
}
fclose($h);
} else {
readfile($file);
} }
fclose($h);
unlink($file); unlink($file);
} }
@ -84,32 +98,28 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
} }
} elseif (!isset($argv[1]) || 'install' !== $argv[1]) { } elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
# Run regular phpunit in a subprocess // Run regular phpunit in a subprocess
$cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always"; $cmd[0] = "php $PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit --colors=always";
$errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.'); $errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
if ($proc = proc_open(implode(' ', $cmd).' 2> '.escapeshellarg($errFile), array(1 => array('pipe', 'w')), $pipes)) { if ($proc = proc_open(implode(' ', $cmd).' 2> '.escapeshellarg($errFile), array(1 => array('pipe', 'w')), $pipes)) {
while (false !== $line = fgets($pipes[1])) { stream_copy_to_stream($pipes[1], STDOUT);
echo $line;
}
fclose($pipes[1]); fclose($pipes[1]);
$exit = proc_close($proc); $exit = proc_close($proc);
$h = fopen($errFile, 'rb'); readfile($errFile);
while (false !== $line = fgets($h)) {
echo $line;
}
fclose($h);
unlink($errFile); unlink($errFile);
} }
if (file_exists($component = array_pop($argv))) { if (!file_exists($component = array_pop($argv))) {
if ($exit) { $component = basename(getcwd());
echo "\033[41mKO\033[0m $component\n\n"; }
} else {
echo "\033[32mOK\033[0m $component\n\n"; if ($exit) {
} echo "\033[41mKO\033[0m $component\n\n";
} else {
echo "\033[32mOK\033[0m $component\n\n";
} }
} }