Repository navigation
feat: run tests for files changed in the Git working tree - #386
Merged
Merged
Conversation
Add a "Run Tests for Changed Files" command on Java projects: it asks Git for the files changed since the last commit (staged, unstaged and untracked), maps them to their tests, and runs those tests. - a changed test file is run as is - for a changed class, all its corresponding test cases are run (abstract test cases are replaced by their concrete subclasses) - tests are grouped by test type so that each group is run by the proper test runner - when nothing can be run, the user is told why Git support lives in org.moreunit.core.git: a small command runner interface, its native implementation (with a timeout, and --no-optional-locks to avoid interfering with other tools), and the parsing of "git status --porcelain=v1 -z".
Replace the external "git" process by JGit, on which EGit is built: no dependency on a git executable anymore, and the repositories EGit has already opened are reused when EGit is installed. - GitRepositories locates the repository of a workspace resource: it asks EGit first (through the public GitInfo adapter, which handles linked working trees, submodules and non-standard layouts), then falls back to JGit's FileRepositoryBuilder. - GitWorkingTreeChanges reports the changed files of a working tree (staged, unstaged, untracked, deleted and conflicting) through the JGit status command. - GitRepository is a small handle which closes the repository only when MoreUnit opened it: the ones owned by EGit are left open. JGit and EGit are optional dependencies of the plug-in (optional Import-Package), and the "Run Tests for Changed Files" command is hidden when JGit is not installed. The EGit update site is part of the target platform so that the build and the tests can use them.
EGit and JGit become required dependencies of MoreUnit For Java instead of optional ones: - org.moreunit requires org.eclipse.egit.core and org.eclipse.jgit, and org.moreunit.feature declares the same requirements so that p2 installs them together with MoreUnit. - the code can rely on them: GitSupport (bundle detection) and EgitRepositories (lazy loading of EGit types) are removed, and the "Git support is not installed" message with them. - the closest repository is now looked up from the project location with JGit first (always up to date), and EGit is asked through the GitInfo adapter when that lookup finds nothing, for instance when the project is connected to a repository which is not one of its parent directories. - the test bundles require EGit/JGit so that the test runtime resolves them.
The previous test needed the "git" executable and left files which cannot be deleted on Windows when git is missing, failing the test with "Failed to close extension context". The new test writes the ".git" file of a linked working tree itself, so it runs everywhere.
JGit may keep a file handle for a short while after a repository is closed, which makes the deletion of its directory fail on Windows and, in turn, fails the test with 'Failed to close extension context'. The Git tests now delete their temporary files themselves, retrying a few times, and JUnit is told not to clean the directory up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a Run Tests for Changed Files command to Java projects: MoreUnit asks EGit/JGit for the files that changed since the last commit, finds the tests that correspond to them, and runs those tests.
Right-click a Java project in the Package Explorer → MoreUnit → Run Tests for Changed Files. The command is also available from
org.moreunit.runtestsforchangedfiles(no default shortcut, it can be bound in Preferences → General → Keys), so it also works from the editor with the project of the open file.Behaviour
gitexecutable is spawned.Git integration
EGit is now a required dependency of the MoreUnit For Java feature:
org.moreunitrequiresorg.eclipse.egit.coreandorg.eclipse.jgit(Require-Bundle), andorg.moreunit.featuredeclares the same requirements, so p2 installs them together with MoreUnit.GitRepositorieslocates the repository of a workspace resource: the closest repository is looked up from the project location with JGit (always up to date), and EGit is asked through the publicorg.eclipse.egit.core.info.GitInfoadapter when that lookup finds nothing — for instance when the project has been connected to a repository which is not one of its parent directories.GitWorkingTreeChangesreads the changed files through the JGit status command.GitRepositoryis a handle which closes the repository only when MoreUnit opened it: the ones owned by EGit are left open.org.moreunit.gitis exported withx-friendsfororg.moreunit.test, so the tests can exercise it directly.Target platform
The EGit update site (
https://download.eclipse.org/egit/updates/) is added toorg.moreunit.build/eclipse-latest.targetwith theorg.eclipse.jgitandorg.eclipse.egit.coreunits, so the build and the tests can compile and run against them.Tests
All green locally:
GitWorkingTreeChangesTest(8 tests),GitRepositoriesTest(4) andGitChangedFilesProviderTest(4) — the Git ones run against real temporary repositories created with JGitChangedTestsFinderTest(5),RunChangedTestsActionExecutorTest(7),JavaProjectsTest(4)RunChangedTestsSWTBotTest(1) asserts the menu entry is present on a Java projectclean verify, SWTBot excluded as in CI): BUILD SUCCESS, 903 tests inorg.moreunit.test, 0 failureThe help page (
org.moreunit.plugin/help/documentation.html) documents the new command.Notes
gitexecutable, then JGit as an optional dependency; this final version uses JGit/EGit as a required dependency.