Skip to content

Commit 41d7467

Browse files
author
Keegan Caruso
committed
Use remote executor for tests using appcontext
1 parent d96f35a commit 41d7467

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/libraries/System.Linq/src/System/Linq/Select.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static IEnumerable<TResult> SelectImplementation<TSource, TResult>(Func<
6060
// for value types. We don't do the same for reference types because reference type
6161
// expansion can happen lazily at runtime and the AOT compiler does postpone it (we
6262
// don't need more code, just more data structures describing the new types).
63-
if (/*ValueTypeTrimFriendlySelect &&*/ typeof(TResult).IsValueType)
63+
if (ValueTypeTrimFriendlySelect && typeof(TResult).IsValueType)
6464
{
6565
#if OPTIMIZE_FOR_SIZE
6666
return new IEnumerableSelectIterator<TSource, TResult>(iterator, selector);

src/libraries/System.Linq/tests/SkipWhileTests.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Generic;
5+
using Microsoft.DotNet.RemoteExecutor;
56
using Xunit;
67

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

65-
[Fact]
66-
public void SkipErrorWhenSourceErrors()
66+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
67+
public static void SkipErrorWhenSourceErrors_TrimFriendlySelectTrue()
6768
{
68-
var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
69-
using(var en = source.GetEnumerator())
69+
RemoteExecutor.Invoke(() =>
7070
{
71-
Assert.Throws<DivideByZeroException>(() => en.MoveNext());
72-
}
71+
AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", true);
72+
73+
var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
74+
var valuesFromEnumerable = source.ToList();
75+
List<decimal> expectedValues = [(decimal)1/2];
76+
Assert.Equal(expectedValues, valuesFromEnumerable);
77+
}).Dispose();
78+
}
79+
80+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
81+
public void SkipErrorWhenSourceErrors_TrimFriendlySelectFalse()
82+
{
83+
RemoteExecutor.Invoke(() =>
84+
{
85+
AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", false);
86+
87+
var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4);
88+
using (var en = source.GetEnumerator())
89+
{
90+
Assert.Throws<DivideByZeroException>(() => en.MoveNext());
91+
}
92+
}).Dispose();
7393
}
7494

7595
[Fact]

src/libraries/System.Linq/tests/System.Linq.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
34
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
45
<DebuggerSupport Condition="'$(DebuggerSupport)' == '' and '$(TargetOS)' == 'browser'">true</DebuggerSupport>
56
</PropertyGroup>

0 commit comments

Comments
 (0)