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> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="JunitXml.TestLogger" Version="2.1.81" /> <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="MfGames.TestSetup" Version="1.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2"> <PackageReference Include="Roslynator.Analyzers" Version="3.2.2">

View file

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