This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/examples/CopyFiles/CopyFilesTest.cs

82 lines
2.2 KiB
C#

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using CliWrap;
using MfGames.IO.Extensions;
using MfGames.Nitride.Tests;
using Xunit;
using Xunit.Abstractions;
namespace CopyFiles;
/// <summary>
/// Tests the execution of the tool and ensures it is working correctly.
/// </summary>
public class CopyFilesTest : NitrideTestBase
{
public CopyFilesTest(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public async Task Run()
{
// Figure out the paths for this test.
DirectoryInfo rootDir =
typeof(CopyFilesProgram).GetDirectory()!.FindGitRoot()!
.GetDirectory("examples/CopyFiles");
DirectoryInfo outputDir = rootDir.GetDirectory("output");
FileInfo projectFile = rootDir.GetFile("CopyFiles.csproj");
this.Logger.Error("A {0}", rootDir);
// Clear out the output directory if we have an old one.
if (outputDir.Exists)
{
outputDir.Delete(true);
}
// Execute the generator. This will throw if there is an exception.
StringBuilder output = new();
try
{
await Cli
.Wrap("dotnet")
.WithWorkingDirectory(projectFile.DirectoryName!)
.WithArguments(
argumentsBuilder => argumentsBuilder
.Add("run")
.Add("--no-build")
.Add("--")
.Add("build"))
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(output))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(output))
.ExecuteAsync();
}
catch (Exception exception)
{
this.Logger.Fatal(
exception,
"There was an exception running the command:\n\n{Log:l}",
output);
throw;
}
// Make sure we have our output.
FileInfo aFile = outputDir.GetFile("a.txt");
Assert.True(aFile.Exists);
string aText = aFile.ReadAllText()
.Trim();
Assert.Equal("This is the 'A' file.", aText);
}
}