test: simplifying failure tests

This commit is contained in:
Dylan R. E. Moonfire 2021-12-07 17:34:02 -06:00
parent 5e9785221b
commit 9344af62cd
2 changed files with 15 additions and 26 deletions

View file

@ -12,6 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" />
<PackageReference Include="MfGames.IO" Version="1.2.3" />
<PackageReference Include="MfGames.TestSetup" Version="1.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2">

View file

@ -7,6 +7,8 @@ using System.Threading.Tasks;
using CliWrap;
using CliWrap.Exceptions;
using MfGames.IO.Extensions;
using Xunit;
namespace MfGames.ToolBuilder.Tests
@ -21,7 +23,7 @@ namespace MfGames.ToolBuilder.Tests
public void CrashCommandFails()
{
// Run the executable using CliWrap.
FileInfo projectFile = GetProjectFile();
FileInfo projectFile = this.GetProjectFile();
StringBuilder output = new();
CancellationToken cancellationToken =
new CancellationTokenSource(TimeSpan.FromSeconds(20))
@ -46,15 +48,15 @@ namespace MfGames.ToolBuilder.Tests
Assert.NotNull(exception);
}
[Fact(Skip = "Not working in CI for some reason")]
[Fact]
public async Task TableCommandWorks()
{
// Run the executable using CliWrap.
FileInfo projectFile = GetProjectFile();
FileInfo projectFile = this.GetProjectFile();
StringBuilder output = new();
CancellationToken cancellationToken =
new CancellationTokenSource(TimeSpan.FromSeconds(20))
.Token;
var delay = TimeSpan.FromMinutes(1);
CancellationTokenSource cancellationTokenSource = new(delay);
CancellationToken cancellationToken = cancellationTokenSource.Token;
CommandResult result = await Cli.Wrap("dotnet")
.WithArguments(
@ -87,27 +89,13 @@ namespace MfGames.ToolBuilder.Tests
/// <summary>
/// Gets the file object representing the sample tool's project.
/// </summary>
private static FileInfo GetProjectFile()
private FileInfo GetProjectFile()
{
// Loop up until we find the directory that contains it.
var parent = new DirectoryInfo(Environment.CurrentDirectory);
while (parent?.GetDirectories("SampleTool").Length == 0)
{
parent = parent.Parent;
}
// If we got a null, we can't find it.
if (parent == null)
{
throw new DirectoryNotFoundException(
"Cannot find sample tool directory from "
+ Environment.CurrentDirectory);
}
// Get the project file inside there.
DirectoryInfo directory = parent.GetDirectories("SampleTool")[0];
FileInfo file = directory.GetFiles("SampleTool.csproj")[0];
FileInfo file = this
.GetType()
.GetDirectory()
.FindGitRoot()
!.GetFile("tests", "SampleTool", "SampleTool.csproj");
return file;
}