From 0735e2f1c9f680546e9bc5fd44df29a784c043bf Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:33:14 -0700 Subject: [PATCH] works? --- .github/workflows/build.yml | 7 ++++-- .gitignore | 1 + Osu.Stubs.Tests/Osu.Stubs.Tests.csproj | 2 ++ Osu.Stubs.Tests/OsuApi.cs | 10 ++++----- Osu.Stubs.Tests/Program.cs | 8 +++++++ Osu.Stubs.Tests/TestStubs.cs | 31 +++++++++++++++++++++----- Osu.Utils/Lazy/LazyConstructor.cs | 2 +- Osu.Utils/Lazy/LazyField.cs | 2 +- Osu.Utils/Lazy/LazyMethod.cs | 2 +- 9 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 Osu.Stubs.Tests/Program.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 382144c..98dccfc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build +name: Build & Test on: push: @@ -34,9 +34,12 @@ jobs: - name: Build run: dotnet build Osu.Patcher.Injector - - name: Upload artifacts + - name: Upload Injector artifact uses: actions/upload-artifact@v4 with: name: osu!patcher-debug if-no-files-found: error path: .\Osu.Patcher.Injector\bin\Debug\net8.0\** + + - name: Run stub tests + run: dotnet run --project Osu.Stubs.Tests \ No newline at end of file diff --git a/.gitignore b/.gitignore index 604086d..962b066 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target/ *.idea *.iml *DotSettings.user +**/TestResult.xml diff --git a/Osu.Stubs.Tests/Osu.Stubs.Tests.csproj b/Osu.Stubs.Tests/Osu.Stubs.Tests.csproj index 4b33949..1ce1e03 100644 --- a/Osu.Stubs.Tests/Osu.Stubs.Tests.csproj +++ b/Osu.Stubs.Tests/Osu.Stubs.Tests.csproj @@ -1,6 +1,7 @@  + Exe Osu.Stubs.Tests net462 x86 @@ -30,6 +31,7 @@ + all diff --git a/Osu.Stubs.Tests/OsuApi.cs b/Osu.Stubs.Tests/OsuApi.cs index 56ccf72..178cb83 100644 --- a/Osu.Stubs.Tests/OsuApi.cs +++ b/Osu.Stubs.Tests/OsuApi.cs @@ -54,15 +54,13 @@ public static async Task DownloadOsu(string dir, ReleaseStream stream = ReleaseS { var updateFiles = await GetReleaseFiles(ReleaseStream.Stable40); - foreach (var updateFile in updateFiles) + Parallel.ForEach(updateFiles, updateFile => { Console.WriteLine($"Downloading {updateFile.FileName}"); + DownloadFile(updateFile.DownloadUrl, Path.Combine(dir, updateFile.FileName)).Wait(); + }); - await DownloadFile( - updateFile.DownloadUrl, - Path.Combine(dir, updateFile.FileName) - ); - } + Console.WriteLine("Finished downloading osu!"); } private static async Task DownloadFile(string url, string path) diff --git a/Osu.Stubs.Tests/Program.cs b/Osu.Stubs.Tests/Program.cs new file mode 100644 index 0000000..8e470e7 --- /dev/null +++ b/Osu.Stubs.Tests/Program.cs @@ -0,0 +1,8 @@ +using NUnitLite; + +namespace Osu.Stubs.Tests; + +public static class Program +{ + public static int Main(string[] args) => new AutoRun().Execute(args); +} \ No newline at end of file diff --git a/Osu.Stubs.Tests/TestStubs.cs b/Osu.Stubs.Tests/TestStubs.cs index 4dcaf95..c229428 100644 --- a/Osu.Stubs.Tests/TestStubs.cs +++ b/Osu.Stubs.Tests/TestStubs.cs @@ -6,6 +6,8 @@ using Osu.Utils.Extensions; using Osu.Utils.Lazy; +#pragma warning disable CS0618 // Type or member is obsolete + namespace Osu.Stubs.Tests; [TestFixture] @@ -13,12 +15,33 @@ namespace Osu.Stubs.Tests; public class TestStubs { [TestCaseSource(nameof(LoadStubs))] - public void TestStub(ILazy lazy) => - Assert.DoesNotThrow(lazy.Fill); + public void TestStub(ILazy lazy) => Assert.DoesNotThrow( + () => + { + try + { + lazy.Fill(); + } + catch (AggregateException e) + { + if (e.InnerException is ReflectionTypeLoadException typeLoadException) + { + throw new AggregateException(typeLoadException.LoaderExceptions); + } + + throw e.InnerException!; + } + } + ); + + [Test(Description = "Tests cannot be run in 64bit mode!", ExpectedResult = true)] + public static bool CheckIs32Bit() => !Environment.Is64BitProcess; private static IEnumerable> LoadStubs() { - var osuDir = Path.Combine(Environment.CurrentDirectory, "osu!"); + if (!CheckIs32Bit()) return []; + + var osuDir = Path.Combine(Assembly.GetExecutingAssembly().Location, "../osu!"); var osuExe = Path.Combine(osuDir, "osu!.exe"); if (!Directory.Exists(osuDir)) // TODO: check file hashes to force re-download @@ -27,10 +50,8 @@ private static IEnumerable> LoadStubs() OsuApi.DownloadOsu(osuDir).Wait(); } -#pragma warning disable CS0618 // Type or member is obsolete // Add osu! directory to assembly search path AppDomain.CurrentDomain.AppendPrivatePath(osuDir); -#pragma warning restore CS0618 // Type or member is obsolete // Load the osu! executable and it's dependencies as assemblies without executing Assembly.LoadFile(osuExe); diff --git a/Osu.Utils/Lazy/LazyConstructor.cs b/Osu.Utils/Lazy/LazyConstructor.cs index a902450..b80aa2c 100644 --- a/Osu.Utils/Lazy/LazyConstructor.cs +++ b/Osu.Utils/Lazy/LazyConstructor.cs @@ -29,7 +29,7 @@ public LazyConstructor(string name, Func action) public string Name { get; } public ConstructorInfo Reference => this.GetReference(Name, _lazy); - + public override string ToString() => $"{nameof(LazyConstructor)}({Name})"; /// diff --git a/Osu.Utils/Lazy/LazyField.cs b/Osu.Utils/Lazy/LazyField.cs index c016ba7..7911288 100644 --- a/Osu.Utils/Lazy/LazyField.cs +++ b/Osu.Utils/Lazy/LazyField.cs @@ -27,7 +27,7 @@ public LazyField(string name, Func action) public string Name { get; } public FieldInfo Reference => this.GetReference(Name, _lazy); - + public override string ToString() => $"{nameof(LazyField)}({Name})"; /// diff --git a/Osu.Utils/Lazy/LazyMethod.cs b/Osu.Utils/Lazy/LazyMethod.cs index 5a7768d..3895007 100644 --- a/Osu.Utils/Lazy/LazyMethod.cs +++ b/Osu.Utils/Lazy/LazyMethod.cs @@ -29,7 +29,7 @@ public LazyMethod(string name, Func action) public string Name { get; } public MethodInfo Reference => this.GetReference(Name, _lazy); - + public override string ToString() => $"{nameof(LazyMethod)}({Name})"; ///