Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Jun 23, 2024
1 parent 5981f38 commit da05d0d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Version>1.9.0-pre2</Version>
<FodyVersion>6.8.0</FodyVersion>
<FodyVersion>6.8.1</FodyVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/InlineIL.Tests/InlineIL.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageReference Include="FodyHelpers" Version="$(FodyVersion)" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 0 additions & 22 deletions src/InlineIL.Tests/Support/DebugTestAttribute.cs

This file was deleted.

51 changes: 51 additions & 0 deletions src/InlineIL.Tests/Support/Facts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

namespace InlineIL.Tests.Support;

public abstract class SkippableFactAttribute : FactAttribute
{
public sealed override string? Skip
{
get => base.Skip ?? GetSkipMessage();
set => base.Skip = value;
}

protected abstract string? GetSkipMessage();
}

public class DebugTestAttribute : SkippableFactAttribute
{
protected override string? GetSkipMessage()
=> Debugger.IsAttached ? null : "Debug test";
}

public class ReleaseFactAttribute : SkippableFactAttribute
{
private readonly Type _typeFromAssembly;

public ReleaseFactAttribute(Type typeFromAssembly)
=> _typeFromAssembly = typeFromAssembly;

protected override string? GetSkipMessage()
{
if (((_typeFromAssembly.Assembly.GetCustomAttribute<DebuggableAttribute>()?.DebuggingFlags ?? DebuggableAttribute.DebuggingModes.Default) & DebuggableAttribute.DebuggingModes.DisableOptimizations) != 0)
return "Inconclusive in debug builds";

return null;
}
}

public class VarargFactAttribute : SkippableFactAttribute
{
protected override string? GetSkipMessage()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.ProcessArchitecture is not (Architecture.X86 or Architecture.X64))
return "Varargs are not supported on this platform";

return null;
}
}
31 changes: 0 additions & 31 deletions src/InlineIL.Tests/Support/ReleaseFactAttribute.cs

This file was deleted.

28 changes: 16 additions & 12 deletions src/InlineIL.Tests/Weaving/MethodRefTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using InlineIL.Tests.Common;
using InlineIL.Tests.Support;
Expand Down Expand Up @@ -421,16 +420,6 @@ public void should_call_conversion_operators()
result.ShouldEqual([1, 2, 3, 4, 5, 6, 101, 102, 1, 3, 102]);
}

[Fact]
public void should_call_vararg_method()
{
if (NetStandard || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.ProcessArchitecture is not (Architecture.X86 or Architecture.X64))
return;

var result = (int[])GetInstance().CallVarArgMethod();
result.ShouldEqual([1, 2, 3, 0, 0]);
}

[Fact]
public void should_report_generic_args_on_normal_method()
{
Expand Down Expand Up @@ -676,11 +665,26 @@ public void should_call_generic_method_of_forwarded_type()
var result = (IEnumerable<string>)GetInstance().CallGenericMethodOfForwardedType();
result.ShouldEqual(["Hello", "Hello"]);
}

[VarargFact]
public void should_call_vararg_method()
{
var result = (int[])GetInstance().CallVarArgMethod();
result.ShouldEqual([1, 2, 3, 0, 0]);
}
}
#endif

#if NETFRAMEWORK
public class MethodRefTestsFramework : MethodRefTestsBase;
public class MethodRefTestsFramework : MethodRefTestsBase
{
[VarargFact]
public void should_call_vararg_method()
{
var result = (int[])GetInstance().CallVarArgMethod();
result.ShouldEqual([1, 2, 3, 0, 0]);
}
}
#endif

[UsedImplicitly]
Expand Down

0 comments on commit da05d0d

Please sign in to comment.