Skip to content
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
b026c64
First verison
SiyuGithub Jan 6, 2023
d7718fa
Modify CocoaSynchronizationContextAdapter.cs pumptill method.
SiyuGithub Jan 10, 2023
9516e6d
Modify PumpTill.
SiyuGithub Jan 10, 2023
8fbeb9a
Modify more CocoaSynchronizationContext.cs and CocoaSynchronizationCo…
SiyuGithub Jan 10, 2023
e996a5c
Modify version2
SiyuGithub Jan 10, 2023
897247b
version3
SiyuGithub Jan 10, 2023
53bf326
Version4:
SiyuGithub Jan 10, 2023
fca1e86
Version5
SiyuGithub Jan 10, 2023
0d636e2
Version6
SiyuGithub Jan 11, 2023
68e2e49
CocoaFact code clean up
SiyuGithub Jan 17, 2023
04de106
More cleanup
SiyuGithub Jan 17, 2023
0bdc567
Use Mac app as harness for xunit test runner
sandyarmstrong Jan 18, 2023
2ca5096
Delete .DS_Store files
sandyarmstrong Jan 18, 2023
b621858
Ensure macos workload is installed
sandyarmstrong Jan 18, 2023
0695648
Convert to file-scoped namespaces
sandyarmstrong Jan 18, 2023
77e6854
Cleanup
sandyarmstrong Jan 18, 2023
a7cc92c
Address a few extraneous warnings
sandyarmstrong Jan 18, 2023
5727671
Only build Xunit.StaFact.Tests.Mac in *Mac configurations
sandyarmstrong Jan 18, 2023
3cf676c
Pass configuration when restoring on Mac
sandyarmstrong Jan 18, 2023
b13aa1d
Basic workload-from-rollback provisioning
sandyarmstrong Jan 18, 2023
153f2ec
Move Xunit.StaFact.Tests.Mac to .NET 6
sandyarmstrong Jan 18, 2023
cf8b3a6
Do not build for Mac on Linux
sandyarmstrong Jan 18, 2023
565faf6
Minor fixes
sandyarmstrong Jan 19, 2023
13063f2
Testing new added TargetPath
SiyuGithub Jan 19, 2023
c2531a3
Fix Mac files not showing up in VSMac solution pad
sandyarmstrong Jan 19, 2023
3d32350
Modify TargetPath more.
SiyuGithub Jan 20, 2023
d03833a
Make another change to test TargetPath
SiyuGithub Jan 20, 2023
3871190
Trying to get macos build working on Linux
sandyarmstrong Jan 20, 2023
715bbfc
Revert "Trying to get macos build working on Linux"
sandyarmstrong Jan 20, 2023
4eb7a71
Tests the CocoaFact unit tests in the DevOps Pipeline
SiyuGithub Jan 24, 2023
bdb092f
Replace TargetPath with another path
SiyuGithub Jan 24, 2023
f4f07b8
Testing
SiyuGithub Jan 24, 2023
f081705
Edit TargetPath
SiyuGithub Jan 24, 2023
d5f36c7
Change the TargetFramework for MacOS
SiyuGithub Jan 24, 2023
8110c72
.yml file clean up
SiyuGithub Jan 24, 2023
8a3a3b6
Another attempt for running CocoaFact unit tests
SiyuGithub Jan 24, 2023
8e75d0c
Another modification for the TargetPath
SiyuGithub Jan 24, 2023
30036b3
Fix Dotnet Test System.IO.FileNotFoundException
SiyuGithub Jan 24, 2023
696daac
Fix libhostpolicy.dylib is not found issue
SiyuGithub Jan 24, 2023
bb80ec5
Adding RuntimeIdentifier to solve libhostpolicy.dylib can't be found
SiyuGithub Jan 24, 2023
09fe7b4
Testing if the test can find libhostpolicy.dylib
SiyuGithub Jan 25, 2023
1de23a6
Replace RuntimeIdentifiers with RuntimeIdentifier
SiyuGithub Jan 25, 2023
643e8bf
Code clean up
SiyuGithub Jan 25, 2023
7c62d1b
Use RuntimeIdentifer instead of RuntimeIdentifiers
SiyuGithub Jan 25, 2023
676ed17
Testing the build pipeline for the new step
SiyuGithub Jan 26, 2023
9f0cb71
Testing pipeline test build
SiyuGithub Jan 26, 2023
90dae75
Test if the dotnet.yml stopped the pipeline run
SiyuGithub Jan 26, 2023
05460db
Modified dotnet.yml
SiyuGithub Jan 26, 2023
36b599c
Fixed AppDelegate.cs
SiyuGithub Jan 26, 2023
6dcf89f
Modify the Pipeline build steps
SiyuGithub Jan 26, 2023
30d506a
Create a powerShell script for Mac unit tests
SiyuGithub Jan 26, 2023
41570f8
Modify dotnet.yml
SiyuGithub Jan 27, 2023
2a198ad
Second solution, run script for Mac unit test in dotnet.yml
SiyuGithub Jan 27, 2023
67c4d92
XML test results generating locally
sandyarmstrong Jan 27, 2023
621aeb1
Modiy the dotnet.yml and add new task to publish the xml
SiyuGithub Jan 27, 2023
b99bc9a
Clean more code in dotnet.yml.
SiyuGithub Jan 27, 2023
aec7cf0
Add more changes
SiyuGithub Jan 27, 2023
2425934
test .yml version 1
SiyuGithub Jan 27, 2023
3c99e99
test .yml Version 2
SiyuGithub Jan 27, 2023
95c3b1f
Test .yml Version 3
SiyuGithub Jan 27, 2023
a44b4c6
Test .yml Version 4
SiyuGithub Jan 27, 2023
b832272
Test .yml Version 5
SiyuGithub Jan 27, 2023
e6db7d5
Test .yml Version 6
SiyuGithub Jan 27, 2023
37e2b59
Test .yml Version 7
SiyuGithub Jan 27, 2023
ef65384
Test .yml Version 8
SiyuGithub Jan 27, 2023
72516ac
Test .ml Version 9
SiyuGithub Jan 28, 2023
d9d14bc
Test .yml Version 10
SiyuGithub Jan 28, 2023
098c9f1
Test .yml Version 11
SiyuGithub Jan 28, 2023
3efebf8
Test .yml Version 12
SiyuGithub Jan 28, 2023
89a130d
Test .yml Version 13
SiyuGithub Jan 28, 2023
d028403
Test .yml Version 14
SiyuGithub Jan 28, 2023
b1a399d
Test .yml Version 15
SiyuGithub Jan 28, 2023
7cf2afb
Test .yml Version 16
SiyuGithub Jan 30, 2023
20e3476
Test .yml Version 17
SiyuGithub Jan 30, 2023
7f8b789
Test .yml Version 18
SiyuGithub Jan 30, 2023
7ae1504
Test .yml Version 19
SiyuGithub Jan 30, 2023
52180e4
Test .yml Version 21
SiyuGithub Jan 30, 2023
9dbf6be
Test .yml Version 22
SiyuGithub Jan 30, 2023
1b9a72d
Test .yml Version 23
SiyuGithub Jan 30, 2023
aaf5ead
Test .yml Version 24
SiyuGithub Jan 30, 2023
c6e76e7
Code clean up
SiyuGithub Jan 30, 2023
d69935f
More code testing
SiyuGithub Jan 30, 2023
1321b3c
More clean up
SiyuGithub Jan 30, 2023
b62abc3
Test pipeline V1
SiyuGithub Feb 1, 2023
892ca8b
Simplify the mac test project
AArnott Feb 6, 2023
bc5256d
Revert some sln file changes
AArnott Feb 6, 2023
8f61172
revert spacing change
AArnott Feb 6, 2023
4400fed
Cleanup pipeline
AArnott Feb 6, 2023
795fe77
fix pipeline
AArnott Feb 6, 2023
f9e66fc
Avoid double-build on mac
AArnott Feb 6, 2023
6a47cdd
Use checked in workloads.json file
AArnott Feb 6, 2023
c04316a
Add notes to CONTRIBUTING about requirement to run
AArnott Feb 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,6 @@ MigrationBackup/

