Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
run-tests.sh is a PHP script rather than a shell script.
Proposed resolution
We have new ways of avoid running php file via web server since this issue created. We could use one of the method.
Remaining tasks
N/A
User interface changes
N/A
API changes
Probably as it's a file rename?
Comment | File | Size | Author |
---|---|---|---|
#72 | 655178-nr-bot.txt | 143 bytes | needs-review-queue-bot |
#62 | 655178-62.patch | 55.46 KB | Anonymous (not verified) |
Issue fork drupal-655178
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
boombatower CreditAttribution: boombatower commentedI agree, but that is an issue for core and 7.x-2.x which I develop outside of core and patch into core.
Comment #2
boombatower CreditAttribution: boombatower commentedComment #3
grendzy CreditAttribution: grendzy commentedWhy can't it have the shebang? All the other files in /scripts do.
Comment #4
claar CreditAttribution: claar commented+1. This script should not be named .sh if it isn't a shell script -- that's just wrong.
I see two reasonable ways to fix this:
Both methods will break various automatic testing systems, but leaving this bug makes running tests unnecessarily confusing for developers. This is the ideal time to get this into 8.x, since we're early in the development process.
Comment #5
rfayI think we should get this done in 8.x, and soon.
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe don't have that for a reason: we need to use the same version of PHP and under the same permissions as the web server. This is not trivial to do, so simply renaming to .php will not make running tests less confusing. Also, if we rename to .php we need to protect against running under the web server.
Comment #7
rfayI think we have to do something about this. I found it incredibly misleading.
Suggestions in IRC:
* No suffix (confuses Mac and Windows but I still think it's good)
* .php with a .htaccess to protect it (IIS doesn't respect .htaccess)
* .php.txt (makes sense to me)
* .php_
Comment #8
grendzy CreditAttribution: grendzy commentedI think I'd prefer the standard .php extension with this check to prevent web server execution:
Regarding the shebang, I think we can add it and that will help the majority of users who only have one version of php installed. More advanced users can still invoke a different interpreter directly, since in that case the shebang gets ignored as if it were a comment.
Comment #9
rfayI like that.
Comment #10
sobi3ch CreditAttribution: sobi3ch commentedreffered to #8
I don't know did I make it in proper way but I just try it
Comment #12
grendzy CreditAttribution: grendzy commentedheh. Not surprisingly, the test bot's operation depends on this file's name.
Output: [Could not open input file: ./core/scripts/run-tests.sh].
Comment #13
rfayYou might want to try a symlink or something. It will be years to make the transition... Not sure if one can check a symlink into git.
Comment #14
grendzy CreditAttribution: grendzy commentedYes git can track symlinks easily. Although, given the handful of other ".sh" files in core/scripts, maybe the more consistent change would be to add the shebang. Of the 8 scripts shipped with core, run-tests.sh is the only one without #!/bin/sh or #!/usr/bin/env php.
Comment #15
rfayIt's just so *wrong* for it to have .sh though. SO WRONG!!!!
Comment #16
sobi3ch CreditAttribution: sobi3ch commented#15 rfay: yeah I agree it's looks really wrong to have .sh for php script .. I'll try with simlink..
And one question, why did you say: "It will be years to make the transition..." why it should take years to do it??
There must be a way to create patch with file renaming.
Comment #17
boombatower CreditAttribution: boombatower commentedIt had a shebang...but that was removed since it broke for windows folks...and now we all suffer together. We can add a file_exists() to check in both places rather the muddy up repos with symbolic link.
Comment #18
rfay@sobi3ch, I guess I was saying that we still have 6.x and 7.x in testing. This would have to be added to the testbot as an item to be found. But I think a symlink is the key here.
Comment #19
boombatower CreditAttribution: boombatower commented#1760928: Allow for #655178 to rename run-tests.sh to run-tests.php
I can go ahead, commit and deploy this Wednesday with other changes as long as there is a consensus on the filename.
Comment #20
grendzy CreditAttribution: grendzy commentedboombatower: Thanks, do you have any more information on the Windows problem with shebangs? I found one old bug in a 5.3 alpha but it was fixed a long time ago: https://bugs.php.net/bug.php?id=47089
So here's one way:
Comment #21
grendzy CreditAttribution: grendzy commentedComment #22
boombatower CreditAttribution: boombatower commentedRelevant issues
#474270: Rename run-tests.sh to run-tests.php
#331580: Make run-tests.sh find PHP on Windows & Linux
Comment #23
grendzy CreditAttribution: grendzy commentedThanks for the links, if I'm reading right at least one problem with the shebang on this script (not necessarily windows-related) is that some users want to autodetect the PHP binary path with
getenv('_')
, and that only works if it's run like/usr/bin/php run-tests...
.There's a PHP_BINARY constant but it's not available until PHP 5.4.
Comment #24
boombatower CreditAttribution: boombatower commentedWell, related to that which is where the issue on windows came up I believe is that we had /usr/bin/php in shebang which didn't work for everyone. Obviously, there is env php and what not in shebang, but you can see the context.
Comment #25
sobi3ch CreditAttribution: sobi3ch commentedso maybe there should be seperate files for win and *nix like:
run-teset.bat <-- fire .php_ file (only windows)
run-tests.sh <-- fire .php_ file (only *unix)
run-test.php_
Especially if you guys check first lines in scirpts/ directory in D6 and D7:
scripts/ in D6:
============
$ find . -type f | xargs head -1
==> ./cron-lynx.sh <==
#!/bin/sh
==> ./code-clean.sh <==
#!/bin/sh
==> ./drupal.sh <==
#!/usr/bin/php
==> ./cron-curl.sh <==
#!/bin/sh
==> ./code-style.pl <==
#!/usr/bin/perl -w
scripts/ in D7:
============
$ find . -type f | xargs head -1
==> ./cron-lynx.sh <==
#!/bin/sh
==> ./code-clean.sh <==
#!/bin/sh
==> ./drupal.sh <==
#!/usr/bin/env php
==> ./password-hash.sh <==
#!/usr/bin/php
==> ./dump-database-d7.sh <==
#!/usr/bin/env php
==> ./generate-d6-content.sh <==
#!/usr/bin/env php
==> ./test.script <==
This file is for testing purposes only.
==> ./run-tests.sh <==
<?php
==> ./cron-curl.sh <==
#!/bin/sh
==> ./dump-database-d6.sh <==
#!/usr/bin/env php
==> ./generate-d7-content.sh <==
#!/usr/bin/env php
.. so it seems ALL scripts use shebang with env OR direct path to command. Maybe I'am lost but I don't see the reason why only just run-tests script need to be all cross platform compatible??? Can you explain me this please.
Comment #26
boombatower CreditAttribution: boombatower commentedI would agree with you that it doesn't make sense to special case run-tests.sh. The reason it was is because people _actually use_ run-tests.sh and no one uses the others, people use drush or not those scripts at all. So people ran into the issue and then it got hot fixed (I was never a fan).
Making these scripts consistent would seem to make a lot of sense. I also got Dries (a while back, script I was working on never panned out) to agree to allow drush scripts in core so perhaps that would be useful here. Seems like a fairly reasonable thing to do and solves the comparability issues.
Comment #27
sobi3ch CreditAttribution: sobi3ch commentedCorrect me if I'm wrong. You suggest (and Dries was agree with you) that we should convert all .sh to .drush script, and make drush command line mandatory? For me sounds cool, but is it not to much (or make sense at all) for simple script to bootstrap all drupal stack before it's run? so many questions..
Comment #28
boombatower CreditAttribution: boombatower commentedDries simply agreed that it made sense (after a discussion with several key core folks) to allow drush scripts in core. That doesn't mean everything has/will be, but that we can use drush scripts in core. There is a patch in the queue to add core to the path that drush searches for for scripts (we will need to update for d8 /core if we want to do this).
Comment #29
boombatower CreditAttribution: boombatower commentedForgot it was actually committed, #1317562: Include core modules in command search path.
Anyway we will probably need to update that.
Comment #30
sobi3ch CreditAttribution: sobi3ch commentedOK I see, so how should this look like on the end, in working enviroment?
$ drush scr run-tests.drush
if so there is an bootstrap issue. We often want to run script in DRUSH_BOOTSTRAP_DRUSH (simplest; Only bootstrap Drush, without any Drupal specific code) mode without bootstrapping unnecessary stuff. I think there should be some configuration (or flag in shebang) to run in appropriate bootstrap mode. Somthing like e.g.:
Then you could run it with:
$ drush scr script.drush
and be sure it's in proper bootstrap mode. More about boostraping: http://drush.ws/docs/bootstrap.html . I'm not very good in drush boostraping so maybe I'm doing something stupid.
I realize there is shebang handle by drush as well so you can start your file like this:
#!/usr/bin/drush
but again we run to windows issue, so probably above example withdefine()
is better.What's your thoughts?
Comment #31
boombatower CreditAttribution: boombatower commentedWe need to alter drush to look for scripts in the core/scripts dir if it does not already. drush uses a hook to define command and you can include the bootstrap level. http://drupalcode.org/project/drush.git/blob/refs/heads/7.x-5.x:/docs/dr...
Drush also already has a run-tests command which perhaps we want to copy into core and tweak. http://drupalcode.org/project/drush.git/blob/refs/heads/7.x-5.x:/command...
I haven't looked at it so not sure if it would even remotely work (I just know it exists). Having this in core though would allow us to replace current script and keep in sync so testbot can use it.
Comment #32
sobi3ch CreditAttribution: sobi3ch commentedWow! seems I need to learn more about drush before I continue this discussion. I need to go sleep..
Comment #33
sobi3ch CreditAttribution: sobi3ch commented@boombatower: hey can you provide link to this patch? I would like to look at it.. cheers
Comment #34
boombatower CreditAttribution: boombatower commentedLink to what patch? Not sure if you were referring to the "script" I mentioned, but that was referring to run-tests.sh being replace by drush command that testbot can use.
Theoretically, the bot could use drush right now...best with stable 6.x, 7.x, but not 8.x since everytime the testing system is changed drush needs to be updated in the same patch. So moving the drush command in core would allow just that and replace the run-test.sh code. Most likely would require some sort of feature merging since I doubt both work the same.
Comment #35
sobi3ch CreditAttribution: sobi3ch commentedSo moving the drush command in to the core means installing drush in /core/drush/ directory or something else? I just want to help but I don't know from which point to start..
Comment #36
boombatower CreditAttribution: boombatower commentedDrush will follow its standard installation instructions. The only file in core will be the drush command definition itself.
Comment #39
star-szrComment #40
markhalliwellComment #42
Mile23Comment #44
joachim CreditAttribution: joachim commentedThe title and summary don't match.
Comment #48
vijaycs85Could we please do this? PhpStorm almost freeze every time open this file.
Comment #50
vijaycs85Comment #51
vijaycs85Comment #52
Mile23+1
Comment #54
jibranIsn't this a BC break?
Comment #55
Chi CreditAttribution: Chi commentedrun-tests.sh is still in place but marked as deprecated. So this should not break anything.
Comment #56
Anonymous (not verified) CreditAttribution: Anonymous commentedReroll + deprecated like https://www.drupal.org/core/deprecation#how-file + CR.
Also patch without mode change:
Or was it specially made?
Comment #57
vijaycs85@vaplas, no I didn't mean to change it. Thanks for the review and the patch!
Comment #58
jibranit is not executable anymore so I think mod change is fine.
Comment #59
Chi CreditAttribution: Chi commentedWhy not use PHP shebang in this file?
Comment #60
Anonymous (not verified) CreditAttribution: Anonymous commented#59: If add line
#!/usr/bin/env php
to therun-tests.php
, and than callrun-tests.sh
, then the result contains some noise:So maybe this should be done in a separate issue, after switching to run-tests.php on the DI.
Or is it a hint that it makes sense to leave the file with executable mode?)
Comment #61
Anonymous (not verified) CreditAttribution: Anonymous commentedReroll + revert 100644 per #58.
Comment #62
Anonymous (not verified) CreditAttribution: Anonymous commentedI also updated 8.5.0 -> 8.5.x. But forgot to do it for trigger_error message. Fixed.
Comment #72
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #75
volegerRerolled against 10.1.x
Comment #76
borisson_I think that run-tests.sh is the old way of working because we were not using phpunit? Are we keeping this supported,
renaming this at this point in time doesn't feel needed/useful.
Comment #77
quietone CreditAttribution: quietone at PreviousNext commentedMoving to the testing component.
Comment #78
nod_Comment #79
Mile23Re: #76
We use run-tests.sh in the CI right now, and it would be great if it were more maintainable.
IIRC the reason it's got the .sh extension is that PHP won't discover the file, and so that htaccess type configuration can exclude it more easily. So it's a security through obscurity type scenario.
Changing the file name also means changing the CI system, and while it doesn't seem like we'd need to alter too much, we'd end up with different file names for different versions of core. A CI system maintainer could speak to whether that effort would be worth it, and what the future plans are for switching to a different test runner potentially.
In my ideal world this script would have been refactored into a symphony console based app, and thus much more maintainable and less ambiguous when it comes to file names. #2624926: Refactor run-tests.sh for Console component. But I fear that ship has sailed as well, because we have always been 'just about to' switch over to something else.