It is not possible to run run-test.sh in a directory containing a space on non-windows systems. This happens because of a bug in the phpunit test runner that doesn't escape the command. Because of this it only affects running phpunit based tests.
$ pwd
/var/www/localhost/htdocs/d8 1
$ php core/scripts/run-tests.sh --url http://localhost.local/d8\ 1 --color --dburl mysql://... --sqlite ./test.sqlite --verbose --class Drupal\Tests\Core\Ajax\AjaxCommandsTest,Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest
Drupal test run
---------------
Tests to be run:
- Drupal\Tests\Core\Ajax\AjaxCommandsTest
- Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest
Test run started:
Monday, December 14, 2015 - 12:50
Test summary
------------
sh: 1: /var/www/localhost/htdocs/d8: Permission denied
sh: 1: /var/www/localhost/htdocs/d8: Permission denied
....
$ php vendor/bin/phpunit -c core/phpunit.xml.dist core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
PHPUnit 4.8.11 by Sebastian Bergmann and contributors.
E
Time: 301 ms, Memory: 5.50Mb
There was 1 error:
1) Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand
PHPUnit_Framework_Exception: sh: 1: /var/www/localhost/htdocs/d8: Permission denied
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | simpletest_with_space.patch | 926 bytes | neclimdul |
| #2 | run_test_sh_doesn_t-2635046-2.patch | 612 bytes | neclimdul |
Comments
Comment #2
neclimdulWe don't really care about escaping for security I don't think because we're basically hard coding the path but we need to escape the space. escapeshellcmd() doesn't do this anyways so here's a quick fix.
Comment #3
neclimdulComment #4
dawehnerLooks fine for me.
I was wondering whether there is some php helper function for that, but I could not find any.
Comment #5
alexpottI've tested this and wrapping it with escapeshellarg() works so why not do that?
Comment #6
dawehnerOH I see, so this would just put it into quotes which has the same behaviour. Yeah why not!
Comment #7
mile23Based on #5, moving this to NW.
Also adding the tag because you can't search for 'run-tests.sh' on d.o.
Comment #10
rafalenden commentedIt also applies to Simpletest.
Comment #14
neclimdulComment #15
dawehner+1 for escaping shell arguments always.
Comment #16
alexpottCommitted and pushed abc6c6a336 to 8.6.x and ab240fc103 to 8.5.x. Thanks!