1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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<string, string> { ["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<ArgumentException>(() => 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);
}
}
|