Skip to content

Commit

Permalink
Merge pull request #98 from AArnott/close60
Browse files Browse the repository at this point in the history
Add support for `TheoryData<T>` in `CombinatorialMemberDataAttribute`
  • Loading branch information
AArnott authored Oct 2, 2024
2 parents 944ba62 + 988d1e3 commit 2739415
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Validation" Version="2.5.51" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand All @@ -18,4 +19,4 @@
<GlobalPackageReference Include="Nullable" Version="1.3.1" />
<GlobalPackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556" />
</ItemGroup>
</Project>
</Project>
7 changes: 6 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ trigger:
- azure-pipelines/release.yml

parameters:
- name: includeMacOS
displayName: Build on macOS
type: boolean
default: false # macOS is often bogged down in Azure Pipelines
- name: RunTests
displayName: Run tests
type: boolean
Expand All @@ -22,10 +26,11 @@ variables:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
BuildConfiguration: Release
codecov_token: 4dc9e7e2-6b01-4932-a180-847b52b43d35 # Get a new one from https://codecov.io/
ci_feed: https://pkgs.dev.azure.com/andrewarnott/_packaging/CI/nuget/v3/index.json # Azure Artifacts feed URL
ci_feed: https://pkgs.dev.azure.com/andrewarnott/OSS/_packaging/PublicCI/nuget/v3/index.json # Azure Artifacts feed URL
NUGET_PACKAGES: $(Agent.TempDirectory)/.nuget/packages/

jobs:
- template: azure-pipelines/build.yml
parameters:
includeMacOS: ${{ parameters.includeMacOS }}
RunTests: ${{ parameters.RunTests }}
58 changes: 55 additions & 3 deletions azure-pipelines/build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
parameters:
- name: windowsPool
type: object
default:
vmImage: windows-2022
- name: includeMacOS
type: boolean
- name: RunTests
type: boolean
default: true

jobs:
- job: Linux
pool:
vmImage: Ubuntu 20.04
- job: Windows
pool: ${{ parameters.windowsPool }}
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
Expand All @@ -20,5 +25,52 @@ jobs:
parameters:
RunTests: ${{ parameters.RunTests }}

- job: Linux
pool:
vmImage: Ubuntu 20.04
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
clean: true
- template: install-dependencies.yml
- template: dotnet.yml
parameters:
RunTests: ${{ parameters.RunTests }}
- script: dotnet format --verify-no-changes --no-restore
displayName: 💅 Verify formatted code

- job: macOS
condition: ${{ parameters.includeMacOS }}
pool:
vmImage: macOS-12
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
clean: true
- template: install-dependencies.yml
- template: dotnet.yml
parameters:
RunTests: ${{ parameters.RunTests }}

- job: WrapUp
dependsOn:
- Windows
- Linux
- macOS
pool: ${{ parameters.windowsPool }} # Use Windows agent because PublishSymbols task requires it (https://github.com/microsoft/azure-pipelines-tasks/issues/13821).
condition: succeededOrFailed()
steps:
- checkout: self
fetchDepth: 0 # avoid shallow clone so nbgv can do its work.
clean: true
- template: install-dependencies.yml
parameters:
initArgs: -NoRestore
- template: publish-symbols.yml
parameters:
includeMacOS: ${{ parameters.includeMacOS }}
- ${{ if parameters.RunTests }}:
- template: publish-codecoverage.yml
parameters:
includeMacOS: ${{ parameters.includeMacOS }}
- template: publish-deployables.yml
6 changes: 5 additions & 1 deletion azure-pipelines/publish-deployables.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
steps:
- powershell: dotnet nuget push "$(Resolve-Path '$(Build.ArtifactStagingDirectory)\deployables-Linux\')*.nupkg" -s $(ci_feed) -k azdo --skip-duplicate
- download: current
displayName: 🔻 Download deployables
artifact: deployables-Linux

- powershell: dotnet nuget push "$(Resolve-Path '$(Pipeline.Workspace)\deployables-Linux\')*.nupkg" -s $(ci_feed) -k azdo --skip-duplicate
displayName: 📦 Push packages to CI feed
condition: and(succeeded(), ne(variables['ci_feed'], ''), ne(variables['Build.Reason'], 'PullRequest'))
46 changes: 44 additions & 2 deletions azure-pipelines/publish-symbols.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
parameters:
includeMacOS:

steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: symbols-Windows
path: $(Pipeline.Workspace)/symbols/Windows
displayName: 🔻 Download Windows symbols
continueOnError: true
- task: DownloadPipelineArtifact@2
inputs:
artifact: symbols-Linux
path: $(Pipeline.Workspace)/symbols/Linux
displayName: 🔻 Download Linux symbols
continueOnError: true
- task: DownloadPipelineArtifact@2
inputs:
artifact: symbols-macOS
path: $(Pipeline.Workspace)/symbols/macOS
displayName: 🔻 Download macOS symbols
continueOnError: true
condition: ${{ parameters.includeMacOS }}

- task: DownloadPipelineArtifact@2
inputs:
artifact: test_symbols-Windows
path: $(Pipeline.Workspace)/test_symbols/Windows
displayName: 🔻 Download Windows test symbols
continueOnError: true
- task: DownloadPipelineArtifact@2
inputs:
artifact: test_symbols-Linux
path: $(Pipeline.Workspace)/test_symbols/Linux
displayName: 🔻 Download Linux test symbols
continueOnError: true
- task: DownloadPipelineArtifact@2
inputs:
artifact: test_symbols-macOS
path: $(Pipeline.Workspace)/test_symbols/macOS
displayName: 🔻 Download macOS test symbols
continueOnError: true
condition: ${{ parameters.includeMacOS }}

- task: PublishSymbols@2
inputs:
SymbolsFolder: $(Build.ArtifactStagingDirectory)/symbols
SymbolsFolder: $(Pipeline.Workspace)/symbols
SearchPattern: '**/*.pdb'
IndexSources: false
SymbolServerType: TeamServices
displayName: 📢 Publish symbols

- task: PublishSymbols@2
inputs:
SymbolsFolder: $(Build.ArtifactStagingDirectory)/test_symbols
SymbolsFolder: $(Pipeline.Workspace)/test_symbols
SearchPattern: '**/*.pdb'
IndexSources: false
SymbolServerType: TeamServices
Expand Down
15 changes: 12 additions & 3 deletions src/Xunit.Combinatorial/CombinatorialMemberDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,19 @@ public CombinatorialMemberDataAttribute(string memberName, params object?[]? arg
/// <returns>The generic type argument for (one of) the <see cref="IEnumerable{T}"/> interface)s) implemented by the <paramref name="enumerableType"/>.</returns>
private static TypeInfo? GetEnumeratedType(Type enumerableType)
{
if (enumerableType.IsGenericType && enumerableType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
if (enumerableType.IsGenericType)
{
Type[] enumerableGenericTypeArgs = enumerableType.GetTypeInfo().GetGenericArguments();
return enumerableGenericTypeArgs[0].GetTypeInfo();
if (enumerableType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
Type[] enumerableGenericTypeArgs = enumerableType.GetTypeInfo().GetGenericArguments();
return enumerableGenericTypeArgs[0].GetTypeInfo();
}

if (enumerableType.GetGenericTypeDefinition() == typeof(TheoryData<>))
{
Type[] enumerableGenericTypeArgs = enumerableType.GetTypeInfo().GetGenericArguments();
return enumerableGenericTypeArgs[0].GetTypeInfo();
}
}

foreach (Type implementedInterface in enumerableType.GetTypeInfo().ImplementedInterfaces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class CombinatorialMemberDataSampleUses
public static readonly IEnumerable<Guid> GuidFieldValues = Enumerable.Range(0, 5).Select(_ => Guid.NewGuid());
#pragma warning restore SA1202 // Elements should be ordered by access

public static readonly TheoryData<MyTestCase> MyTestCases = new(
new MyTestCase(1, "Foo"),
new MyTestCase(2, "Bar"));

public static IEnumerable<int> IntPropertyValues => GetIntMethodValues();

public static IEnumerable<Guid> GuidPropertyValues => GetGuidMethodValues();
Expand Down Expand Up @@ -84,4 +88,18 @@ public void CombinatorialMemberDataFromFields(
{
Assert.True(true);
}

[Theory, CombinatorialData]
public void TheoryDataOfT([CombinatorialMemberData(nameof(MyTestCases))] MyTestCase testCase, bool flag)
{
/*
This will give you:
testCase(1, "Foo"), true
testCase(1, "Foo"), false
testCase(2, "Bar"), true
testCase(2, "Bar"), false
*/
}

public record MyTestCase(int Number, string Text);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net462</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Xunit.Combinatorial\Xunit.Combinatorial.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IsExternalInit" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Validation" />
<PackageReference Include="xunit.runner.visualstudio" />
Expand Down

0 comments on commit 2739415

Please sign in to comment.