Browse Source

Abort if a script fails to execute, and exit with the exit code of the process, fixes #1943

Jordi Boggiano 12 years ago
parent
commit
5d360ab43b

+ 4 - 2
src/Composer/Script/EventDispatcher.php

@@ -120,8 +120,10 @@ class EventDispatcher
                     throw $e;
                 }
             } else {
-                if (0 !== $this->process->execute($callable)) {
-                    $event->getIO()->write(sprintf('<error>Script %s handling the %s event returned with an error: %s</error>', $callable, $event->getName(), $this->process->getErrorOutput()));
+                if (0 !== ($exitCode = $this->process->execute($callable))) {
+                    $event->getIO()->write(sprintf('<error>Script %s handling the %s event returned with an error</error>', $callable, $event->getName()));
+
+                    throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
                 }
             }
         }

+ 6 - 3
tests/Composer/Test/Script/EventDispatcherTest.php

@@ -59,7 +59,8 @@ class EventDispatcherTest extends TestCase
 
         $process->expects($this->once())
             ->method('execute')
-            ->with($command);
+            ->with($command)
+            ->will($this->returnValue(0));
 
         $dispatcher->dispatchCommandEvent("post-install-cmd", false);
     }
@@ -80,7 +81,8 @@ class EventDispatcherTest extends TestCase
             ->getMock();
 
         $process->expects($this->exactly(2))
-            ->method('execute');
+            ->method('execute')
+            ->will($this->returnValue(0));
 
         $listeners = array(
             'echo -n foo',
@@ -165,8 +167,9 @@ class EventDispatcherTest extends TestCase
 
         $io->expects($this->once())
             ->method('write')
-            ->with($this->equalTo('<error>Script '.$code.' handling the post-install-cmd event returned with an error: </error>'));
+            ->with($this->equalTo('<error>Script '.$code.' handling the post-install-cmd event returned with an error</error>'));
 
+        $this->setExpectedException('RuntimeException');
         $dispatcher->dispatchCommandEvent("post-install-cmd", false);
     }