Skip to content

Commit

Permalink
Converter tests: Add explicit interactive/non-interactive modes
Browse files Browse the repository at this point in the history
This can surely be factored simpler, but I don't care atm.
  • Loading branch information
yupferris committed Jul 24, 2021
1 parent 73e95a2 commit ea4e07a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 24 deletions.
10 changes: 8 additions & 2 deletions Tests/WaveSabreConvertTests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ namespace WaveSabreConvertTests
{
class Program
{
static void Main(string[] args)
static int Main(string[] args)
{
var testsDir = new DirectoryInfo("Tests");
var refsDir = new DirectoryInfo("Refs");

var interactive = args.Length == 1 ? args[0] == "-i" : false;

bool success = true;

foreach (var testFileInfo in testsDir.EnumerateFiles())
{
var testFileName = testFileInfo.Name;
var refFileName = testFileName + ".ref";

new Test().Run(testsDir.FullName + "\\" + testFileName, refsDir.FullName + "\\" + refFileName);
success |= new Test().Run(testsDir.FullName + "\\" + testFileName, refsDir.FullName + "\\" + refFileName, interactive);
}

return success ? 0 : 1;
}
}
}
103 changes: 81 additions & 22 deletions Tests/WaveSabreConvertTests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace WaveSabreConvertTests
{
class Test
{
public void Run(string testFileName, string refFileName)
public bool Run(string testFileName, string refFileName, bool interactive)
{
var testFileInfo = new FileInfo(testFileName);
var refFileInfo = new FileInfo(refFileName);
Expand All @@ -24,6 +24,8 @@ public void Run(string testFileName, string refFileName)

var testSong = new ProjectConverter().Convert(testFileName, logger);

bool success = false;

if (refFileInfo.Exists)
{
var refSong = JsonConvert.DeserializeObject<Song>(File.ReadAllText(refFileName));
Expand All @@ -32,6 +34,7 @@ public void Run(string testFileName, string refFileName)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("PASSED");
success = true;
}
else
{
Expand All @@ -43,39 +46,95 @@ public void Run(string testFileName, string refFileName)
Console.ForegroundColor = ConsoleColor.White;
diff.Print();
Console.ForegroundColor = originalColor;
while (true)
if (interactive)
{
Console.WriteLine("Update ref? (y/n)");
var line = Console.ReadLine().ToLower();
if (line.Length == 1)
Response response;
do
{
response = YesNoPrompt("Update ref?");
} while (response == Response.Invalid);
if (response == Response.Yes)
{
writeRef(refFileName, testSong);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("UPDATED REF");
success = true;
}
else
{
var c = line[0];
if (c == 'y')
{
writeRef(refFileName, testSong);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("UPDATED REF");
break;
}
else if (c == 'n')
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAILED");
break;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAILED");
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAILED");
}
}
}
else
{
writeRef(refFileName, testSong);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("CREATED REF");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("NO REF FOUND");
Console.ForegroundColor = originalColor;
if (interactive)
{
Response response;
do
{
response = YesNoPrompt("Create ref?");
} while (response == Response.Invalid);
if (response == Response.Yes)
{
writeRef(refFileName, testSong);
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("CREATED REF");
success = true;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAILED");
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("FAILED");
}
}

Console.ForegroundColor = originalColor;
Console.WriteLine();

return success;
}

enum Response
{
Yes,
No,
Invalid,
}

Response YesNoPrompt(string prompt)
{
Console.WriteLine(prompt + " (y/n)");
var line = Console.ReadLine().ToLower();
if (line.Length == 1)
{
var c = line[0];
if (c == 'y')
{
return Response.Yes;
}
else if (c == 'n')
{
return Response.No;
}
}
return Response.Invalid;
}

void writeRef(string refFileName, Song song)
Expand Down

0 comments on commit ea4e07a

Please sign in to comment.