diff options
5 files changed, 65 insertions, 30 deletions
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<string> 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<string> replaceCall { get; set; } + + [Value(2, Required=true, MetaName = "type", HelpText = "Types to patch.")] + public IEnumerable<string> 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<string> 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<string> replaceCall { get; set; } - - [Value(2, Required=true, MetaName = "type", HelpText = "Types to patch.")] - public IEnumerable<string> 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<FixFileStreamsCmd, ReplaceCallCmd>(args) .WithParsed<FixFileStreamsCmd>(opts => new FixFileStreams(opts)) .WithParsed<ReplaceCallCmd>(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 @@ <Import Project="$(MSBuildToolsPath)/Microsoft.CSharp.targets" /> <ItemGroup> - <Compile Include="patcher.cs"/> <Compile Include="assembly-info.cs"/> + <Compile Include="options.cs"/> + <Compile Include="patcher.cs"/> + <Compile Include="tests.cs"/> </ItemGroup> <PropertyGroup> @@ -14,6 +16,7 @@ <CecilInfo>Version=0.10.0.0$(Blurb)50cebf1cceb9d05e</CecilInfo> <CmdLineInfo>Version=2.2.1.0$(Blurb)de6f01bd326f8c32</CmdLineInfo> + <NUnitInfo>Version=3.10.1.0$(Blurb)2638cd05610744eb</NUnitInfo> </PropertyGroup> <ItemGroup> @@ -26,6 +29,7 @@ <SpecificVersion>False</SpecificVersion> <Private>True</Private> </Reference> + <Reference Include="nunit.framework, $(NUnitInfo)"/> </ItemGroup> <PropertyGroup> 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); + } +} |