Improved some comments
このコミットが含まれているのは:
1 親
9146efc596
コミット
7cf7bf6c85
2ファイル変更
+85
-37
検索条件に一致するファイルはありません
@@ -1,9 +1,6 @@
|
||||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
@@ -13,21 +10,29 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
{
|
||||
static NativeLibrariesResolverTests()
|
||||
{
|
||||
var path = Path.GetDirectoryName(typeof(NativeLibrariesResolverTests).Assembly.Location);
|
||||
string path = Path.GetDirectoryName(typeof(NativeLibrariesResolverTests).Assembly.Location);
|
||||
|
||||
while (Path.GetFileName(path) is not "ComputeSharp")
|
||||
{
|
||||
path = Path.GetDirectoryName(path);
|
||||
}
|
||||
|
||||
SampleProjectDirectory = Path.Combine(path, "samples", "ComputeSharp.Sample.NuGet");
|
||||
var sampleProjectPath = Path.Combine(SampleProjectDirectory, "ComputeSharp.Sample.NuGet.csproj");
|
||||
|
||||
var packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj");
|
||||
string
|
||||
sampleProjectPath = Path.Combine(SampleProjectDirectory, "ComputeSharp.Sample.NuGet.csproj"),
|
||||
packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj");
|
||||
|
||||
// Run dotnet pack and on the packaging project, to ensure the local NuGet package is
|
||||
// available. Then run dotnet restore on the sample project. This is done so that
|
||||
// other tests can skip the restore step to run faster, as there's lots of them.
|
||||
Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit();
|
||||
// We use "--no-restore" where possible to speed up the tests
|
||||
Process.Start("dotnet", $"restore {sampleProjectPath}").WaitForExit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directory of the ComputeSharp.Sample.NuGet project.
|
||||
/// </summary>
|
||||
private static string SampleProjectDirectory { get; }
|
||||
|
||||
[TestMethod]
|
||||
@@ -37,7 +42,7 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
[DataRow(Configuration.Release, RID.Win_x64)]
|
||||
public void DotnetRunWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
// "dotnet run" fails with "--no-restore"
|
||||
// "dotnet run" fails with "--no-restore", so in this case we restore packages as well
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, "dotnet", $"run -c {configuration} {ToOption(rid)}"));
|
||||
}
|
||||
|
||||
@@ -49,7 +54,9 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
public void DotnetBuildWithRunningDotnetHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
BuildSampleProject(configuration, rid);
|
||||
var realtivePathToDll = Path.Combine("bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.dll");
|
||||
|
||||
string realtivePathToDll = Path.Combine("bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.dll");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, "dotnet", realtivePathToDll));
|
||||
}
|
||||
|
||||
@@ -61,7 +68,9 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
public void DotnetBuildWithRunningDotnetHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
BuildSampleProject(configuration, rid);
|
||||
var pathToDllDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}");
|
||||
|
||||
string pathToDllDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToDllDirectory, "dotnet", "ComputeSharp.Sample.NuGet.dll"));
|
||||
}
|
||||
|
||||
@@ -73,7 +82,9 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
public void DotnetBuildWithRunningAppHostFromProjectDirectoryWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
BuildSampleProject(configuration, rid);
|
||||
var relativePathToAppHost = Path.Combine("bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
string relativePathToAppHost = Path.Combine("bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, relativePathToAppHost, ""));
|
||||
}
|
||||
|
||||
@@ -85,7 +96,9 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
public void DotnetBuildWithRunningAppHostDirectlyWorks(Configuration configuration, RID rid)
|
||||
{
|
||||
BuildSampleProject(configuration, rid);
|
||||
var pathToAppHostDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}");
|
||||
|
||||
string pathToAppHostDirectory = Path.Combine(SampleProjectDirectory, "bin", $"{configuration}", "net5.0", $"{ToDirectory(rid)}");
|
||||
|
||||
Assert.AreEqual(0, Exec(pathToAppHostDirectory, "ComputeSharp.Sample.NuGet.exe", ""));
|
||||
}
|
||||
|
||||
@@ -94,20 +107,34 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
[DataRow(Configuration.Release)]
|
||||
public void DotnetPublishWorks(Configuration configuration)
|
||||
{
|
||||
// We do not support publishing without the RID
|
||||
// Publishing without specifying an RID is not supported
|
||||
Exec(SampleProjectDirectory, "dotnet", $"publish -c {configuration} -r win-x64 --no-restore");
|
||||
var pathToAppHost = Path.Combine("bin", $"{configuration}", "net5.0", "win-x64", "publish", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
string pathToAppHost = Path.Combine("bin", $"{configuration}", "net5.0", "win-x64", "publish", "ComputeSharp.Sample.NuGet.exe");
|
||||
|
||||
Assert.AreEqual(0, Exec(SampleProjectDirectory, pathToAppHost, ""));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the sample project with a specific configuration and target runtime.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration to use to build the project.</param>
|
||||
/// <param name="rid">The RID to use to build the project.</param>
|
||||
private static void BuildSampleProject(Configuration configuration, RID rid)
|
||||
{
|
||||
Exec(SampleProjectDirectory, "dotnet", $"build -c {configuration} {ToOption(rid)} --no-restore");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a specified process from the command line and returns the exit code.
|
||||
/// </summary>
|
||||
/// <param name="workingDirectory">The working directory to execute the process.</param>
|
||||
/// <param name="filePath">The target file path for the process to execute.</param>
|
||||
/// <param name="arguments">The arguments to invoke the process.</param>
|
||||
/// <returns>The exit code for the executed process.</returns>
|
||||
private static int Exec(string workingDirectory, string filePath, string arguments)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
ProcessStartInfo startInfo = new()
|
||||
{
|
||||
UseShellExecute = true,
|
||||
CreateNoWindow = true,
|
||||
@@ -117,12 +144,18 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
WorkingDirectory = workingDirectory
|
||||
};
|
||||
|
||||
var process = Process.Start(startInfo);
|
||||
Process process = Process.Start(startInfo);
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
return process.ExitCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of a cmd option for the dotnet tool, for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToOption(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
@@ -130,6 +163,11 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a text representation of the build folder for the given <see cref="RID"/>.
|
||||
/// </summary>
|
||||
/// <param name="rid">The input <see cref="RID"/> value.</param>
|
||||
/// <returns>A text representation for <paramref name="rid"/>.</returns>
|
||||
private static string ToDirectory(RID rid) => rid switch
|
||||
{
|
||||
RID.None => "",
|
||||
@@ -137,12 +175,18 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver
|
||||
_ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID))
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A build configuration.
|
||||
/// </summary>
|
||||
public enum Configuration
|
||||
{
|
||||
Debug,
|
||||
Release
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A runtime identifier.
|
||||
/// </summary>
|
||||
public enum RID
|
||||
{
|
||||
None,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする