using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace Luneraria.Core.Tests
{
///
/// Console runner: dotnet run --project tools/dotnet/Luneraria.Core.Tests -- [suite ...]
/// Writes the JSON protocol to $LUNE_TEST_REPORT (if set) and exits non-zero on any failure.
/// Diagnostics: --float-probe out.json, --trace-mirror out.txt, --image scenario label out.png.
///
public static class Program
{
public static int Main(string[] args)
{
string root = FindRoot();
string golden = Path.Combine(root, "Assets/Luneraria/Tests/Core/Golden");
if (args.Length == 4 && args[0] == "--image")
return ReplayImage.Write(golden, args[1], args[2], Path.GetFullPath(args[3]));
if (args.Length == 2 && args[0] == "--trace-mirror")
{
// Scenario mirror_match of Golden/scenarios.json, round 7 (docs/port/U1.5-UNITY.md).
DivergenceTrace.Write(Path.GetFullPath(args[1]), 3, new[] { "glutpakt", "glutpakt", "glutpakt", "glutpakt", "glutpakt", "glutpakt" }, "verteidigung", 7);
return 0;
}
if (args.Length == 2 && args[0] == "--float-probe")
{
string probeRuntime = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
string json = FloatProbe.Run(golden).ToJson(probeRuntime, probeRuntime + ", Release");
File.WriteAllText(Path.GetFullPath(args[1]), json);
Console.Write(json);
return 0;
}
var wanted = new HashSet(args);
var report = new SuiteReport();
foreach (CheckSuite suite in CheckSuite.All())
{
if (wanted.Count > 0 && !wanted.Contains(suite.Name))
continue;
suite.GoldenDirectory = golden;
var clock = Stopwatch.StartNew();
bool ok = suite.Run();
clock.Stop();
report.Add(suite, clock.Elapsed.TotalSeconds);
Console.WriteLine("LUNE_U1_{0} {1}: {2} checks; {3} failures ({4:0.0} s)", ok ? "PASS" : "FAIL", suite.Name, suite.Checks, suite.Failures.Count, clock.Elapsed.TotalSeconds);
foreach (string failure in suite.Failures)
Console.WriteLine(" FAIL " + failure);
foreach (string note in suite.Notes)
Console.WriteLine(" note " + note);
}
string runtime = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
if (SuiteReport.TargetPath != null)
report.WriteTo(SuiteReport.TargetPath, runtime, runtime + ", Release");
Console.WriteLine(report.Failures == 0 ? "LUNE_U1_TESTS_OK" : "LUNE_U1_TESTS_FAILED");
return report.Failures == 0 ? 0 : 1;
}
static string FindRoot()
{
string dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Assets/Luneraria")))
dir = Path.GetDirectoryName(dir);
return dir ?? Directory.GetCurrentDirectory();
}
}
}