Skip to content

Commit

Permalink
[Tests] Allow to ignore tests that fail on the interpreter. (xamarin#…
Browse files Browse the repository at this point in the history
…6802)

There are some failures that only happen in the interpreter. We add a
TestRuntime method that allow to check if the interpreter is used.
  • Loading branch information
mandel-macaque authored Aug 21, 2019
1 parent 9b6705b commit 55a95cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions tests/EmbeddedResources/EmbeddedResources.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -37,12 +37,16 @@
<ItemGroup>
<Reference Include="Xamarin.iOS" />
<Reference Include="MonoTouch.NUnitLite" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Include="ResourcesTest.cs" />
<Compile Include="..\common\TestRuntime.cs">
<Link>TestRuntime.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Welcome.resx">
Expand All @@ -59,4 +63,4 @@
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
</Project>
7 changes: 6 additions & 1 deletion tests/EmbeddedResources/ResourcesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.IO;
using System.Resources;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
using NUnit.Framework;

#if XAMCORE_2_0
Expand All @@ -30,8 +32,11 @@ public class ResourcesTest {
[Test]
public void Embedded ()
{

#if __TVOS__
Assert.Ignore ("This test is disabled on TVOS."); // Randomly crashed on tvOS -> https://github.com/xamarin/maccore/issues/1909
if (TestRuntime.CheckExecutingWithInterpreter ())
Assert.Ignore ("This test is disabled on TVOS."); // Randomly crashed on tvOS -> https://github.com/xamarin/maccore/issues/1909

#endif

#if MONOMAC
Expand Down
15 changes: 15 additions & 0 deletions tests/common/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Reflection.Emit;

#if XAMCORE_2_0
using AVFoundation;
Expand Down Expand Up @@ -111,6 +112,20 @@ public static void IgnoreInCI (string message)
NUnit.Framework.Assert.Ignore (message);
}

public static bool CheckExecutingWithInterpreter ()
{
// until System.Runtime.CompilerServices.RuntimeFeature.IsSupported("IsDynamicCodeCompiled") returns a valid result, atm it
// always return true, try to build an object of a class that should fail without introspection, and catch the exception to do the
// right thing
try {
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (null, AssemblyBuilderAccess.RunAndSave);
return true;
} catch (PlatformNotSupportedException) {
// we do not have the interpreter, lets continue
return false;
}
}

public static void AssertXcodeVersion (int major, int minor, int build = 0)
{
if (CheckXcodeVersion (major, minor, build))
Expand Down

0 comments on commit 55a95cf

Please sign in to comment.