# dotnet tool local install directory
.store/

# File built by MacOS
.DS_Store
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<TargetingWindows Condition=" '$(TargetFramework)' == 'net472' or $(TargetFramework.EndsWith('-windows')) ">true</TargetingWindows>
<TargetingMacos Condition="$(TargetFramework.Contains('macos'))">true</TargetingMacos>

<!-- https://github.com/dotnet/msbuild/blob/main/documentation/ProjectReference-Protocol.md#setplatform-negotiation -->
<EnableDynamicPlatformResolution>true</EnableDynamicPlatformResolution>
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.5.0-release-20230105-01" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="xunit.extensibility.execution" Version="2.4.2" />
<PackageVersion Include="xunit.runner.console" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="xunit" Version="2.4.2" />
</ItemGroup>
Expand Down
21 changes: 20 additions & 1 deletion Xunit.StaFact.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31314.41
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xunit.StaFact", "src\Xunit.StaFact\Xunit.StaFact.csproj", "{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xunit.StaFact", "src\Xunit.StaFact\Xunit.StaFact.csproj", "{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3DC2EEF3-BA28-4C7A-B4F4-FCA18FBABE99}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xunit.StaFact.Tests", "test\Xunit.StaFact.Tests\Xunit.StaFact.Tests.csproj", "{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xunit.StaFact.Tests.Mac", "test\Xunit.StaFact.Tests.Mac\Xunit.StaFact.Tests.Mac.csproj", "{077DFB77-0E63-4399-BD0B-4F9D9AC80495}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B9635B8C-19E8-4D04-ACA4-A391D558D80A}"
ProjectSection(SolutionItems) = preProject
src\.editorconfig = src\.editorconfig
Expand All @@ -39,23 +41,40 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
DebugMac|Any CPU = DebugMac|Any CPU
ReleaseMac|Any CPU = ReleaseMac|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.Release|Any CPU.Build.0 = Release|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.DebugMac|Any CPU.Build.0 = Debug|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.ReleaseMac|Any CPU.ActiveCfg = Release|Any CPU
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6}.ReleaseMac|Any CPU.Build.0 = Release|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.Release|Any CPU.Build.0 = Release|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.DebugMac|Any CPU.Build.0 = Debug|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.ReleaseMac|Any CPU.ActiveCfg = Release|Any CPU
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E}.ReleaseMac|Any CPU.Build.0 = Release|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.Release|Any CPU.ActiveCfg = Release|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.DebugMac|Any CPU.ActiveCfg = Debug|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.DebugMac|Any CPU.Build.0 = Debug|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.ReleaseMac|Any CPU.ActiveCfg = Release|Any CPU
{077DFB77-0E63-4399-BD0B-4F9D9AC80495}.ReleaseMac|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8C500C20-0CD6-4257-A9ED-C571DA6E68D6} = {B9635B8C-19E8-4D04-ACA4-A391D558D80A}
{9F99EC1E-7FF7-419D-84F7-3CE96D653C2E} = {1E94DC16-537C-4D14-A201-ED3140A994EB}
{077DFB77-0E63-4399-BD0B-4F9D9AC80495} = {1E94DC16-537C-4D14-A201-ED3140A994EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DA3510A0-C12F-4470-B8A6-197F0D32CB7C}
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

