Skip to content

Commit

Permalink
Backfill XML docs on all the context objects
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Dec 5, 2023
1 parent 7e82f3f commit 1bd651f
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/xunit.analyzers/Utility/EmptyAssertContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Xunit.Analyzers;

public class EmptyAssertContext : IAssertContext
Expand All @@ -8,4 +10,6 @@ public class EmptyAssertContext : IAssertContext
public static EmptyAssertContext Instance { get; } = new();

public bool SupportsAssertFail => false;

public Version Version { get; } = new();
}
3 changes: 3 additions & 0 deletions src/xunit.analyzers/Utility/EmptyCoreContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.CodeAnalysis;

namespace Xunit.Analyzers;
Expand Down Expand Up @@ -36,4 +37,6 @@ public class EmptyCoreContext : ICoreContext
public bool TheorySupportsDefaultParameterValues => false;

public bool TheorySupportsParameterArrays => false;

public Version Version { get; } = new();
}
10 changes: 10 additions & 0 deletions src/xunit.analyzers/Utility/IAssertContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
using System;

namespace Xunit.Analyzers;

public interface IAssertContext
{
/// <summary>
/// Gets a flag indicating whether <c>Assert.Fail</c> is supported.
/// </summary>
bool SupportsAssertFail { get; }

/// <summary>
/// Gets the version number of the assertion assembly.
/// </summary>
Version Version { get; }
}
51 changes: 51 additions & 0 deletions src/xunit.analyzers/Utility/ICoreContext.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,85 @@
using System;
using Microsoft.CodeAnalysis;

namespace Xunit.Analyzers;

public interface ICoreContext
{
/// <summary>
/// Gets a reference to type <c>Xunit.ClassDataAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? ClassDataAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.CollectionAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? CollectionAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.CollectionDefinitionAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? CollectionDefinitionAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.Sdk.DataAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? DataAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.FactAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? FactAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.IClassFixture&lt;T&gt;</c>, if available.
/// </summary>
INamedTypeSymbol? IClassFixtureType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.ICollectionFixture&lt;T&gt;</c>, if available.
/// </summary>
INamedTypeSymbol? ICollectionFixtureType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.InlineDataAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? InlineDataAttributeType { get; }

// TODO: This will need to be updated when v3 names are finalized
/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestOutputHelper</c> (v2)
/// or <c>Xunit.v3._ITestOutputHelper</c>, if available.
/// </summary>
INamedTypeSymbol? ITestOutputHelperType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.MemberDataAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? MemberDataAttributeType { get; }

/// <summary>
/// Gets a reference to type <c>Xunit.TheoryAttribute</c>, if available.
/// </summary>
INamedTypeSymbol? TheoryAttributeType { get; }

/// <summary>
/// Gets a flag indicating whether theory data can be automatically converted from a <see cref="string"/>
/// value into a <see cref="DateTimeOffset"/> or a <see cref="Guid"/>.
/// </summary>
bool TheorySupportsConversionFromStringToDateTimeOffsetAndGuid { get; }

/// <summary>
/// Gets a flag indicating whether theory methods support default parameter values.
/// </summary>
bool TheorySupportsDefaultParameterValues { get; }

/// <summary>
/// Gets a flag indicating whether theory methods support params arrays.
/// </summary>
bool TheorySupportsParameterArrays { get; }

/// <summary>
/// Gets the version number of the core assembly.
/// </summary>
Version Version { get; }
}
6 changes: 3 additions & 3 deletions src/xunit.analyzers/Utility/TypeSymbolFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public static INamedTypeSymbol IEnumerableOfObjectArray(Compilation compilation)
return iEnumerableOfT.Construct(iTheoryDataRow);
}

public static INamedTypeSymbol? IMethodInfo_V2(Compilation compilation) =>
compilation.GetTypeByMetadataName("Xunit.Abstractions.IMethodInfo");

public static INamedTypeSymbol? IMessageSink_V2(Compilation compilation) =>
compilation.GetTypeByMetadataName("Xunit.Abstractions.IMessageSink");

public static INamedTypeSymbol? IMessageSinkMessage_V2(Compilation compilation) =>
compilation.GetTypeByMetadataName("Xunit.Abstractions.IMessageSinkMessage");

public static INamedTypeSymbol? IMethodInfo_V2(Compilation compilation) =>
compilation.GetTypeByMetadataName("Xunit.Abstractions.IMethodInfo");

public static INamedTypeSymbol? InlineDataAttribute(Compilation compilation) =>
compilation.GetTypeByMetadataName("Xunit.InlineDataAttribute");

