Skip to content

Commit

Permalink
Use remote executor for tests using appcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan Caruso committed Nov 27, 2024
1 parent 951704f commit 2f6ab0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libraries/System.Linq/src/System/Linq/Select.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static IEnumerable<TResult> SelectImplementation<TSource, TResult>(Func<
// for value types. We don't do the same for reference types because reference type
// expansion can happen lazily at runtime and the AOT compiler does postpone it (we
// don't need more code, just more data structures describing the new types).
if (/*ValueTypeTrimFriendlySelect &&*/ typeof(TResult).IsValueType)
if (ValueTypeTrimFriendlySelect && typeof(TResult).IsValueType)
{
#if OPTIMIZE_FOR_SIZE
return new IEnumerableSelectIterator<TSource, TResult>(iterator, selector);
Expand Down
30 changes: 25 additions & 5 deletions src/libraries/System.Linq/tests/SkipWhileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;

namespace System.Linq.Tests
Expand Down Expand Up @@ -62,14 +63,33 @@ public void RunOnce()
Assert.Equal(Enumerable.Range(10, 10), Enumerable.Range(0, 20).RunOnce().SkipWhile((i, idx) => idx < 10));
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public static void SkipErrorWhenSourceErrors_TrimFriendlySelectTrue()
{
RemoteExecutor.Invoke(() =>
{
AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", true);

var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
var valuesFromEnumerable = source.ToList();
List<decimal> expectedValues = [(decimal)1/2];
Assert.Equal(expectedValues, valuesFromEnumerable);
}).Dispose();
}

[Fact]
public void SkipErrorWhenSourceErrors()
public void SkipErrorWhenSourceErrors_TrimFriendlySelectFalse()
{
var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
using(var en = source.GetEnumerator())
RemoteExecutor.Invoke(() =>
{
Assert.Throws<DivideByZeroException>(() => en.MoveNext());
}
AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", false);

var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
using (var en = source.GetEnumerator())
{
Assert.Throws<DivideByZeroException>(() => en.MoveNext());
}
}).Dispose();
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Linq/tests/System.Linq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'browser'">true</DebuggerSupport>
</PropertyGroup>
Expand Down

0 comments on commit 2f6ab0c

Please sign in to comment.