Skip to content
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

Eliminate string constructor for TestPackage #920

Merged
merged 4 commits into from
Mar 23, 2021
Merged

Conversation

CharliePoole
Copy link
Collaborator

Fixes #889

This fix enables us to move forward without having to support multiple constructors for TestPackage, simplifying tests and new feature development. It's not intended as the last word on the interface provided by TestPackage, which we will need to rethink somewhat for the design of the final 4.0 release. This is covered in issues #885 and #919.

The old string constructor created a package with a file name but no subpackages. The list constructor created a package with no file name and subpackages. Named packages are only used internally by the engine, so that constructor has now been replaced by the Named() modifier. Addition of a params overload makes the TestPackage constructor work the same whether one or multiple test files are used.

@CharliePoole
Copy link
Collaborator Author

Although this is only a refactoring toward 4.0, I've asked for review because of substantive changes to the tests. I'll be happy if someone just looks those over and agrees that what I've done is the way to go. In fact, the tests of what runner is used in various circumstances represent what is currently done. If that's not what we want done in some case, we should flag that as a separate issue.

Copy link
Member

@ChrisMaddock ChrisMaddock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Charlie,

The changes look good - but I'm wondering if we can come up with a more explicit API than the Named() method - I feel like whether a package is named or not is a consequence of it's place in the structure, rather than key characteristic.

I think I might have stumbled across an alternative while reviewing this - let me know what you think.

Inconclusive = 2 * 1,
Skipped = 2 * 7
}));
// TODO: Get extensions working - need new releases due to interface change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth filing an issue for this? I wouldn't want it to be forgotten. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be doing at least the NUnit Project as a new release while we work on this. Don't want to do too much until the API is established.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it may only be the NUnit Project loader that has a problem... it uses the old string constructor, which now looks like a params string[] constructor!

src/NUnitEngine/nunit.engine.api/TestPackage.cs Outdated Show resolved Hide resolved
Settings = new Dictionary<string,object>();
SubPackages = new List<TestPackage>();
}
InitializeSubPackages(testFiles);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we already had a params ctor for this! Do we need both constructors, if we're changing the API for v4 anyway? I guess there's no major drawback, other than being a less clean and simple API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we didn't because it would never have been used for a single string argument - the named constructor would have been used. I added it primarily for ease of use in tests, but then I thought users like ease of use as well. We could have it as the only constructor, but would have to change two or three places where we use the IList constructor. I can go any way you like on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I prefer the clean API with a single constructor, over the convenience of both.

It's not one I feel incredibly strongly on though - if you particularly disagree here. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference in the abstract, but when I tried out each of the two alternatives separately, I was forced to write ugly code in one place or another. Runners and project loaders would usually have some kind of dynamic list and would be forced to construct an array from it. OTOH the 39 uses of the params constructor would have to add a new [] construct to their code.

@CharliePoole
Copy link
Collaborator Author

I guess the alternative to Named(string) was AddSubPackages(string). As I've explained, extension authors need to create full packages, including a name and settings. One option is to make FullName settable and I tried that for a while. But some sort of fluent modifier seemed more natural to me.

@ChrisMaddock
Copy link
Member

I guess the alternative to Named(string) was AddSubPackages(string). As I've explained, extension authors need to create full packages, including a name and settings. One option is to make FullName settable and I tried that for a while. But some sort of fluent modifier seemed more natural to me.

Interested in what anyone on @nunit/engine-team would think on this one! ☝️ I think we're into preference territory here - and it's a case where mine and your preferences differ, Charlie! 😄

@CharliePoole
Copy link
Collaborator Author

I've gone with the "AddSubPackage" suggestion in place of "Named".

@CharliePoole
Copy link
Collaborator Author

Ready for re-review

@ChrisMaddock ChrisMaddock merged commit 9a89dc8 into dev-4.0 Mar 23, 2021
@ChrisMaddock ChrisMaddock deleted the issue-889 branch March 23, 2021 19:26
@ChrisMaddock
Copy link
Member

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants