chore: import upstream snapshot with attribution
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:21:23 +08:00
commit b957a53def
5423 changed files with 863745 additions and 0 deletions
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
[AttributeUsage(AttributeTargets.Method)]
[XunitTestCaseDiscoverer("VectorData.ConformanceTests.Xunit.ConditionalFactDiscoverer", "VectorData.ConformanceTests")]
public sealed class ConditionalFactAttribute : FactAttribute;
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit.Abstractions;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
/// <summary>
/// Used dynamically from <see cref="ConditionalFactAttribute" />.
/// Make sure to update that class if you move this type.
/// </summary>
public class ConditionalFactDiscoverer(IMessageSink messageSink) : FactDiscoverer(messageSink)
{
protected override IXunitTestCase CreateTestCase(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo factAttribute)
=> new ConditionalFactTestCase(
this.DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod);
}
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit.Abstractions;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
public sealed class ConditionalFactTestCase : XunitTestCase
{
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public ConditionalFactTestCase()
{
}
public ConditionalFactTestCase(
IMessageSink diagnosticMessageSink,
TestMethodDisplay defaultMethodDisplay,
TestMethodDisplayOptions defaultMethodDisplayOptions,
ITestMethod testMethod,
object[]? testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments)
{
}
public override async Task<RunSummary> RunAsync(
IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
object[] constructorArguments,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
=> await XunitTestCaseExtensions.TrySkipAsync(this, messageBus)
? new RunSummary { Total = 1, Skipped = 1 }
: await base.RunAsync(
diagnosticMessageSink,
messageBus,
constructorArguments,
aggregator,
cancellationTokenSource);
}
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
[AttributeUsage(AttributeTargets.Method)]
[XunitTestCaseDiscoverer("VectorData.ConformanceTests.Xunit.ConditionalTheoryDiscoverer", "VectorData.ConformanceTests")]
public sealed class ConditionalTheoryAttribute : TheoryAttribute;
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit.Abstractions;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
/// <summary>
/// Used dynamically from <see cref="ConditionalTheoryAttribute" />.
/// Make sure to update that class if you move this type.
/// </summary>
public class ConditionalTheoryDiscoverer(IMessageSink messageSink) : TheoryDiscoverer(messageSink)
{
protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo theoryAttribute)
{
yield return new ConditionalTheoryTestCase(
this.DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod);
}
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo theoryAttribute,
object[] dataRow)
{
yield return new ConditionalFactTestCase(
this.DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
dataRow);
}
}
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft. All rights reserved.
using Xunit.Abstractions;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
public sealed class ConditionalTheoryTestCase : XunitTheoryTestCase
{
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public ConditionalTheoryTestCase()
{
}
public ConditionalTheoryTestCase(
IMessageSink diagnosticMessageSink,
TestMethodDisplay defaultMethodDisplay,
TestMethodDisplayOptions defaultMethodDisplayOptions,
ITestMethod testMethod)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod)
{
}
public override async Task<RunSummary> RunAsync(
IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
object[] constructorArguments,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
=> await XunitTestCaseExtensions.TrySkipAsync(this, messageBus)
? new RunSummary { Total = 1, Skipped = 1 }
: await base.RunAsync(
diagnosticMessageSink,
messageBus,
constructorArguments,
aggregator,
cancellationTokenSource);
}
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft. All rights reserved.
namespace VectorData.ConformanceTests.Xunit;
/// <summary>
/// Disable the tests in the decorated scope.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
public sealed class DisableTestsAttribute : Attribute, ITestCondition
{
public ValueTask<bool> IsMetAsync()
{
return new(false);
}
public string Skip { get; set; } = "Test disabled due to usage of DisableTestsAttribute";
public string SkipReason
=> this.Skip;
}
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
namespace VectorData.ConformanceTests.Xunit;
public interface ITestCondition
{
ValueTask<bool> IsMetAsync();
string SkipReason { get; }
}
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Concurrent;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace VectorData.ConformanceTests.Xunit;
public static class XunitTestCaseExtensions
{
private static readonly ConcurrentDictionary<string, List<IAttributeInfo>> s_typeAttributes = new();
private static readonly ConcurrentDictionary<string, List<IAttributeInfo>> s_assemblyAttributes = new();
public static async ValueTask<bool> TrySkipAsync(XunitTestCase testCase, IMessageBus messageBus)
{
var method = testCase.Method;
var type = testCase.TestMethod.TestClass.Class;
var assembly = type.Assembly;
var skipReasons = new List<string>();
var attributes =
s_assemblyAttributes.GetOrAdd(
assembly.Name,
a => assembly.GetCustomAttributes(typeof(ITestCondition)).ToList())
.Concat(
s_typeAttributes.GetOrAdd(
type.Name,
t => type.GetCustomAttributes(typeof(ITestCondition)).ToList()))
.Concat(method.GetCustomAttributes(typeof(ITestCondition)))
.OfType<ReflectionAttributeInfo>()
.Select(attributeInfo => (ITestCondition)attributeInfo.Attribute);
foreach (var attribute in attributes)
{
if (!await attribute.IsMetAsync())
{
skipReasons.Add(attribute.SkipReason);
}
}
if (skipReasons.Count > 0)
{
messageBus.QueueMessage(
new TestSkipped(new XunitTest(testCase, testCase.DisplayName), string.Join(Environment.NewLine, skipReasons)));
return true;
}
return false;
}
}