Skip to content

Commit

Permalink
Feature : Add Net 8.0 (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman authored Jan 1, 2024
1 parent 63a8b3c commit 4a0d181
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 106 deletions.
16 changes: 8 additions & 8 deletions src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageProjectUrl>https://github.com/reactiveui/punchclock/</PackageProjectUrl>
<Authors>.NET Foundation and Contributors</Authors>
<Owners>xpaulbettsx;ghuntley</Owners>
<NoWarn>$(NoWarn);VSX1000</NoWarn>
<NoWarn>$(NoWarn);VSX1000;SA1010</NoWarn>
<Platform>AnyCPU</Platform>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Description>Make sure your asynchronous operations show up to work on time</Description>
Expand Down Expand Up @@ -34,14 +34,14 @@
</PropertyGroup>

<ItemGroup Condition="$(IsTestProject)">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.console" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.console" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="Xunit.StaFact" Version="1.1.11" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="DiffEngine" Version="12.4.1" />
<PackageReference Include="DiffEngine" Version="13.0.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -50,7 +50,7 @@
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand All @@ -64,7 +64,7 @@

<ItemGroup>
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.1" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.6.2" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Punchclock
{
public class OperationQueue : System.IDisposable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/reactiveui/punchclock")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Punchclock
{
public class OperationQueue : System.IDisposable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/reactiveui/punchclock")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Punchclock
{
public class OperationQueue : System.IDisposable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")]
namespace Punchclock
{
public class OperationQueue : System.IDisposable
{
public OperationQueue(int maximumConcurrent = 4) { }
public void Dispose() { }
protected virtual void Dispose(bool isDisposing) { }
public System.IObservable<T> EnqueueObservableOperation<T>(int priority, System.Func<System.IObservable<T>> asyncCalculationFunc) { }
public System.IObservable<T> EnqueueObservableOperation<T>(int priority, string key, System.Func<System.IObservable<T>> asyncCalculationFunc) { }
public System.IObservable<T> EnqueueObservableOperation<T, TDontCare>(int priority, string key, System.IObservable<TDontCare> cancel, System.Func<System.IObservable<T>> asyncCalculationFunc) { }
public System.IDisposable PauseQueue() { }
public void SetMaximumConcurrent(int maximumConcurrent) { }
public System.IObservable<System.Reactive.Unit> ShutdownQueue() { }
}
public static class OperationQueueExtensions
{
public static System.Threading.Tasks.Task Enqueue(this Punchclock.OperationQueue operationQueue, int priority, System.Func<System.Threading.Tasks.Task> asyncOperation) { }
public static System.Threading.Tasks.Task Enqueue(this Punchclock.OperationQueue operationQueue, int priority, string key, System.Func<System.Threading.Tasks.Task> asyncOperation) { }
public static System.Threading.Tasks.Task Enqueue(this Punchclock.OperationQueue operationQueue, int priority, string key, System.Func<System.Threading.Tasks.Task> asyncOperation, System.Threading.CancellationToken token) { }
public static System.Threading.Tasks.Task<T> Enqueue<T>(this Punchclock.OperationQueue operationQueue, int priority, System.Func<System.Threading.Tasks.Task<T>> asyncOperation) { }
public static System.Threading.Tasks.Task<T> Enqueue<T>(this Punchclock.OperationQueue operationQueue, int priority, string key, System.Func<System.Threading.Tasks.Task<T>> asyncOperation) { }
public static System.Threading.Tasks.Task<T> Enqueue<T>(this Punchclock.OperationQueue operationQueue, int priority, string key, System.Func<System.Threading.Tasks.Task<T>> asyncOperation, System.Threading.CancellationToken token) { }
}
}
92 changes: 14 additions & 78 deletions src/Punchclock.Tests/API/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,24 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

using DiffEngine;

using PublicApiGenerator;

using Splat;

using System.Threading.Tasks;
using VerifyXunit;
using Xunit;

namespace Punchclock.APITests
namespace Punchclock.APITests;

/// <summary>
/// Tests for handling API approval.
/// </summary>
[ExcludeFromCodeCoverage]
[UsesVerify]
public class ApiApprovalTests
{
/// <summary>
/// Tests for handling API approval.
/// Tests to make sure the punchclock project is approved.
/// </summary>
[ExcludeFromCodeCoverage]
public class ApiApprovalTests
{
private static readonly Regex _removeCoverletSectionRegex = new Regex(@"^namespace Coverlet\.Core\.Instrumentation\.Tracker.*?^}", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.Compiled);

/// <summary>
/// Tests to make sure the punchclock project is approved.
/// </summary>
[Fact]
public void PunchclockTests()
{
CheckApproval(typeof(OperationQueue).Assembly);
}

private static void CheckApproval(Assembly assembly, [CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null)
{
var targetFrameworkName = Assembly.GetExecutingAssembly().GetTargetFrameworkName();

var sourceDirectory = Path.GetDirectoryName(filePath);

var approvedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.approved.txt");
var receivedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.received.txt");

if (!File.Exists(receivedFileName))
{
File.Create(receivedFileName).Close();
}

if (!File.Exists(approvedFileName))
{
File.Create(approvedFileName).Close();
}

var approvedPublicApi = File.ReadAllText(approvedFileName);

var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = new[] { "Akavache" } };
var receivedPublicApi = Filter(assembly.GeneratePublicApi(generatorOptions));

if (!string.Equals(receivedPublicApi, approvedPublicApi, StringComparison.InvariantCulture))
{
File.WriteAllText(receivedFileName, receivedPublicApi);
DiffRunner.Launch(receivedFileName, approvedFileName);
}

Assert.Equal(approvedPublicApi, receivedPublicApi);
}

private static string Filter(string text)
{
text = _removeCoverletSectionRegex.Replace(text, string.Empty);
return string.Join(Environment.NewLine, text.Split(
new[]
{
Environment.NewLine
},
StringSplitOptions.RemoveEmptyEntries)
.Where(l =>
!l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) &&
!l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) &&
!l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) &&
!string.IsNullOrWhiteSpace(l)));
}
}
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public Task PunchclockTests() => typeof(OperationQueue).Assembly.CheckApproval(["Punchclock"]);
}
42 changes: 42 additions & 0 deletions src/Punchclock.Tests/API/ApiExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2023 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using PublicApiGenerator;
using VerifyXunit;

namespace Punchclock.APITests;

/// <summary>
/// A helper for doing API approvals.
/// </summary>
public static class ApiExtensions
{
/// <summary>
/// Checks to make sure the API is approved.
/// </summary>
/// <param name="assembly">The assembly that is being checked.</param>
/// <param name="namespaces">The namespaces.</param>
/// <param name="filePath">The caller file path.</param>
/// <returns>
/// A Task.
/// </returns>
public static async Task CheckApproval(this Assembly assembly, string[] namespaces, [CallerFilePath] string filePath = "")
{
var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = namespaces };
var apiText = assembly.GeneratePublicApi(generatorOptions);
var result = await Verifier.Verify(apiText, null, filePath)
.UniqueForRuntimeAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture));
}
}
28 changes: 15 additions & 13 deletions src/Punchclock.Tests/Punchclock.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net472</TargetFrameworks>
<NoWarn>$(NoWarn);1591;CA1707;SA1633</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DynamicData" Version="8.*" />
<PackageReference Include="splat" Version="14.*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DynamicData" Version="8.*" />
<PackageReference Include="splat" Version="14.*" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="Verify.Xunit" Version="22.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Punchclock\Punchclock.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Punchclock\Punchclock.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Punchclock/PriorityQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public T[] DequeueSome(int count)
{
if (count == 0)
{
return Array.Empty<T>();
return [];
}

var ret = new T[count];
Expand Down
2 changes: 1 addition & 1 deletion src/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.400",
"version": "8.0.10",
"rollForward": "latestMinor"
},
"msbuild-sdks": {
Expand Down

0 comments on commit 4a0d181

Please sign in to comment.