Expand Down
60 changes: 60 additions & 0 deletions src/xunit.analyzers/Utility/V2AbstractionsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,63 +53,123 @@ public class V2AbstractionsContext
lazyIXunitSerializableType = new(() => TypeSymbolFactory.IXunitSerializable_V2(compilation));
}

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IAssemblyInfo</c>, if available.
/// </summary>
public INamedTypeSymbol? IAssemblyInfoType =>
lazyIAssemblyInfoType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IAttributeInfo</c>, if available.
/// </summary>
public INamedTypeSymbol? IAttributeInfoType =>
lazyIAttributeInfoType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IMessageSinkMessage</c>, if available.
/// </summary>
public INamedTypeSymbol? IMessageSinkMessageType =>
lazyIMessageSinkMessageType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IMessageSink</c>, if available.
/// </summary>
public INamedTypeSymbol? IMessageSinkType =>
lazyIMessageSinkType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IMethodInfo</c>, if available.
/// </summary>
public INamedTypeSymbol? IMethodInfoType =>
lazyIMethodInfoType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IParameterInfo</c>, if available.
/// </summary>
public INamedTypeSymbol? IParameterInfoType =>
lazyIParameterInfoType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ISourceInformationProvider</c>, if available.
/// </summary>
public INamedTypeSymbol? ISourceInformationProviderType =>
lazyISourceInformationProviderType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ISourceInformation</c>, if available.
/// </summary>
public INamedTypeSymbol? ISourceInformationType =>
lazyISourceInformationType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestAssembly</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestAssemblyType =>
lazyITestAssemblyType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestCase</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestCaseType =>
lazyITestCaseType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestClass</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestClassType =>
lazyITestClassType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestCollection</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestCollectionType =>
lazyITestCollectionType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestFrameworkDiscoverer</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestFrameworkDiscovererType =>
lazyITestFrameworkDiscovererType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestFrameworkExecutor</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestFrameworkExecutorType =>
lazyITestFrameworkExecutorType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestFramework</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestFrameworkType =>
lazyITestFrameworkType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestMethod</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestMethodType =>
lazyITestMethodType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITest</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestType =>
lazyITestType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITypeInfo</c>, if available.
/// </summary>
public INamedTypeSymbol? ITypeInfoType =>
lazyITypeInfoType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.IXunitSerializable</c>, if available.
/// </summary>
public INamedTypeSymbol? IXunitSerializableType =>
lazyIXunitSerializableType.Value;

/// <summary>
/// Gets the version number of the abstractions assembly.
/// </summary>
public Version Version { get; }

public static V2AbstractionsContext? Get(
Expand Down
4 changes: 3 additions & 1 deletion src/xunit.analyzers/Utility/V2AssertContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public class V2AssertContext : IAssertContext
Version = version;
}

/// <inheritdoc/>
public bool SupportsAssertFail =>
Version >= Version_2_5_0;

public Version Version { get; set; }
/// <inheritdoc/>
public Version Version { get; }

public static V2AssertContext? Get(
Compilation compilation,
Expand Down
19 changes: 18 additions & 1 deletion src/xunit.analyzers/Utility/V2CoreContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,67 @@ public class V2CoreContext : ICoreContext
lazyTheoryAttributeType = new(() => TypeSymbolFactory.TheoryAttribute(compilation));
}

/// <inheritdoc/>
public INamedTypeSymbol? ClassDataAttributeType =>
lazyClassDataAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? CollectionAttributeType =>
lazyCollectionAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? CollectionDefinitionAttributeType =>
lazyCollectionDefinitionAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? DataAttributeType =>
lazyDataAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? FactAttributeType =>
lazyFactAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? IClassFixtureType =>
lazyIClassFixtureType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? ICollectionFixtureType =>
lazyICollectionFixtureType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? InlineDataAttributeType =>
lazyInlineDataAttributeType.Value;

/// <summary>
/// Gets a reference to type <c>Xunit.Abstractions.ITestOutputHelper</c>, if available.
/// </summary>
public INamedTypeSymbol? ITestOutputHelperType =>
lazyITestOutputHelperType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? MemberDataAttributeType =>
lazyMemberDataAttributeType.Value;

/// <inheritdoc/>
public INamedTypeSymbol? TheoryAttributeType =>
lazyTheoryAttributeType.Value;

// See: https://github.com/xunit/xunit/pull/1546
/// <inheritdoc/>
public bool TheorySupportsConversionFromStringToDateTimeOffsetAndGuid =>
Version >= Version_2_4_0;

/// <inheritdoc/>
public bool TheorySupportsDefaultParameterValues =>
Version >= Version_2_2_0;

/// <inheritdoc/>
public bool TheorySupportsParameterArrays =>
Version >= Version_2_2_0;

public Version Version { get; set; }
/// <inheritdoc/>
public Version Version { get; }

public static V2CoreContext? Get(
Compilation compilation,
Expand Down
10 changes: 10 additions & 0 deletions src/xunit.analyzers/Utility/V2ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ public class V2ExecutionContext
lazyLongLivedMarshalByRefObjectType = new(() => TypeSymbolFactory.LongLivedMarshalByRefObject_ExecutionV2(compilation));
}

/// <summary>
/// Gets a reference to type <c>Xunit.LongLivedMarshalByRefObject</c>, if available.
/// </summary>
public INamedTypeSymbol? LongLivedMarshalByRefObjectType =>
lazyLongLivedMarshalByRefObjectType.Value;

/// <summary>
/// Gets a description of the target platform for the execution library (i.e., "desktop"). This is
/// typically extracted from the assembly name (i.e., "xunit.execution.desktop").
/// </summary>
public string Platform { get; }

/// <summary>
/// Gets the version number of the execution assembly.
/// </summary>
public Version Version { get; }

public static V2ExecutionContext? Get(
Expand Down
5 changes: 5 additions & 0 deletions src/xunit.analyzers/Utility/V2RunnerUtilityContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ public class V2RunnerUtilityContext : IRunnerUtilityContext
lazyLongLivedMarshalByRefObjectType = new(() => TypeSymbolFactory.LongLivedMarshalByRefObject_RunnerUtilityV2(compilation));
}

/// <summary>
/// Gets a reference to type <c>Xunit.Sdk.LongLivedMarshalByRefObject</c>, if available.
/// </summary>
public INamedTypeSymbol? LongLivedMarshalByRefObjectType =>
lazyLongLivedMarshalByRefObjectType.Value;

/// <inheritdoc/>
public string Platform { get; }

/// <inheritdoc/>
public Version Version { get; }

public static V2RunnerUtilityContext? Get(
Expand Down
Loading

0 comments on commit 1bd651f

Please sign in to comment.