Problem/Motivation
run-tests.sh is a mess. It's brittle and untestable.
Proposed resolution
Refactor run-tests.sh to use the Symfony Console component.
This will have to occur over a few different phases:
1) Straightforward conversion of existing functions to Command methods, with calling code moved to execute(). under_score function names are temporarily retained from the original script so I know where I am. (done)
2) Proper injection of various services used by command methods, including DRUPAL_ROOT. They currently use \Drupal. (mostly done)
3) Refactor various methods to reduce individual complexity. (done in some places, such as RunTestsCommand::simpletest_script_get_test_list())
4) Move the classes out of run-tests.sh into a proper PSR-4 namespace to enable testing. (done: Drupal\Core\RunTests)
5) Shim out direct calls to simpletest functions such as \simpletest_clean_results_table() so that we can mock for unit testing.
6) Add unit tests for testable portions.
7) [Your concern here]
8) Figure out how to review. :-)
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | 2624926-40.patch | 127.21 KB | ravi.shankar |
| #20 | 2624926_21.patch | 123.52 KB | mile23 |
| #18 | interdiff.txt | 12.85 KB | mile23 |
| #18 | 2624926_18.patch | 119.15 KB | mile23 |
| #13 | interdiff.txt | 9.58 KB | mile23 |
Comments
Comment #2
mile23This is a first-pass at some of the work in phase 1 mentioned above. It's a WIP. Some things work, some don't.
I've used the file name
run-tests.phpbecause it's easier to haverun-tests.shin the next tab to refer to. Obviously we'd change the file name once it's in shape. Or would we? :-)Because of the way Console works, you have to specify a run-tests command, like this:
php core/scripts/run-tests.php run-tests --listComment #3
chi commentedWe can set run-tests as default command.
$app->setDefaultCommand('run-tests');Comment #4
mile23Yah, thanks. I figured it out. I had to make a single-command application because otherwise there are parsing errors, since
run-tests.shhas a lot of options that should be commands.Still a WIP...
Exception handling is mostly baked. We can't use
ConsoleEvents::EXCEPTIONhandler because that would add complexity in the wrong places. Add that to the @todo list.Message coloring works with
--colorwhich is, sadly, off by default.How to evaluate:
Apply patch.
Type:
php ./core/scripts/run-tests.php --helpUgly but useable... Still WIP.
Make sure there's an installed Drupal and do something like:
php ./core/scripts/run-tests.php --module node --colorSome tests fail for mysterious reasons, but many do not.
When you're done:
php ./core/scripts/run-tests.php --cleanComment #5
mile23Comment #6
mile23Here it is patched as
run-tests.sh. I'm also going to let the testbot run it, because there are some tests that fail locally in the UI.The patch git generated is a confuzzled mess so I'll upload the new script as well.
Comment #7
mile23Moved most of the code to
\Drupal\Core\RunTestswhich allows us to start writing unit tests without a lot ofrequire_oncemumbo jumbo.Starting to shim out the direct
simpletest.modulecalls so we can mock them for testing.See the issue update for more details.
Comment #11
mile23Not entirely sure why #7 is failing. It'd be nice if CI began storing artifacts before the test ran, so we could see what's causing the problem. (There's no log of the exception/fatal.)
Anyway, it all works locally, so here is more lightweight refactoring with some unit tests.
Really not ready for prime-time yet.
Comment #13
mile23Expanded some unit testing, refactored the Config class to facilitate testing.
CI errors still a mystery.
Comment #15
mile23Local testbot says the error is:
So the testrunner kernel's container is failing to initialize because there's something strange about how it tries to load
core.services.yml.If anyone has any ideas... :-)
Comment #16
mile23Bug in drupalci. #2629700: Force run-tests.sh to run as www-data to generate the simpletest test list.
Comment #17
dawehnerIMHO run-tests.sh should work outside of Drupal, given that this is what you want to test in the first place. Do you really require those files?
Comment #18
mile23Ideally, yes, but I'm only trying to refactor it so it's testable and maintainable, not change any fundamental behavior. So far the patch has a number of unit tests of
run-test.sh's behavior, which is the point of the exercise.Decoupling can come later, along with whatever other changes we desire.
Speaking of which.... :-)
Here's a patch which adds some coding standards stuff, and moves PHP executable discovery away from
getenv('_')towardsPHP_BINARY. With tests. (The tests were reporting phpunit as the executable when usinggetenv('_').)Once the sudo change happens at the testbot level, this will pass and will only need a change away from simpltest_script_underscore method names to camelCase to be acceptable, if not thoroughly tested.
But it will provide a framework by which new behaviors can be tested, and bugs tested against.
It might be that this gets shoved to 8.1.x and that's fine, too.
Comment #20
mile23Bumped to 8.1.x.
Renamed all the under_score names to camelCase. Yanked Console's support for --help, so we only ever see the old help screen we're familiar with.
This is a nice stopping point. Let's call it a DRY normalization, such that the refactored repeated parts are now unit-testable. This is mostly related to test discovery, which is the part I was interested in.
Anyone is welcome to join in, of course. :-)
Next steps:
core/core.services.ymljust fine under the testbot, whereas this one can't unless you run it as sudo.Comment #21
mile23Comment #23
dawehner@mile23
Please keep in mind that even refactoring is nice, you want to try to keep the issue in scope so its actually reviewable. Otherwise you won't make any progress at all.
Comment #24
mile23That's why I called it a stopping point.
The only real issue at this point is why
core.services.ymlisn't readable by the testbot. My local testbot builds keep flaking out after one run (don't darevagrant haltor it's all over) so going is slow.The wins here are:
Comment #25
jhedstromThis is very generic to single-command applications. I think we should provide a base application class for single-command apps (the db dump script could be the proof of concept).
Comment #27
finne+1 on the rename: other .sh scripts in the /core/scripts dir are all valid shell scripts (that mostly boot php on the first line). This file should have a php extention, or the first line should add #!/bin/php
Comment #29
mile23#2629700: Force run-tests.sh to run as www-data to generate the simpletest test list. is close to happening, so this refactor will be testable.
A lot of the code of run-tests.sh will have changed, so this won't just be a re-roll if/when work resumes.
Comment #31
mile23Comment #39
volegerComment #40
ravi.shankar commentedAdded reroll of patch #20 on Drupal-9.2.x
Comment #42
mondrakeChange issue component.