Problem/Motivation

#2869120: run-tests.sh ignores classes if they have whitespace before the declaration using --directory was committed without a test. This means we can't discover whether future changes will be regressions.

TestDiscovery already has a scanDirectory() method which has very few dependencies, but which requires that we have already built a class loader namespace map, which we don't have at that level of run-tests.sh, and might be something we're trying to avoid during the --directory scan.

Proposed resolution

Move the code block dealing with --directory to a class named something like DirectoryTestFinder.

This code can then be unit tested using vfsStream or other mocking, according to the many test cases written in that code block's inline comments:

      // Extract test case class names from specified directory.
      // Find all tests in the PSR-X structure; Drupal\$extension\Tests\*.php
      // Since we do not want to hard-code too many structural file/directory
      // assumptions about PSR-0/4 files and directories, we check for the
      // minimal conditions only; i.e., a '*.php' file that has '/Tests/' in
      // its path.
      // Ignore anything from third party vendors.
        // '/Tests/' can be contained anywhere in the file's path (there can be
        // sub-directories below /Tests), but must be contained literally.
        // Case-insensitive to match all Simpletest and PHPUnit tests:
        // ./lib/Drupal/foo/Tests/Bar/Baz.php
        // ./foo/src/Tests/Bar/Baz.php
        // ./foo/tests/Drupal/foo/Tests/FooTest.php
        // ./foo/tests/src/FooTest.php
 

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#11 interdiff.txt1.28 KBmile23
#11 2871289_10.patch9.13 KBmile23
#4 2871289_4.patch9.13 KBmile23

Comments

Mile23 created an issue. See original summary.

mile23’s picture

mile23’s picture

Issue summary: View changes
mile23’s picture

Version: 8.4.x-dev » 8.3.x-dev
Status: Active » Needs review
StatusFileSize
new9.13 KB

Try this on.

I got most of the way through before I realized I was working on 8.3.x. Unfortunately, the patch doesn't apply to 8.4.x, so if this is too disruptive we can move it to 8.4.x.

It's almost a bug report since #2869120: run-tests.sh ignores classes if they have whitespace before the declaration using --directory happened without a test.

Status: Needs review » Needs work

The last submitted patch, 4: 2871289_4.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review
berdir’s picture

The same is true about everything in run-tests.sh. Do we really want to completely refactor that into testable code when we plan to eventually replace it completely with phpunit anyway?

mile23’s picture

If there's a plan to remove run-tests.sh I haven't seen an issue about it.

I have seen these though: #2866082: [Plan] Roadmap for Simpletest #2867818: Create version of run-tests.sh tuned for running PHPUnit #2626986: [meta] Improvements to run-tests.sh

Mixologic’s picture

We cannot replace run-tests.sh with phpunit unless we're willing to accept a few of regressions:
1. When a phpunit test has a segfault, and either php or apache core dumps, testing just stops, and you will not know exactly which test it is that caused it to crash.
2. We need a way to list all of the testing *files* that are included so that we can know if a patch or commit has made changes to tests, that way have the ability to run just changed tests first.
3. Tests will take about 32 times as long to run, because phpunit does not offer a way to efficiently parallelize tests across multiple processors or multiple machines. They will also cost 32x as much.

Thats not to say we cant refactor run-tests.sh into a tiny library that only has those few things as functionality, just that we cannot use pure phpunit all on its own without giving up those features, and #3 is pretty much non-optional.

mile23’s picture

Updated to fix CS errors.

Not sure what to do about the NOWDOC indentation problem.

mile23’s picture

StatusFileSize
new9.13 KB
new1.28 KB

Ugh. Missed the files. :-)

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mile23’s picture

Status: Needs review » Active

The patch in #11 no longer applies. The reason is that Drupal core now uses this line to do the directory discovery, after #3035312: Move file_scan_directory() to file_system service:

foreach (\Drupal::service('file_system')->scanDirectory($directory, '/\.php$/', $ignore) as $file) {

That is, the system under test is discovering the tests.

That means that while there's probably test coverage for the file_system service, it also means that the test coverage for the file_system service is potentially discovered by the file_system service.

Therefore it's impossible to ascertain whether the goal of test coverage for run-test's --directory feature is met, though we could probably just go on assuming our quality is high without any data, which seems to be The Drupal Way.

It's also unclear whether anyone really wants to go about gathering the data which would help us understand the quality of the product, so I'm going to set this issue as Active. If anyone wants to champion this cause they can pick it up.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.