Skip to content

Add SkipOnPlatform attribute to Microsoft.DotNet.XUnitExtensions#7184

Merged
akoeplinger merged 2 commits intodotnet:mainfrom
akoeplinger:add-skiponplatform
Apr 3, 2021
Merged

Add SkipOnPlatform attribute to Microsoft.DotNet.XUnitExtensions#7184
akoeplinger merged 2 commits intodotnet:mainfrom
akoeplinger:add-skiponplatform

Conversation

@akoeplinger
Copy link
Member

In dotnet/runtime we have a bunch of test assemblies that don't make sense on some platforms, e.g. Browser.
Right now we're skipping them via [SkipOnMono("reason", TestPlatforms.Browser)] but there's nothing that inherently ties this to Mono other than the current implementation.

Add a more generic SkipOnPlatform attribute that we can use instead.

In dotnet/runtime we have a bunch of test assemblies that don't make sense on some platforms, e.g. Browser.
Right now we're skipping them via `[SkipOnMono("reason", TestPlatforms.Browser)]` but there's nothing that inherently ties this to Mono other than the current implementation.

Add a more generic SkipOnPlatform attribute that we can use instead.
@akoeplinger akoeplinger requested a review from safern April 2, 2021 16:13
@safern
Copy link
Member

safern commented Apr 2, 2021

It seems like this attribute is equivalent as the PlatformSpecific one but being reversed. Does it make sense to add a new one instead of just doing:

[assembly: PlatformSpecific(~TestPlatforms.Browser)]

@akoeplinger
Copy link
Member Author

PlatformSpecificAttribute isn't allowed at the assembly-level today (not sure if there was a reason for that).

Additionally it doesn't have a reason argument so we'd need to turn them into comments.

I personally also don't like the double inversion of "platform specific" + "enum bit flip".

I don't feel strongly though so if you think another attribute isn't needed I won't object :)

@safern
Copy link
Member

safern commented Apr 2, 2021

I wanted to get your take on expanding platformspecific to the assembly level and taking a reason.

The reason I was suggesting that was because all our tests when we want to skip say on Windows or Browser we use that approach so I was trying to be consistent with what we have. If we add this attribute we might endup in a combine mode, but I think it is fine adding this new attribute as sometimes the enum bit flip is kind of confusing.

{
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
TestPlatforms testPlatforms = TestPlatforms.Any;
Copy link
Member

Choose a reason for hiding this comment

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

This means that if for any reason we can't get the argument or get something else (I don't know how it would happen), we would skip the tests on all platforms. Should we instead initialize to, (TestPlatforms)0?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is copied from

TestPlatforms testPlatforms = TestPlatforms.Any;
(which was also copied to SkipOnMonoDiscoverer).

I agree with your suggestion, will change it.

Copy link
Member

Choose a reason for hiding this comment

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

Right, that is because SkipOnMonoDiscoverer supports skipping on Mono on any Platform (by not providing any test platform).

@akoeplinger
Copy link
Member Author

The reason I was suggesting that was because all our tests when we want to skip say on Windows or Browser we use that approach so I was trying to be consistent with what we have.

My intention is to switch instances of [PlatformSpecific(~TestPlatforms.Browser)] to this new attribute :)

@safern
Copy link
Member

safern commented Apr 2, 2021

My intention is to switch instances of [PlatformSpecific(~TestPlatforms.Browser)] to this new attribute :)

Sounds good! Thanks for adding this new attribute, makes some things easier and clearer.

@akoeplinger akoeplinger merged commit 1bfe912 into dotnet:main Apr 3, 2021
@akoeplinger akoeplinger deleted the add-skiponplatform branch April 3, 2021 09:30
akoeplinger added a commit to akoeplinger/arcade that referenced this pull request Apr 6, 2021
While looking at doing the conversion in dotnet/runtime after dotnet#7184 I noticed that having the reason argument reads weird, it's better to have the platform as the first argument so it reads more like a sentence.

E.g. instead of

```csharp
[SkipOnPlatform("System.Net.Security is not supported on this platform.", TestPlatforms.Browser)]
```

we have

```csharp
[SkipOnPlatform(TestPlatforms.Browser, "System.Net.Security is not supported on this platform.")]
```

Also allow multiple attributes since the skip reason can be quite different between platforms.
akoeplinger added a commit that referenced this pull request Apr 6, 2021
While looking at doing the conversion in dotnet/runtime after #7184 I noticed that having the reason argument reads weird, it's better to have the platform as the first argument so it reads more like a sentence.

E.g. instead of

```csharp
[SkipOnPlatform("System.Net.Security is not supported on this platform.", TestPlatforms.Browser)]
```

we have

```csharp
[SkipOnPlatform(TestPlatforms.Browser, "System.Net.Security is not supported on this platform.")]
```

Also allow multiple attributes since the skip reason can be quite different between platforms.
akoeplinger added a commit to akoeplinger/arcade that referenced this pull request Apr 12, 2021
…net#7184)

* Add SkipOnPlatform attribute to Microsoft.DotNet.XUnitExtensions

In dotnet/runtime we have a bunch of test assemblies that don't make sense on some platforms, e.g. Browser.
Right now we're skipping them via `[SkipOnMono("reason", TestPlatforms.Browser)]` but there's nothing that inherently ties this to Mono other than the current implementation.

Add a more generic SkipOnPlatform attribute that we can use instead.

* PR feedback
akoeplinger added a commit to akoeplinger/arcade that referenced this pull request Apr 12, 2021
While looking at doing the conversion in dotnet/runtime after dotnet#7184 I noticed that having the reason argument reads weird, it's better to have the platform as the first argument so it reads more like a sentence.

E.g. instead of

```csharp
[SkipOnPlatform("System.Net.Security is not supported on this platform.", TestPlatforms.Browser)]
```

we have

```csharp
[SkipOnPlatform(TestPlatforms.Browser, "System.Net.Security is not supported on this platform.")]
```

Also allow multiple attributes since the skip reason can be quite different between platforms.
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