From 41d7467ed7d8418f6498323fd69d42ffa88eb76c Mon Sep 17 00:00:00 2001 From: Keegan Caruso Date: Wed, 27 Nov 2024 11:06:06 -0800 Subject: [PATCH] Use remote executor for tests using appcontext --- .../System.Linq/src/System/Linq/Select.cs | 2 +- .../System.Linq/tests/SkipWhileTests.cs | 32 +++++++++++++++---- .../tests/System.Linq.Tests.csproj | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Linq/src/System/Linq/Select.cs b/src/libraries/System.Linq/src/System/Linq/Select.cs index 79700032a69d7..db9adc9874030 100644 --- a/src/libraries/System.Linq/src/System/Linq/Select.cs +++ b/src/libraries/System.Linq/src/System/Linq/Select.cs @@ -60,7 +60,7 @@ private static IEnumerable SelectImplementation(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(iterator, selector); diff --git a/src/libraries/System.Linq/tests/SkipWhileTests.cs b/src/libraries/System.Linq/tests/SkipWhileTests.cs index a13a686cef3f3..5884d9c7ce3c1 100644 --- a/src/libraries/System.Linq/tests/SkipWhileTests.cs +++ b/src/libraries/System.Linq/tests/SkipWhileTests.cs @@ -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 @@ -62,14 +63,33 @@ public void RunOnce() Assert.Equal(Enumerable.Range(10, 10), Enumerable.Range(0, 20).RunOnce().SkipWhile((i, idx) => idx < 10)); } - [Fact] - public void SkipErrorWhenSourceErrors() + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public static void SkipErrorWhenSourceErrors_TrimFriendlySelectTrue() { - var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4); - using(var en = source.GetEnumerator()) + RemoteExecutor.Invoke(() => { - Assert.Throws(() => en.MoveNext()); - } + 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 expectedValues = [(decimal)1/2]; + Assert.Equal(expectedValues, valuesFromEnumerable); + }).Dispose(); + } + + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public void SkipErrorWhenSourceErrors_TrimFriendlySelectFalse() + { + RemoteExecutor.Invoke(() => + { + 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(() => en.MoveNext()); + } + }).Dispose(); } [Fact] diff --git a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj index 1e4692999a174..ac0ef5e696463 100644 --- a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj +++ b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj @@ -1,5 +1,6 @@ + true $(NetCoreAppCurrent) true