-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unittest framework and some dependency tests #2759
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=66s Full build output
|
Yeah that's a DMD bug. Even though we're in a deprecated context, |
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it github broken or is the indentation all screwed up here
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.