Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a few #if that are no longer needed #4138

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 16 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,22 @@
</ItemGroup>
</Target>

<!-- R9 common properties -->
<!-- Test configuration -->
<PropertyGroup>
<!-- Disable building Integration Test projects in LUT. -->
<BuildForLiveUnitTesting Condition="'$(BuildForLiveUnitTesting)' == '' and '$(IsIntegrationTestProject)' == 'true'">false</BuildForLiveUnitTesting>

<!-- Redirect test logs into a subfolder -->
<TestResultsLogDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsLogDir)', 'TestLogs'))</TestResultsLogDir>

<!--
Run tests with the VS Test Runner (dotnet test) instead of the XUnit Test runner (dotnet exec).
This is needed to produce Cobertura code coverage. See the targets file to more information.
-->
<UseVSTestRunner>true</UseVSTestRunner>
</PropertyGroup>

<!-- Common properties -->
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\Analyzers.props" />
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\Packaging.props" />
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\LegacySupport.props" />
Expand Down
22 changes: 4 additions & 18 deletions eng/Packages/TestOnly.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Disable building Integration Test projects in LUT. -->
<BuildForLiveUnitTesting Condition="'$(BuildForLiveUnitTesting)' == '' and '$(IsIntegrationTestProject)' == 'true'">false</BuildForLiveUnitTesting>

<!-- Redirect test logs into a subfolder -->
<TestResultsLogDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsLogDir)', 'TestLogs'))</TestResultsLogDir>

<!--
Run tests with the VS Test Runner (dotnet test) instead of the XUnit Test runner (dotnet exec).
This is needed to produce Cobertura code coverage. See the targets file to more information.
-->
<UseVSTestRunner>true</UseVSTestRunner>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="AutoFixture.AutoMoq" Version="4.17.0" />
<PackageVersion Include="autofixture" Version="4.17.0" />
Expand All @@ -35,13 +21,13 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.22" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="3.1.22" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.32" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="3.1.32" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.19" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.19" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public static IStandardHedgingHandlerBuilder Configure(this IStandardHedgingHand
_ = builder.Services.Configure<HttpStandardHedgingResilienceOptions>(
builder.Name,
section,
#if NET6_0_OR_GREATER
o => o.ErrorOnUnknownConfiguration = true);
#else
_ => { });
#endif

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public static IHttpStandardResilienceStrategyBuilder Configure(this IHttpStandar
_ = builder.Services.Configure<HttpStandardResilienceOptions>(
builder.StrategyName,
section,
#if NET6_0_OR_GREATER
o => o.ErrorOnUnknownConfiguration = true);
#else
_ => { });
#endif

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ namespace Microsoft.Extensions.Options.Contextual;
/// </summary>
/// <typeparam name="TOptions">The type of options being requested.</typeparam>
internal sealed class ContextualOptionsFactory<TOptions> : IContextualOptionsFactory<TOptions>
#if NET5_0_OR_GREATER
where TOptions : class
#else
where TOptions : class, new()
#endif
{
private readonly IOptionsFactory<TOptions> _baseFactory;
private readonly ILoadContextualOptions<TOptions>[] _loaders;
Expand Down Expand Up @@ -124,11 +120,7 @@ async ValueTask<TOptions> ConfigureOptions(TContext context)
if (result.Failed)
{
failures ??= new();
#if NETFRAMEWORK || NETSTANDARD2_0
failures.Add(result.FailureMessage);
#else
failures.AddRange(result.Failures);
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
#if NET6_0_OR_GREATER
using Microsoft.Extensions.Logging;
#endif
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Telemetry.Enrichment;
using Microsoft.Shared.Diagnostics;
Expand Down Expand Up @@ -202,10 +200,8 @@ void IEnrichmentPropertyBag.Add(ReadOnlySpan<KeyValuePair<string, string>> prope
}
}

#if NET6_0_OR_GREATER
/// <summary>
/// Gets log define options configured to skip the log level enablement check.
/// </summary>
public static LogDefineOptions SkipEnabledCheckOptions { get; } = new() { SkipEnabledCheck = true };
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,11 @@ public Task WaitForMeasurementsAsync(int minCount, CancellationToken cancellatio
{
lock (_measurements)
{
_waiters.Remove(w);
_ = _waiters.Remove(w);
}

// trigger the task from outside the lock
#if NET6_0_OR_GREATER
w.TaskSource.TrySetCanceled(cancellationToken);
#else
w.TaskSource.TrySetCanceled();
#endif
_ = w.TaskSource.TrySetCanceled(cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we await this? This is testing code, and discarding a task will ignore potential exceptions in TrySetCanceled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wait for what? TrySetCanceled returns a boolean. And this is intentionally fire-and-forget so we don't care about the return value.

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public async Task TestEmitter()
var sources = new List<string>();
foreach (var file in Directory.GetFiles("TestClasses"))
{
#if NETCOREAPP3_1_OR_GREATER
sources.Add("#define NETCOREAPP3_1_OR_GREATER\n" + File.ReadAllText(file));
#else
sources.Add(File.ReadAllText(file));
#endif
}

// try it without the frozen collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,7 @@ public void SkipEnabledCheckTests()
SkipEnabledCheckTestExtensions.LoggerMethodWithFalseSkipEnabledCheck(logger, LogLevel.Information, "p1");
Assert.Equal(0, logger.Collector.Count);

#if NET8_0_OR_GREATER
// Whilst these API are marked as NET6_0_OR_GREATER we don't build .NET 6.0,
// and as such the API is available in .NET 8 onwards.
#if NET6_0_OR_GREATER
SkipEnabledCheckTestExtensions.LoggerMethodWithTrueSkipEnabledCheck(logger);
Assert.Equal(1, logger.Collector.Count);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,7 @@ public void AddStandardResilienceHandler_ConfigurationPropertyWithTypo_Throws(Me

AddStandardResilienceHandler(mode, builder, _invalidConfigurationSection, options => { });

#if NET8_0_OR_GREATER
// Whilst these API are marked as NET6_0_OR_GREATER we don't build .NET 6.0,
// and as such the API is available in .NET 8 onwards.
Assert.Throws<InvalidOperationException>(() => HttpClientBuilderExtensionsTests.GetStrategy(builder.Services, $"test-standard"));
#else
GetStrategy(builder.Services, $"test-standard").Should().NotBeNull();
#endif
}

[Fact]
Expand Down