Add unittest framework and some dependency tests#2759
Merged
thewilsonator merged 8 commits intodlang:masterfrom Dec 27, 2023
Merged
Add unittest framework and some dependency tests#2759thewilsonator merged 8 commits intodlang:masterfrom
thewilsonator merged 8 commits intodlang:masterfrom
Conversation
The parameter names were repeating the type name, which in a language like D does not make sense.
This is consistent with the naming of other factory functions.
This would make moving this unittest to another module easier.
This would make extending TestDub much easier by exposing the class fields, the common initialization routine, and a configuration point. It also allows us to move TestDub to another module.
As we will begin to inject more dependencies, having a base module makes sense.
In order to make the `Dub` class properly unittest-able, we need to be able to use a non-default `PackageSupplier`, in particular one that would not hit the registry or the filesystem. This can be achieved by moving a free function to a method and having derived class override it, as shown in this commit.
We want to allow one to provide their own PackageManager instance. There are 3 standard ways of doing this: 1) Provide an instance in the constructor; 2) Provide a template parameter; 3) Use a hook that is called by the constructor; We are going with option 3 as the other two methods have clear downsides: Option 1 exposes too much of the implementation detail (even if it can be wrapped by another constructor) and makes the dependency to internal state hard / impossible (we need to instantiate SpecialDirs then load the config that may modify SpecialDirs). Option 2 is even worse as it exposes implementation details to the type and makes OOP impossible (e.g. method accepting a `PackageManager` need to be changed). Option 3 is the best compromise, as its main downside is that it requires to create a new `Dub` type, however that is already required due to the amount of configuration points that do IO (loadConfig, determineDefaultCompiler, computePkgSuppliers).
Dub has always been notoriously hard to test due to the amount of IO it does. Over the past few years, I have progressively refactored it to allow dependency injection to take place, which this finally put into action. By overriding the `PackageManager`, `PackageSupplier`, and a few strategic functions, we can start to unittest Dub's behavior solely in unittests. This should hopefully tremendously helps with adding regression tests for the package manager side of Dub (the build side still need work to have similar capabilities).
Total deprecations: 17 Total warnings: 0 Build statistics: statistics (-before, +after)
-executable size=5310288 bin/dub
+executable size=5314464 bin/dub
rough build time=66sFull build output |
Member
Author
Yeah that's a DMD bug. Even though we're in a deprecated context, |
thewilsonator
approved these changes
Dec 27, 2023
maxhaton
reviewed
Dec 28, 2023
Comment on lines
+104
to
+115
| public Package makeTestPackage(string str, Version vers, PackageFormat fmt = PackageFormat.json) | ||
| { | ||
| import dub.recipe.io; | ||
| final switch (fmt) { | ||
| case PackageFormat.json: | ||
| auto recipe = parsePackageRecipe(str, "dub.json"); | ||
| recipe.version_ = vers.toString(); | ||
| return new Package(recipe); | ||
| case PackageFormat.sdl: | ||
| auto recipe = parsePackageRecipe(str, "dub.sdl"); | ||
| recipe.version_ = vers.toString(); | ||
| return new Package(recipe); |
Member
There was a problem hiding this comment.
it github broken or is the indentation all screwed up here
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.
See each commit for details. In the long run we might want to go with a full filesystem abstraction, especially when it comes to testing the building side, but that should allow us to write some good tests for over half of Dub.