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.
Running core/scripts/run-tests.sh
and specifying a non-existent test results in PHP notices and warnings, as the below. The fix is as easy as testing for an array key before trying to use it. Patch to follow.
$ sudo -u www-data php scripts/run-tests.sh --url http://d8.dev/ example
PHP Notice: Undefined index: example in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
PHP Stack trace:
PHP 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
PHP 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
Notice: Undefined index: example in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
Call Stack:
0.0012 392608 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
0.3849 14331120 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
PHP Warning: array_keys() expects parameter 1 to be array, null given in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
PHP Stack trace:
PHP 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
PHP 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
PHP 3. array_keys() /var/www/community/d8.dev/core/scripts/run-tests.sh:807
Warning: array_keys() expects parameter 1 to be array, null given in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
Call Stack:
0.0012 392608 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
0.3849 14331120 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
0.9888 200043912 3. array_keys() /var/www/community/d8.dev/core/scripts/run-tests.sh:807
PHP Warning: array_merge(): Argument #2 is not an array in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
PHP Stack trace:
PHP 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
PHP 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
PHP 3. array_merge() /var/www/community/d8.dev/core/scripts/run-tests.sh:807
Warning: array_merge(): Argument #2 is not an array in /var/www/community/d8.dev/core/scripts/run-tests.sh on line 807
Call Stack:
0.0012 392608 1. {main}() /var/www/community/d8.dev/core/scripts/run-tests.sh:0
0.3849 14331120 2. simpletest_script_get_test_list() /var/www/community/d8.dev/core/scripts/run-tests.sh:70
0.9889 200043912 3. array_merge() /var/www/community/d8.dev/core/scripts/run-tests.sh:807
ERROR: No valid tests were specified.
Comment | File | Size | Author |
---|---|---|---|
#23 | run_tests_sh_does_not-2310415-D7-23.patch | 2.94 KB | cilefen |
#18 | run_tests_sh_does_not-2310415-18.patch | 2.86 KB | cilefen |
#18 | interdiff-14-18.txt | 2.88 KB | cilefen |
#14 | have_run_tests_sh-2310415-14.patch | 3.3 KB | cilefen |
#14 | interdiff-11-14.txt | 3.05 KB | cilefen |
Comments
Comment #1
TravisCarden CreditAttribution: TravisCarden commentedComment #2
penyaskitoShould we show an informative message instead?
Comment #3
dawehner+1 for providing an actual helpful message. If you want to be super-fancy you could use
http://en.wikipedia.org/wiki/Levenshtein_distance to provide the probable wanted test.
Comment #4
cilefen CreditAttribution: cilefen commentedThere is also a fatal error when an unknown test class is specified:
Comment #5
cilefen CreditAttribution: cilefen commentedChanged the title appropriately. Retitle if we want this issue to cover unknown individual tests (test classes).
Comment #6
cilefen CreditAttribution: cilefen commentedThis will error and exit on invalid test groups or test classes and report which group or class is invalid. I love the Levenshtein distance idea -- "Did you mean ...?"
Comment #7
cilefen CreditAttribution: cilefen commentedThis patch also calculates likely matches based on the Levenshtein distance. Please credit @ednawig also on commit.
Test group example:
Test class example:
Comment #8
penyaskitoWow, impressive!! I'm wondering if it would be better to show the suggestions in one line for not filling out with error messages.
Comment #9
cilefen CreditAttribution: cilefen commentedThis version prints the alternatives on one line. I made the match stricter so we don't get as many.
Comment #10
jibranThis needs work. param name's are not helpful and description is also missing.
Comment #11
cilefen CreditAttribution: cilefen commentedComment #12
sunHm. This triggers a full (slow) test discovery even though you specified a concrete list of test classes to execute.
Wondering whether we can loop over the given list first, but check whether
class_exists()
?That will only trigger a direct lookup + autoload of the specified classes. Only if one of them does not exist, we can enter an error code path, which performs the additional discovery in order to output suggestions. (?)
Not sure why the prefix/label is in all-uppercase?
Also, listing one alternative per line as in earlier iterations was more readable. I'd recommend to decrease the possible amount of alternatives instead:
Please note #2189345: run-tests.sh should exit with a failure code if any tests failed
Comment #13
cilefen CreditAttribution: cilefen commented@sun Thank you for reviewing. For #1, you are absolutely right, class_exists is faster, so I moved the full discovery to the error path. For #2, done. For #3, do you want to postpone this until the exit() constants are in?
Comment #14
cilefen CreditAttribution: cilefen commentedComment #17
sunThanks! Looks better now.
We don't necessarily need to wait for the other issue.
Can we find a better name for the
simpletest_alternatives()
function? (1) All functions in the script are prefixed withsimpletest_script_
. (2) Any particular reason for not moving the print/output code directly into it + rename it tosimpletest_script_print_alternatives()
?btw, fixing issue title - a bug report should summarize the bug, not the feature. :-)
Comment #18
cilefen CreditAttribution: cilefen commentedRenamed to simpletest_script_print_alternatives().
Changed the matching on test group names to be less strict than for classes in terms of the input length because the group names are shorter than class names.
Comment #19
sunGreat work. Now it looks really clean.
We probably want to backport this to D7 for (1) parity/consistency, (2) UX, and (3) because D7 will be around for some more years.
Comment #20
cilefen CreditAttribution: cilefen commentedRecommended commit message "Issue #2310415 by cilefen, ednawig TravisCarden: Fixed run-tests.sh does not handle the error when invalid test groups/classes are specified."
@ednawig helped.
Comment #21
webchickVery nicely done!
Committed and pushed to 8.x. Moving back to 7.x for back port.
Comment #23
cilefen CreditAttribution: cilefen commentedHere is the backport to D7.
Comment #24
sanduhrsPatch applies fine and works as expected.
Comment #25
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!
Comment #27
David_Rothstein CreditAttribution: David_Rothstein commentedI went ahead and added this to CHANGELOG.txt, since @cilefen pointed out that it's actually a new feature (in addition to a bugfix).