Legoktm has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/405572 )

Change subject: Refactor test runner and clean up tmp files
......................................................................


Refactor test runner and clean up tmp files

Change-Id: I9b8a11ddba136dbaad35189e7415daa5dd5b5844
---
M src/CheckCommand.php
1 file changed, 24 insertions(+), 20 deletions(-)

Approvals:
  Legoktm: Verified; Looks good to me, approved



diff --git a/src/CheckCommand.php b/src/CheckCommand.php
index a78246d..587f2e7 100644
--- a/src/CheckCommand.php
+++ b/src/CheckCommand.php
@@ -84,6 +84,27 @@
                return '\'/' . implode( '|', $filter ) . '/\'';
        }
 
+       private function runTests( $output, $command, $tests ) {
+               // TODO: Run this in parallel?
+               $clover = tempnam( sys_get_temp_dir(), 'clover' );
+               $cmd = $command .
+                       " --coverage-clover $clover --filter " .
+                       $this->getFilterRegex( $tests );
+               $process = new CommandProcess( $cmd );
+               // Disable timeout
+               $process->setTimeout( null );
+               // Run and buffer output for progress
+               $process->runWithOutput( $output );
+
+               $this->scopedCallbacks[] = new ScopedCallback(
+                       function () use ( $clover ) {
+                               unlink( $clover );
+                       }
+               );
+
+               return $clover;
+       }
+
        protected function execute( InputInterface $input, OutputInterface 
$output ) {
                $git = new Git( getcwd() );
                $sha1 = $input->getOption( 'sha1' );
@@ -129,18 +150,10 @@
 
                // TODO: We need to trim suite.xml coverage filter, because 
that takes forever
 
+               $command = $input->getOption( 'command' );
                if ( $testsToRun ) {
                        // Run it!
-                       // TODO: Run this in parallel?
-                       $newClover = tempnam( sys_get_temp_dir(), 'old-clover' 
);
-                       $cmd = $input->getOption( 'command' ) .
-                               " --coverage-clover $newClover --filter " .
-                               $this->getFilterRegex( $testsToRun );
-                       $process = new CommandProcess( $cmd );
-                       // Disable timeout
-                       $process->setTimeout( null );
-                       // Run and buffer output for progress
-                       $process->runWithOutput( $output );
+                       $newClover = $this->runTests( $output, $command, 
$testsToRun );
                } else {
                        $newClover = null;
                }
@@ -159,15 +172,7 @@
                        $this->absolutify( $changedTests->deleted )
                ) );
                if ( $testsOldToRun ) {
-                       $oldClover = tempnam( sys_get_temp_dir(), 'new-clover' 
);
-                       $cmd = $input->getOption( 'command' ) .
-                               " --coverage-clover $oldClover --filter " .
-                               $this->getFilterRegex( $testsOldToRun );
-                       $process = new CommandProcess( $cmd );
-                       // Disable timeout
-                       $process->setTimeout( null );
-                       // Run and buffer output for progress
-                       $process->runWithOutput( $output );
+                       $oldClover = $this->runTests( $output, $command, 
$testsOldToRun );
                } else {
                        $oldClover = null;
                }
@@ -182,7 +187,6 @@
                $diff = ( new Differ() )->diff( $oldClover, $newClover );
                $printer = new DiffPrinter( $output );
                $printer->show( $diff );
-               // TODO: clean up tmp clover files
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/405572
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9b8a11ddba136dbaad35189e7415daa5dd5b5844
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/phpunit-patch-coverage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to