- job: macOS
condition: ${{ parameters.includeMacOS }}
variables:
BuildConfiguration: ReleaseMac
pool:
vmImage: macOS-12
steps:
Expand Down
5 changes: 4 additions & 1 deletion azure-pipelines/dotnet-test-cloud.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ if ($x86) {
}

$frameworks = @()
if ($IsMacOS -or $IsLinux) {
if ($IsLinux) {
$frameworks += '-f','net6.0'
}
if ($IsMacOS) {
$frameworks += '-f','net6.0-macos'
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the changes to this file can be undone now, right?


& $dotnet test $RepoRoot `
--no-build `
Expand Down
14 changes: 13 additions & 1 deletion azure-pipelines/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ steps:

- powershell: azure-pipelines/dotnet-test-cloud.ps1 -Configuration $(BuildConfiguration) -Agent $(Agent.JobName) -PublishResults
displayName: 🧪 dotnet test
condition: and(succeeded(), ${{ parameters.RunTests }})
condition: and(and(succeeded(), ${{ parameters.RunTests }}), ne(variables['BuildConfiguration'], 'ReleaseMac'))

- script: dotnet build ./test/Xunit.StaFact.Tests.Mac/Xunit.StaFact.Tests.Mac.csproj /t:Test
displayName: 🧪 Mac-specific tests
condition: eq(variables['BuildConfiguration'], 'ReleaseMac')

- task: PublishTestResults@2
inputs:
testResultsFormat: XUnit
testResultsFiles: ./test_logs/Xunit.StaFact.Tests.Mac.xml
displayName: 'Publish Mac-specific tests Results'
condition: and(succeededOrFailed(), eq(variables['BuildConfiguration'], 'ReleaseMac'))
continueOnError: true

- powershell: azure-pipelines/variables/_pipelines.ps1
failOnStderr: true
Expand Down
18 changes: 17 additions & 1 deletion init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ if (!$NoPrerequisites) {
if ($env:OS -eq 'Windows_NT') {
$EnvVars['PROCDUMP_PATH'] = & "$PSScriptRoot\azure-pipelines\Get-ProcDump.ps1"
}

# Install specific macOS workload version in order to support usage on older .NET and macOS
$rollbackFile = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
@{
"microsoft.net.sdk.macos" = "12.3.2372/7.0.100"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you explain to me more about this requirement? Does this mean that dotnet workload restore is not enough?
I wonder too if this is somehow related to msbuild's failing import error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The macOS workload is necessary in order to target net6.0-macos. That target framework is not available without the workload being installed.

The .NET SDK makes it difficult to specify a preferred version of a given workload. You have to use a rollback file to achieve this. Without specifying the version, the SDK will pull the latest for the SDK version specified in global.json (without taking target framework into account). So, even though this project is net6.0-macos, it would be referencing a newer Microsoft.macOS.dll that is not compatible with projects using the .NET 6 SDK and an older macos workload. To fix this, we specify an older workload version that is compatible with an older .NET/workload.

I wonder too if this is somehow related to msbuild's failing import error.

Yes. dotnet workload restore appears to be broken, at least with the macOS workload. It's like it tries to load targets before they have been installed. Tomas filed a bug about it recently: dotnet/sdk#30230. It would be great if the .NET SDK team fixed that. We can't depend on dotnet restore for CI, because it would pick up the wrong workload version as described earlier, but for local development it would be very convenient.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks. That's helpful, and I've upvoted that issue.
How do dotnet workloads work when the SDK to be installed into is in an elevated location like Program Files?
It's very odd to me that init.ps1 works, but running this command outside of init fails, where workloads.json refers to the json file your init.ps1 creates:

> dotnet workload install macos --from-rollback-file workloads.json

Downloading Microsoft.macOS.Sdk.Msi.x64 (13.1.1024)
Workload installation failed. Rolling back installed packs...
Workload installation failed: One or more errors occurred. (microsoft.macos.sdk.msi.x64::13.1.1024 is not found in NuGet feeds https://api.nuget.org/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json".)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Notice it's picking 13.1.1024, which is a different version. It's newer, and I don't see it in nuget.

If you have multiple SDK versions installed, and you're running workload install from outside of a context where a global.json is specifying your SDK version, you can get different results based on whatever the default SDK is.

How do dotnet workloads work when the SDK to be installed into is in an elevated location like Program Files?

On Mac, when installing workloads to the machine-wide .NET SDK installation (/usr/local/share/dotnet), you have to use sudo to elevate. Presumably something similar is needed on Windows?

@AArnott AArnott Feb 7, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I do have the 7.0.200 installed, as of this morning when a VS update installed it. But all my dotnet workload install attempts were within the directory containing global.json, so evidently my repo's 7.0.101 constraint wasn't effective at retaining behavior from that SDK in this regard.

Windows doesn't need sudo to elevate. It prompts with interactive UI as needed.

The failures I'm seeing turn out to come from a collection of bugs in the SDK around this area. The do not show up when DOTNET_ROOT is set, which is why it works in non-elevated scenarios.

} | ConvertTo-Json | Set-Content -Path $rollbackFile

try {
dotnet workload install macos --from-rollback-file $rollbackFile
}
finally {
Remove-Item $rollbackFile
}
}

# Workaround nuget credential provider bug that causes very unreliable package restores on Azure Pipelines
Expand All @@ -77,7 +90,10 @@ try {

if (!$NoRestore -and $PSCmdlet.ShouldProcess("NuGet packages", "Restore")) {
Write-Host "Restoring NuGet packages" -ForegroundColor $HeaderColor
dotnet restore
if ($IsMacOS) {
$restoreArgs = "/p:Configuration=DebugMac"
}
dotnet restore $restoreArgs
if ($lastexitcode -ne 0) {
throw "Failure while restoring packages."
}
Expand Down
16 changes: 16 additions & 0 deletions src/Xunit.StaFact/Mac/CocoaFactAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using Xunit.Sdk;

namespace Xunit;

/// <summary>
/// Identifies an xunit test that starts on with a <see cref="System.Threading.SynchronizationContext"/>
/// running on <see cref="Foundation.NSRunLoop.Main"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Xunit.Sdk.CocoaFactDiscoverer", ThisAssembly.AssemblyName)]
public class CocoaFactAttribute : FactAttribute
{
}
16 changes: 16 additions & 0 deletions src/Xunit.StaFact/Mac/CocoaTheoryAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using Xunit.Sdk;

namespace Xunit;

/// <summary>
/// Identifies an xunit theory that starts on with a <see cref="System.Threading.SynchronizationContext"/>
/// running on <see cref="Foundation.NSRunLoop.Main"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[XunitTestCaseDiscoverer("Xunit.Sdk.CocoaTheoryDiscoverer", ThisAssembly.AssemblyName)]
public class CocoaTheoryAttribute : TheoryAttribute
{
}
35 changes: 35 additions & 0 deletions src/Xunit.StaFact/Sdk.Mac/CocoaFactDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;

namespace Xunit.Sdk;

/// <summary>
/// The discovery class for <see cref="CocoaFactDiscoverer"/>.
/// </summary>
public class CocoaFactDiscoverer : FactDiscoverer
{
private readonly IMessageSink diagnosticMessageSink;

/// <summary>
/// Initializes a new instance of the <see cref="CocoaFactDiscoverer"/> class.
/// </summary>
/// <param name="diagnosticMessageSink">The diagnostic message sink.</param>
public CocoaFactDiscoverer(IMessageSink diagnosticMessageSink)
: base(diagnosticMessageSink)
{
this.diagnosticMessageSink = diagnosticMessageSink;
}

protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
if (testMethod.Method.ReturnType.Name == "System.Void" &&
testMethod.Method.GetCustomAttributes(typeof(AsyncStateMachineAttribute)).Any())
{
return new ExecutionErrorTestCase(this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod, "Async void methods are not supported.");
}

return new UITestCase(UITestCase.SyncContextType.Cocoa, this.diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod);
}
}
Loading