Skip to content

Commit

Permalink
works?
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Mar 31, 2024
1 parent f440461 commit 0735e2f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 16 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build & Test

on:
push:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target/
*.idea
*.iml
*DotSettings.user
**/TestResult.xml
2 changes: 2 additions & 0 deletions Osu.Stubs.Tests/Osu.Stubs.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Osu.Stubs.Tests</RootNamespace>
<TargetFramework>net462</TargetFramework>
<PlatformTarget>x86</PlatformTarget> <!-- Running in 32bit is necessary for loading in osu! -->
Expand Down Expand Up @@ -30,6 +31,7 @@

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0"/>
<PackageReference Include="NUnit" Version="4.1.0"/>
<PackageReference Include="NUnitLite" Version="4.1.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="NUnit.Analyzers" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 4 additions & 6 deletions Osu.Stubs.Tests/OsuApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions Osu.Stubs.Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using NUnitLite;

namespace Osu.Stubs.Tests;

public static class Program
{
public static int Main(string[] args) => new AutoRun().Execute(args);
}
31 changes: 26 additions & 5 deletions Osu.Stubs.Tests/TestStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,42 @@
using Osu.Utils.Extensions;
using Osu.Utils.Lazy;

#pragma warning disable CS0618 // Type or member is obsolete

namespace Osu.Stubs.Tests;

[TestFixture]
[Parallelizable]
public class TestStubs
{
[TestCaseSource(nameof(LoadStubs))]
public void TestStub(ILazy<MemberInfo> lazy) =>
Assert.DoesNotThrow(lazy.Fill);
public void TestStub(ILazy<MemberInfo> 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<ILazy<MemberInfo>> 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
Expand All @@ -27,10 +50,8 @@ private static IEnumerable<ILazy<MemberInfo>> 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);
Expand Down
2 changes: 1 addition & 1 deletion Osu.Utils/Lazy/LazyConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public LazyConstructor(string name, Func<ConstructorInfo> action)
public string Name { get; }

public ConstructorInfo Reference => this.GetReference(Name, _lazy);

public override string ToString() => $"{nameof(LazyConstructor)}({Name})";

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Osu.Utils/Lazy/LazyField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LazyField(string name, Func<FieldInfo> action)
public string Name { get; }

public FieldInfo Reference => this.GetReference(Name, _lazy);

public override string ToString() => $"{nameof(LazyField<object>)}({Name})";

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Osu.Utils/Lazy/LazyMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public LazyMethod(string name, Func<MethodInfo> action)
public string Name { get; }

public MethodInfo Reference => this.GetReference(Name, _lazy);

public override string ToString() => $"{nameof(LazyMethod)}({Name})";

/// <summary>
Expand Down

0 comments on commit 0735e2f

Please sign in to comment.