parent
21ab76dbd3
commit
6694ceb407
19 changed files with 37 additions and 161 deletions
|
|
@ -22,8 +22,11 @@ jobs:
|
|||
- name: dotnet format check
|
||||
run: dotnet format arcade.slnx --verify-no-changes --verbosity minimal
|
||||
|
||||
- name: dotnet pack sdk
|
||||
run: dotnet pack src/sdk/Sdk.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: dotnet pack
|
||||
run: dotnet pack arcade.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
run: dotnet pack arcade.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: dotnet test
|
||||
run: dotnet test --solution arcade.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@ jobs:
|
|||
id: version
|
||||
uses: ./.forgejo/actions/version
|
||||
|
||||
- name: dotnet pack sdk
|
||||
run: dotnet pack src/sdk/Sdk.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: dotnet pack
|
||||
run: dotnet pack arcade.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
run: dotnet pack arcade.slnx -p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: upload packages
|
||||
uses: https://code.geekeey.de/actions/artifacts/push@ae8d20e174a8706675e6d54ebd3719a2802ea9dd # 1
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="TUnit" Version="1.75.0" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="TUnit" Version="1.76.28" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,7 +1,3 @@
|
|||
<Solution>
|
||||
<Project Path="src/sdk/Sdk/Geekeey.Arcade.NET.Sdk/Geekeey.Arcade.NET.Sdk.csproj" />
|
||||
<Project Path="src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Razor/Geekeey.Arcade.NET.Sdk.Razor.csproj" />
|
||||
<Project Path="src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj" />
|
||||
<Project Path="src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Web/Geekeey.Arcade.NET.Sdk.Web.csproj" />
|
||||
<Project Path="src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj" />
|
||||
</Solution>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<OutputType>Exe</OutputType>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/fixtures/**/*</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
|
@ -10,4 +9,8 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="TUnit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<TestingPlatformCommandLineOptionDefault Include="results-directory" Value="$([System.IO.Path]::Combine('$(ArtifactsPath)', 'log'))" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Geekeey.Arcade.NET.Tests.Shared;
|
||||
|
||||
namespace Geekeey.Arcade.NET.Tests;
|
||||
|
||||
|
|
@ -20,10 +21,9 @@ internal sealed class SdkNuGetTests
|
|||
var command = Command.WithWorkingDirectory(path)
|
||||
.WithThrowOnExit()
|
||||
.WithEnvironment("DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER", "1");
|
||||
await command.RunAsync("dotnet", "pack", Path.Combine("src", "sdk", "Sdk.slnf"));
|
||||
await command.RunAsync("dotnet", "pack", Path.Combine("src", "sdk", "Sdk.slnx"));
|
||||
|
||||
var search = await command.RunAsync("dotnet", "package", "search", "--format=json", "--source", package,
|
||||
"Geekeey.Arcade.NET.Sdk");
|
||||
var search = await command.RunAsync("dotnet", "package", "search", "--format=json", "--source", package, "Geekeey.Arcade.NET.Sdk");
|
||||
|
||||
var result = JsonSerializer.Deserialize<PackageSearchResponse>(search.StdOut)
|
||||
?? throw new InvalidOperationException("The package search response was empty.");
|
||||
|
|
@ -50,25 +50,6 @@ internal sealed class SdkNuGetTests
|
|||
await Assert.That(project.File("bin", "Debug", "net10.0", "project.dll")).Exists();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSdkWritesResultsToArtifactsDirectory()
|
||||
{
|
||||
// Arrange
|
||||
using var project = await CreateProjectFromTemplate("Geekeey.Arcade.NET.Sdk.Test", "test");
|
||||
var artifacts = project.Directory("artifacts");
|
||||
var build = await project.RunAsync("dotnet", "build", $"-p:ArtifactsPath={artifacts.FullName}");
|
||||
await Assert.That(build.ExitCode).IsZero();
|
||||
|
||||
// Act
|
||||
var test = await project.RunAsync("dotnet", project.File("artifacts", "bin", "project", "debug", "project.dll").FullName);
|
||||
|
||||
// Assert
|
||||
await Assert.That(test.ExitCode).IsZero();
|
||||
await Assert.That(artifacts.GetFiles("*-report.html", SearchOption.AllDirectories)).IsNotEmpty();
|
||||
await Assert.That(artifacts.GetFiles("*-tunit-report.json", SearchOption.AllDirectories)).IsNotEmpty();
|
||||
await Assert.That(project.Directory("TestResults").Exists).IsFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Arguments("Geekeey.Arcade.NET.Sdk", "base")]
|
||||
[Arguments("Geekeey.Arcade.NET.Sdk.Razor", "razor")]
|
||||
|
|
|
|||
74
src/sdk.tests/Shared/Command.cs
Normal file
74
src/sdk.tests/Shared/Command.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Geekeey.Arcade.NET.Tests.Shared;
|
||||
|
||||
internal sealed record Command(string WorkingDirectory, IEnumerable<KeyValuePair<string, string>> Environment)
|
||||
{
|
||||
public bool ThrowOnExit { get; init; }
|
||||
|
||||
public static Command WithWorkingDirectory(string path)
|
||||
{
|
||||
return new Command(path, []);
|
||||
}
|
||||
|
||||
public Command WithEnvironment(string name, string value)
|
||||
{
|
||||
return WithEnvironment([new KeyValuePair<string, string>(name, value)]);
|
||||
}
|
||||
|
||||
public Command WithEnvironment(IEnumerable<KeyValuePair<string, string>> environment)
|
||||
{
|
||||
var env = new Dictionary<string, string>(Environment);
|
||||
|
||||
foreach (var pair in environment)
|
||||
{
|
||||
env[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
return this with { Environment = env };
|
||||
}
|
||||
|
||||
public Command WithThrowOnExit()
|
||||
{
|
||||
return this with { ThrowOnExit = true };
|
||||
}
|
||||
|
||||
public async Task<CommandOutput> RunAsync(string exe, params IReadOnlyList<string> args)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(args);
|
||||
|
||||
var startInfo = new ProcessStartInfo(exe)
|
||||
{
|
||||
WorkingDirectory = WorkingDirectory,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
foreach (var argument in args)
|
||||
{
|
||||
startInfo.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
foreach (var pair in Environment)
|
||||
{
|
||||
startInfo.Environment[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
var process = Process.Start(startInfo) ?? throw new InvalidOperationException("Could not start dotnet.");
|
||||
var output = await process.StandardOutput.ReadToEndAsync();
|
||||
var error = await process.StandardError.ReadToEndAsync();
|
||||
|
||||
await process.WaitForExitAsync();
|
||||
|
||||
_ = ThrowOnExit && process.ExitCode is not 0
|
||||
? throw new InvalidOperationException($"'{exe}' exited with code {process.ExitCode}.{System.Environment.NewLine}{error}{output}")
|
||||
: 0;
|
||||
|
||||
return new CommandOutput(output, error, process.ExitCode);
|
||||
}
|
||||
}
|
||||
6
src/sdk.tests/Shared/CommandOutput.cs
Normal file
6
src/sdk.tests/Shared/CommandOutput.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
namespace Geekeey.Arcade.NET.Tests.Shared;
|
||||
|
||||
internal sealed record CommandOutput(string StdOut, string StdErr, int ExitCode);
|
||||
65
src/sdk.tests/Shared/Project.cs
Normal file
65
src/sdk.tests/Shared/Project.cs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
namespace Geekeey.Arcade.NET.Tests.Shared;
|
||||
|
||||
internal sealed class Project : IDisposable
|
||||
{
|
||||
private readonly DirectoryInfo _root;
|
||||
private readonly Command _shell;
|
||||
|
||||
public Project(DirectoryInfo root)
|
||||
{
|
||||
_root = root;
|
||||
_shell = Command.WithWorkingDirectory(_root.FullName)
|
||||
.WithEnvironment("DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER", "1")
|
||||
.WithEnvironment("TUNIT_DISABLE_GITHUB_REPORTER", "true")
|
||||
.WithEnvironment("NUGET_PACKAGES", System.IO.Path.Combine(_root.FullName, "packages"));
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get => _root.FullName;
|
||||
}
|
||||
|
||||
public Task<CommandOutput> RunAsync(string exe, params IReadOnlyList<string> args)
|
||||
{
|
||||
return _shell.RunAsync(exe, args);
|
||||
}
|
||||
|
||||
public void CopyFrom(string path)
|
||||
{
|
||||
System.IO.Directory.Copy(path, _root.FullName);
|
||||
}
|
||||
|
||||
public FileInfo File(params IReadOnlyList<string> path)
|
||||
{
|
||||
return new FileInfo(System.IO.Path.Combine([_root.FullName, .. path]));
|
||||
}
|
||||
|
||||
public DirectoryInfo Directory(params IReadOnlyList<string> path)
|
||||
{
|
||||
return new DirectoryInfo(System.IO.Path.Combine([_root.FullName, .. path]));
|
||||
}
|
||||
|
||||
public async Task Template(string path, string from, string insert)
|
||||
{
|
||||
string content;
|
||||
var file = File(path);
|
||||
|
||||
using (var text = file.OpenText())
|
||||
{
|
||||
content = await text.ReadToEndAsync();
|
||||
}
|
||||
|
||||
content = content.Replace(from, insert, StringComparison.Ordinal);
|
||||
|
||||
await using var writer = new StreamWriter(file.OpenWrite());
|
||||
await writer.WriteAsync(content);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_root.Delete(recursive: true);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@
|
|||
<NoWarn>IDE0055</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TUnit" Version="1.75.0" />
|
||||
<PackageReference Include="TUnit" Version="1.76.28" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
5
src/sdk.tests/testconfig.json
Normal file
5
src/sdk.tests/testconfig.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"platformOptions": {
|
||||
"resultDirectory": "../../artifacts/log"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"solution": {
|
||||
"path": "../../arcade.slnx",
|
||||
"projects": [
|
||||
"src/sdk/Sdk/Geekeey.Arcade.NET.Sdk/Geekeey.Arcade.NET.Sdk.csproj",
|
||||
"src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Razor/Geekeey.Arcade.NET.Sdk.Razor.csproj",
|
||||
"src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj",
|
||||
"src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Web/Geekeey.Arcade.NET.Sdk.Web.csproj"
|
||||
]
|
||||
}
|
||||
}
|
||||
6
src/sdk/Sdk.slnx
Normal file
6
src/sdk/Sdk.slnx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<Solution>
|
||||
<Project Path="Sdk/Geekeey.Arcade.NET.Sdk/Geekeey.Arcade.NET.Sdk.csproj" />
|
||||
<Project Path="Sdk/Geekeey.Arcade.NET.Sdk.Razor/Geekeey.Arcade.NET.Sdk.Razor.csproj" />
|
||||
<Project Path="Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj" />
|
||||
<Project Path="Sdk/Geekeey.Arcade.NET.Sdk.Web/Geekeey.Arcade.NET.Sdk.Web.csproj" />
|
||||
</Solution>
|
||||
|
|
@ -6,9 +6,6 @@
|
|||
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
|
||||
<IncludeSymbols>false</IncludeSymbols>
|
||||
<IsPackable>true</IsPackable>
|
||||
<!-- The packaging project is not a testing platform application itself: the Microsoft.Testing.Platform
|
||||
package flows to consumers and defaults 'IsTestingPlatformApplication' to true there. -->
|
||||
<IsTestingPlatformApplication>false</IsTestingPlatformApplication>
|
||||
<Description>MSBuild SDK for test projects with standardized build, analyzer, and editor configuration defaults.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -23,8 +20,5 @@
|
|||
<None Include="../../common/Common.props" Pack="true" PackagePath="common/Common.props" />
|
||||
<None Include="../../common/Common.targets" Pack="true" PackagePath="common/Common.targets" />
|
||||
<None Include="../../configuration/**/*" Pack="true" PackagePath="configuration/%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
<None Include="extensions/TestingPlatformExtensions.props" Pack="true" PackagePath="Sdk/TestingPlatformExtensions.props" />
|
||||
<None Include="extensions/TestingPlatformExtensions.targets" Pack="true" PackagePath="Sdk/TestingPlatformExtensions.targets" />
|
||||
<None Include="extensions/TestingPlatformExtensions.cs" Pack="true" PackagePath="common/source/TestingPlatformExtensions.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,4 @@
|
|||
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)../configuration/Geekeey.Arcade.NET.Sdk.Test.editorconfig" />
|
||||
<EditorConfigFiles Include="$(MSBuildThisFileDirectory)../configuration/Geekeey.Arcade.NET.FileBasedProgram.editorconfig" Condition="'$(FileBasedProgram)' == 'true'" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)TestingPlatformExtensions.props" />
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
<Project>
|
||||
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition="'$(_MustImportMicrosoftNETSdk)' == 'true'" />
|
||||
|
||||
<Import Project="$(MSBuildThisFileDirectory)TestingPlatformExtensions.targets" />
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
// <auto-generated>
|
||||
// This file is generated into the test project by Geekeey.Arcade.NET.Sdk.Test.
|
||||
// </auto-generated>
|
||||
|
||||
#nullable enable
|
||||
#pragma warning disable TPEXP
|
||||
|
||||
using Microsoft.Testing.Platform.Builder;
|
||||
using Microsoft.Testing.Platform.CommandLine;
|
||||
using Microsoft.Testing.Platform.Configurations;
|
||||
|
||||
namespace Geekeey.Arcade.NET.Sdk.Test;
|
||||
|
||||
public static class TestingPlatformExtensions
|
||||
{
|
||||
public static void AddExtensions(ITestApplicationBuilder builder, string[] arguments)
|
||||
{
|
||||
builder.Configuration.AddConfigurationSource(() => new ResultDirectoryConfigurationSource());
|
||||
}
|
||||
|
||||
public static class TestingPlatformBuilderHook
|
||||
{
|
||||
public static void AddExtensions(ITestApplicationBuilder builder, string[] arguments)
|
||||
=> TestingPlatformExtensions.AddExtensions(builder, arguments);
|
||||
}
|
||||
|
||||
private sealed class ResultDirectoryConfigurationSource : IConfigurationSource
|
||||
{
|
||||
public string Uid => "Geekeey.Arcade.NET.Sdk.Test.TestingPlatformExtensions";
|
||||
public string Version => "1.0.0";
|
||||
public string DisplayName => "Geekeey Arcade Testing Platform extensions";
|
||||
public string Description => "Uses the artifacts directory for test results by default.";
|
||||
|
||||
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
|
||||
|
||||
public int Order => 4;
|
||||
|
||||
public Task<IConfigurationProvider> BuildAsync(CommandLineParseResult commandLineParseResult)
|
||||
=> Task.FromResult<IConfigurationProvider>(new ResultDirectoryConfigurationProvider());
|
||||
}
|
||||
|
||||
private sealed class ResultDirectoryConfigurationProvider : IConfigurationProvider
|
||||
{
|
||||
public Task LoadAsync() => Task.CompletedTask;
|
||||
|
||||
public bool TryGet(string key, out string? value)
|
||||
{
|
||||
if (string.Equals(key, "platformOptions:resultDirectory", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
value = @"__ARTIFACTS_PATH__";
|
||||
return true;
|
||||
}
|
||||
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<Project>
|
||||
<!-- Register the SDK's Testing Platform extensions with MTP's generated entry point. -->
|
||||
<ItemGroup Condition="'$(IsTestProject)' == 'true' and '$(Language)' == 'C#' and '$(ArtifactsPath)' != ''">
|
||||
<TestingPlatformBuilderHook Include="D7E9E4C8-5F8A-4D0D-9C0E-9C3D0A5B2A11">
|
||||
<DisplayName>Geekeey Arcade Testing Platform extensions</DisplayName>
|
||||
<TypeFullName>Geekeey.Arcade.NET.Sdk.Test.TestingPlatformExtensions.TestingPlatformBuilderHook</TypeFullName>
|
||||
</TestingPlatformBuilderHook>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<_ArcadeTestingPlatformExtensionsSourcePath>$(MSBuildThisFileDirectory)../common/source/TestingPlatformExtensions.cs</_ArcadeTestingPlatformExtensionsSourcePath>
|
||||
<_ArcadeTestingPlatformExtensionsGeneratedPath>$(IntermediateOutputPath)TestingPlatformExtensions.g.cs</_ArcadeTestingPlatformExtensionsGeneratedPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="_GenerateArcadeTestingPlatformExtensions" BeforeTargets="CoreCompile"
|
||||
Inputs="$(_ArcadeTestingPlatformExtensionsSourcePath)" Outputs="$(_ArcadeTestingPlatformExtensionsGeneratedPath)"
|
||||
Condition="'$(Language)' == 'C#' and '$(ArtifactsPath)' != ''">
|
||||
<ReadLinesFromFile File="$(_ArcadeTestingPlatformExtensionsSourcePath)">
|
||||
<Output TaskParameter="Lines" ItemName="_ArcadeTestingPlatformExtensionsSourceLine" />
|
||||
</ReadLinesFromFile>
|
||||
<ItemGroup>
|
||||
<_ArcadeTestingPlatformExtensionsSourceLineWithPath Include="@(_ArcadeTestingPlatformExtensionsSourceLine->Replace('__ARTIFACTS_PATH__', '$(ArtifactsPath)'))" />
|
||||
</ItemGroup>
|
||||
<WriteLinesToFile
|
||||
File="$(_ArcadeTestingPlatformExtensionsGeneratedPath)"
|
||||
Lines="@(_ArcadeTestingPlatformExtensionsSourceLineWithPath)"
|
||||
Overwrite="true"
|
||||
WriteOnlyWhenDifferent="true" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_IncludeArcadeTestingPlatformExtensions" BeforeTargets="CoreCompile"
|
||||
DependsOnTargets="_GenerateArcadeTestingPlatformExtensions"
|
||||
Condition="'$(Language)' == 'C#' and '$(ArtifactsPath)' != ''">
|
||||
<ItemGroup>
|
||||
<Compile Remove="**/TestingPlatformExtensions.g.cs" />
|
||||
<FileWrites Include="$(_ArcadeTestingPlatformExtensionsGeneratedPath)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
Loading…
Reference in a new issue