-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathArgParserTests.cs
More file actions
40 lines (36 loc) · 1.32 KB
/
ArgParserTests.cs
File metadata and controls
40 lines (36 loc) · 1.32 KB
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
using System.IO;
using System.Linq;
using BizHawk.Client.Common;
namespace BizHawk.Tests.Client.Common
{
[TestClass]
public sealed class ArgParserTests
{
[DataRow("--config=config.json", "--help")]
[DataRow("--config=config.json", "--version")]
[TestMethod]
public void TestConfigWithHelpOrVersion(params string[] args)
=> Assert.AreEqual(0, ArgParser.ParseArguments(out _, args, fromUnitTest: true));
[TestMethod]
public void TestHelpSaysPassFlagsFirst()
{
using StringWriter output = new();
ArgParser.RunHelpActionForUnitTest(output);
var outputLines = output.ToString().Split('\n');
var usageLine = outputLines[outputLines.Index().First(tuple => tuple.Item.Contains("Usage:")).Index + 1].ToUpperInvariant();
Assert.IsTrue(usageLine.IndexOf("OPTION") < usageLine.IndexOf("ROM"));
}
[DataRow("rom.nes", "--nonexistent")]
[DataRow("--nonexistent", "rom.nes")]
[DataRow("--nonexistent", "--", "rom.nes")]
[TestMethod]
public void TestWithNonexistent(params string[] args)
{
int? exitCode = null;
var e = Assert.ThrowsExactly<ArgParser.ArgParserException>(() => exitCode = ArgParser.ParseArguments(out _, args, fromUnitTest: true));
Assert.AreNotEqual(0, exitCode ?? 1);
Assert.Contains(substring: "Unrecog", e.Message);
Assert.Contains(substring: "--nonexistent", e.Message);
}
}
}