Skip to content

Commit 7261c23

Browse files
控制变量,新增 Rougamo.Mono.Tests 测试项目和 run-issue108-test.bat 验证脚本,逐步验证修复效果(#108
1 parent a8c41db commit 7261c23

6 files changed

Lines changed: 90 additions & 1 deletion

File tree

test/Rougamo.Fody.Tests/IssueTest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Issues;
1+
using Issues;
22
using Issues.Attributes;
33
using System;
44
using System.Collections.Generic;
@@ -269,5 +269,11 @@ public void Issue107Test()
269269
var instance = Assembly.GetInstance(nameof(Issue107));
270270
instance.Test();
271271
}
272+
[Fact]
273+
public void Issue108Test()
274+
{
275+
var instance = Assembly.GetInstance("Issue108`1", false, t => t.MakeGenericType(typeof(string)));
276+
instance.CatchAndGetStackTrace(108, "mono-stacktrace");
277+
}
272278
}
273279
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Xunit;
2+
using Rougamo.Fody.Tests;
3+
4+
namespace Rougamo.Mono.Tests
5+
{
6+
public class IssueReproductionTests
7+
{
8+
[Fact]
9+
public void Test_Mono_Runtime_Does_Not_Crash()
10+
{
11+
var weavedAssembly = new WeavedAssembly("Issues");
12+
var instance = weavedAssembly.GetInstance("Issue108`1", false, t => t.MakeGenericType(typeof(string)));
13+
var result = instance.CatchAndGetStackTrace(108, "mono-stacktrace");
14+
Assert.True(true);
15+
}
16+
}
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net48</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
10+
<PackageReference Include="xunit" Version="2.4.2" />
11+
<PackageReference Include="xunit.runner.console" Version="2.4.2">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
<PrivateAssets>all</PrivateAssets>
14+
</PackageReference>
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
<PrivateAssets>all</PrivateAssets>
18+
</PackageReference>
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\TestAssemblies\Issues\Issues.csproj" />
23+
<ProjectReference Include="..\Rougamo.Fody.Tests\Rougamo.Fody.Tests.csproj" />
24+
</ItemGroup>
25+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Rougamo;
2+
3+
namespace Issues.Attributes;
4+
5+
public class _108_Attribute : MoAttribute
6+
{
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Issues.Attributes;
2+
using System;
3+
4+
namespace Issues;
5+
6+
public class Issue108<T>
7+
{
8+
[_108_]
9+
public string CatchAndGetStackTrace(int code = 108, string message = "mono-stacktrace")
10+
{
11+
try
12+
{
13+
ThrowCore(code, message);
14+
return string.Empty;
15+
}
16+
catch (Exception ex)
17+
{
18+
return ex.StackTrace ?? string.Empty;
19+
}
20+
}
21+
22+
private void ThrowCore(int code, string message)
23+
{
24+
throw new InvalidOperationException($"{typeof(T).Name}:{code}:{message}");
25+
}
26+
}

test/run-issue108-test.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@echo off
2+
echo Building Issues to ensure weaving...
3+
dotnet build %~dp0TestAssemblies\Issues\Issues.csproj -c Debug
4+
echo Building Mono Issue108 Test...
5+
dotnet build %~dp0Rougamo.Mono.Tests\Rougamo.Mono.Tests.csproj -c Debug
6+
echo Running Issue108 xUnit via Mono...
7+
mono %USERPROFILE%\.nuget\packages\xunit.runner.console\2.4.2\tools\net472\xunit.console.exe %~dp0Rougamo.Mono.Tests\bin\Debug\net48\Rougamo.Mono.Tests.dll
8+
pause

0 commit comments

Comments
 (0)