Skip to content

Add support for .NET5.0 OSPlatformAttribute - #3926

Merged
stevenaw merged 4 commits into
nunit:masterfrom
manfred-brands:supportedosplatform
Oct 24, 2021
Merged

stevenaw merged 4 commits into
nunit:masterfrom
manfred-brands:supportedosplatform

Conversation

@manfred-brands

@manfred-brands manfred-brands commented Sep 6, 2021 •

Copy link
Copy Markdown
Member

Fixes #3866

Approach taken is to convert a SupportedOSPlatformAttribute into a PlatformAttribute with Include and
a UnsupportedOSPlatformAttribute into a PlatformAttribute with Exclude.

Here the passed in PlatformName is translated into a Platform that is supported by NUnit.
Currently only supported are:

.NET 5 PlatformName NUnit Platform
Windows Win
Windows[0-9] Windows[0-9]
OsX, MacOS MacOsX
Linux Linux

Other names are passed verbatim, like: Android, Browser.
These will result in invalid Platform name errors in NUnit.

@manfred-brands
manfred-brands marked this pull request as ready for review September 6, 2021 08:41

@Dreamescaper Dreamescaper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks fine by me.
I've only left a minor nitpicks.

Comment thread src/NUnitFramework/framework/Attributes/OSPlatformTranslator.cs Outdated
/// </summary>
/// <param name="possibleSupportedOSPlatformAttribute"></param>
/// <returns></returns>
public static object Translate(object possibleSupportedOSPlatformAttribute)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Personally I would prefer something like that:

public static bool TryTranslate(object possibleSupportedOSPlatformAttribute, out PlatformAttribute platformAttribute);

That would make it more obvious what this method returns.

And then use it smth like that:

OSPlatformTranslator.TryTranslate(attribute, out var platformAttribute) ? platformAttribute : attribute

(Your option is more concise though, so I don't insist to hard)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because of #3941 I have to changes this, combining multiple OSPlatformAttribute into a single PlatformAttribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for explaining this, I was going to ask why the need to handle PlatformAttribute in the translator. Are you saying that this PR will also fix #3941 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@stevenaw This PR will as a side effect combine multiple Platform attributes into one, thereby 'fixing' #3941. It depends if the owners want that or change the AllowMultiple flag.
The main reason I combine it here is for code that currently use both SupportOSPlatform and Platform. The first for the .NET compiler, the 2nd for nunit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@manfred-brands Sorry it's taken me a few days to get back to you. That makes a lot of sense, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is fix to fix #3941 and keep the AllowMultiple as it is.

@manfred-brands

Copy link
Copy Markdown
Member Author

@mikkelbu MacOS builds fail with "The repository primary signature validity period has expired". Also fails in 'master'.

@rprouse

rprouse commented Sep 28, 2021

Copy link
Copy Markdown
Member

Let's ignore the MacOS failures for now. It looks like a problem with the build images being out of date. I can override and merge.

@mikkelbu

mikkelbu commented Sep 28, 2021 •

Copy link
Copy Markdown
Member

I also noticed the problems with builds which was also why I manually triggered https://nunit.visualstudio.com/NUnit/_build/results?buildId=4256&view=results, but I've not had time to look at it the last couple of week.

Regarding failures like this I proposed to run the builds every day in #3928, but so far I've not heard any feedback.

EDIT: I've made a PR that should fix the CI on MacOS.

Comment thread src/NUnitFramework/framework/Attributes/OSPlatformTranslator.cs

@stevenaw stevenaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@manfred-brands Thanks for investigating + putting this PR up! I have one suggestion that may help with ensuring these tests continue to run in the future

Comment thread src/NUnitFramework/tests/Attributes/OSPlatformAttributeTests.cs Outdated
Perform a few compiler suggested changes.
@stevenaw

stevenaw commented Oct 5, 2021

Copy link
Copy Markdown
Member

Thanks for your contribution @manfred-brands ! We'll need a second approval before the PR can be merged.

@stevenaw
stevenaw merged commit d8e06e8 into nunit:master Oct 24, 2021
@stevenaw

Copy link
Copy Markdown
Member

LGTM. Thanks for your contribution @manfred-brands !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SupportedOSPlatform

5 participants