2023-01-16 19:45:59 +00:00
|
|
|
using System;
|
2021-12-07 06:00:13 +00:00
|
|
|
using System.IO;
|
2023-01-16 19:45:59 +00:00
|
|
|
using System.Text;
|
2021-12-07 06:00:13 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using CliWrap;
|
|
|
|
|
|
|
|
using MfGames.IO.Extensions;
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.Tests;
|
2021-12-07 06:00:13 +00:00
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
namespace CopyFiles;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests the execution of the tool and ensures it is working correctly.
|
|
|
|
/// </summary>
|
|
|
|
public class CopyFilesTest : NitrideTestBase
|
2021-12-07 06:00:13 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
public CopyFilesTest(ITestOutputHelper output)
|
|
|
|
: base(output)
|
2021-12-07 06:00:13 +00:00
|
|
|
{
|
2022-06-05 18:44:51 +00:00
|
|
|
}
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
[Fact]
|
|
|
|
public async Task Run()
|
|
|
|
{
|
|
|
|
// Figure out the paths for this test.
|
|
|
|
DirectoryInfo rootDir =
|
2023-01-15 00:19:42 +00:00
|
|
|
typeof(CopyFilesProgram).GetDirectory()!.FindGitRoot()!
|
|
|
|
.GetDirectory("examples/CopyFiles");
|
2022-07-09 04:52:10 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
DirectoryInfo outputDir = rootDir.GetDirectory("output");
|
|
|
|
FileInfo projectFile = rootDir.GetFile("CopyFiles.csproj");
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
this.Logger.Error("A {0}", rootDir);
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
// Clear out the output directory if we have an old one.
|
|
|
|
if (outputDir.Exists)
|
|
|
|
{
|
|
|
|
outputDir.Delete(true);
|
|
|
|
}
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
// Execute the generator. This will throw if there is an exception.
|
2023-01-16 19:45:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
// Make sure we have our output.
|
|
|
|
FileInfo aFile = outputDir.GetFile("a.txt");
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
Assert.True(aFile.Exists);
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-07-09 04:52:10 +00:00
|
|
|
string aText = aFile.ReadAllText()
|
|
|
|
.Trim();
|
2021-12-07 06:00:13 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
Assert.Equal("This is the 'A' file.", aText);
|
2021-12-07 06:00:13 +00:00
|
|
|
}
|
|
|
|
}
|