From 2d3dabe8af2ea4abc51f68891741db360ad11c75 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 17 Jul 2018 04:36:39 +0200 Subject: monogame-patcher: Restructure and add stub tests Mainly this is so we can prepare for running unit tests, so we get the latest version of NUnit and run the console test runner. Currently there is only a dummy test which always succeeds, but it's there so that we can fill out the boilerplate later. I also moved the option definitions into a separate file so they don't clutter up the main file. Signed-off-by: aszlig --- .../build-support/monogame-patcher/default.nix | 21 +++++++++++++++ .../build-support/monogame-patcher/src/options.cs | 28 ++++++++++++++++++++ .../build-support/monogame-patcher/src/patcher.cs | 30 +--------------------- .../monogame-patcher/src/patcher.csproj | 6 ++++- .../build-support/monogame-patcher/src/tests.cs | 10 ++++++++ 5 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 pkgs/games/build-support/monogame-patcher/src/options.cs create mode 100644 pkgs/games/build-support/monogame-patcher/src/tests.cs (limited to 'pkgs/games') diff --git a/pkgs/games/build-support/monogame-patcher/default.nix b/pkgs/games/build-support/monogame-patcher/default.nix index 1a06425e..457d124a 100644 --- a/pkgs/games/build-support/monogame-patcher/default.nix +++ b/pkgs/games/build-support/monogame-patcher/default.nix @@ -20,5 +20,26 @@ buildDotnetPackage { sha256 = "0wf8mzr16d2ni008m60rrk738v8ypk74llk6g8mlyx7rrlchnxaf"; outputFiles = [ "lib/net45/*" ]; }) + + (fetchNuGet { + baseName = "NUnit"; + version = "3.10.1"; + sha256 = "159m1wpb9yy2x77x7nl0647jkpzj5j801a2inhdl7hcjys8xrqxi"; + outputFiles = [ "lib/net45/*" ]; + }) + + (fetchNuGet { + baseName = "NUnit.ConsoleRunner"; + version = "3.8.0"; + sha256 = "1gspqzfhvpc8yapni7zcr5h2y025swihv78cw07v048l3myf3pzk"; + outputFiles = [ "tools/*" ]; + }) ]; + + doCheck = true; + checkPhase = '' + nunitLibs="$(pkg-config nunit.framework --variable=Libraries)" + MONO_PATH="$(dirname "$nunitLibs")" HOME="$PWD" \ + nunit3-console bin/Release/monogame-patcher.exe + ''; } diff --git a/pkgs/games/build-support/monogame-patcher/src/options.cs b/pkgs/games/build-support/monogame-patcher/src/options.cs new file mode 100644 index 00000000..ebe1f75b --- /dev/null +++ b/pkgs/games/build-support/monogame-patcher/src/options.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; + +using CommandLine; + +class GenericOptions +{ + [Option('i', "infile", Required=true, HelpText="Input file to transform.")] + public string inputFile { get; set; } + [Option('o', "outfile", HelpText="File to write transformed data to.")] + public string outputFile { get; set; } +} + +[Verb("fix-filestreams", HelpText="Fix System.IO.FileStream constructors" + +" to open files read-only.")] +class FixFileStreamsCmd : GenericOptions { + [Value(0, Required=true, MetaName = "type", HelpText = "Types to patch.")] + public IEnumerable typesToPatch { get; set; } +}; + +[Verb("replace-call", HelpText="Replace calls to types.")] +class ReplaceCallCmd : GenericOptions { + [Value(0, Min=2, Max=2, HelpText="Call to replace.")] + public IEnumerable replaceCall { get; set; } + + [Value(2, Required=true, MetaName = "type", HelpText = "Types to patch.")] + public IEnumerable typesToPatch { get; set; } + +}; diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.cs b/pkgs/games/build-support/monogame-patcher/src/patcher.cs index c1502ba1..794db98e 100644 --- a/pkgs/games/build-support/monogame-patcher/src/patcher.cs +++ b/pkgs/games/build-support/monogame-patcher/src/patcher.cs @@ -9,14 +9,6 @@ using Mono.Cecil; using CommandLine; -class GenericOptions -{ - [Option('i', "infile", Required=true, HelpText="Input file to transform.")] - public string inputFile { get; set; } - [Option('o', "outfile", HelpText="File to write transformed data to.")] - public string outputFile { get; set; } -} - class Command { protected string infile; protected string outfile; @@ -43,13 +35,6 @@ class Command { } } -[Verb("fix-filestreams", HelpText="Fix System.IO.FileStream constructors" - +" to open files read-only.")] -class FixFileStreamsCmd : GenericOptions { - [Value(0, Required=true, MetaName = "type", HelpText = "Types to patch.")] - public IEnumerable typesToPatch { get; set; } -}; - class FixFileStreams : Command { public FixFileStreams(FixFileStreamsCmd options) : base(options) { var filtered = this.module.Types @@ -99,16 +84,6 @@ class FixFileStreams : Command { } } -[Verb("replace-call", HelpText="Replace calls to types.")] -class ReplaceCallCmd : GenericOptions { - [Value(0, Min=2, Max=2, HelpText="Call to replace.")] - public IEnumerable replaceCall { get; set; } - - [Value(2, Required=true, MetaName = "type", HelpText = "Types to patch.")] - public IEnumerable typesToPatch { get; set; } - -}; - class ReplaceCall : Command { private string search; private string replace; @@ -156,11 +131,8 @@ class ReplaceCall : Command { } public class patcher { - public static int Main(string[] args) { - Parser.Default.ParseArguments< - GenericOptions, FixFileStreamsCmd, ReplaceCallCmd - >(args) + Parser.Default.ParseArguments(args) .WithParsed(opts => new FixFileStreams(opts)) .WithParsed(opts => new ReplaceCall(opts)); return 0; diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.csproj b/pkgs/games/build-support/monogame-patcher/src/patcher.csproj index cd8f1c19..994b78e5 100644 --- a/pkgs/games/build-support/monogame-patcher/src/patcher.csproj +++ b/pkgs/games/build-support/monogame-patcher/src/patcher.csproj @@ -4,8 +4,10 @@ - + + + @@ -14,6 +16,7 @@ Version=0.10.0.0$(Blurb)50cebf1cceb9d05e Version=2.2.1.0$(Blurb)de6f01bd326f8c32 + Version=3.10.1.0$(Blurb)2638cd05610744eb @@ -26,6 +29,7 @@ False True + diff --git a/pkgs/games/build-support/monogame-patcher/src/tests.cs b/pkgs/games/build-support/monogame-patcher/src/tests.cs new file mode 100644 index 00000000..8b9d3ee3 --- /dev/null +++ b/pkgs/games/build-support/monogame-patcher/src/tests.cs @@ -0,0 +1,10 @@ +using NUnit.Framework; + +[TestFixture] +public class PatcherTests { + [Test] + public void foo() { + // Dummy test + Assert.IsTrue(true); + } +} -- cgit 1.4.1