using Godosa.Core.Runs; using Godosa.Core.Runs.Scripts; using Xunit; namespace Godosa.Core.Tests.Runs.Scripts; public class ScriptRunFlagsTests { private static ScriptRunFlags Parse(params string[] args) { var f = new ScriptRunFlags(); for (var i = 0; i < args.Length; i++) Assert.True(ScriptRunFlags.TryTake(args, ref i, f), args[i]); return f; } [Fact] public void ParsesEveryOption() { var f = Parse("--script", "main.steps", "--var", "res=1920x1080", "--var", "who=gil", "--output", "trace", "--no-cache", "--no-snapshots", "--from", "one", "--until", "two", "--step-cap", "500", "--report-dir", "out/runs/a"); Assert.True(f.NoSnapshots); Assert.False(f.ToOptions(new RunFlags(), null).Snapshots); Assert.Equal("main.steps", f.Script); Assert.Equal(new Dictionary { ["res"] = "1920x1080", ["who"] = "gil" }, f.Vars); Assert.Equal((OutputLevel.Trace, true, "one", "two", 500, "out/runs/a"), (f.Output!.Value, f.NoCache, f.From, f.Until, f.StepCap!.Value, f.ReportDir)); } [Fact] public void NotOurs_ReturnsFalse_IndexUnchanged() { var i = 0; Assert.False(ScriptRunFlags.TryTake(["--mute"], ref i, new ScriptRunFlags())); Assert.Equal(0, i); } [Theory] [InlineData("--var", "novalue")] [InlineData("--output", "loud")] [InlineData("--step-cap", "x")] public void BadValues_Throw(string option, string value) { var i = 0; Assert.Throws(() => ScriptRunFlags.TryTake([option, value], ref i, new ScriptRunFlags())); } [Fact] public void ToOptions_DeterministicSeedOutput() { var o = Parse("--output", "steps", "--no-cache").ToOptions(new RunFlags(Deterministic: true, Seed: 7), "out/runs/cache"); Assert.Equal((true, (ulong?)7UL, OutputLevel.Steps, OutputLevel.Steps, false, "out/runs/cache"), (o.Deterministic, o.Seed, o.Output, o.Floor, o.UseCache, o.CacheDir)); Assert.False(Parse("--nondeterministic").ToOptions(new RunFlags(), null).Deterministic); } }