From a188825be983a81633577330944002608ac694f1 Mon Sep 17 00:00:00 2001 From: Brad Wilson Date: Tue, 18 Jan 2022 08:59:33 -0800 Subject: [PATCH] Port #2463 to v2 --- src/xunit.assert.nuspec | 6 +++- src/xunit.assert/Asserts | 2 +- src/xunit.execution/xunit.execution.csproj | 2 +- src/xunit.extensibility.core.nuspec | 6 ++++ src/xunit.extensibility.execution.nuspec | 8 +++++- .../Asserts/CollectionAssertsTests.cs | 28 +++++++++++++++++++ 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/xunit.assert.nuspec b/src/xunit.assert.nuspec index 5b16003e2..ed2290fc0 100644 --- a/src/xunit.assert.nuspec +++ b/src/xunit.assert.nuspec @@ -17,6 +17,7 @@ + @@ -24,5 +25,8 @@ + + + - \ No newline at end of file + diff --git a/src/xunit.assert/Asserts b/src/xunit.assert/Asserts index 08ea727ab..43e3e208a 160000 --- a/src/xunit.assert/Asserts +++ b/src/xunit.assert/Asserts @@ -1 +1 @@ -Subproject commit 08ea727abe286ecc3bf340959d909cba7b9b195e +Subproject commit 43e3e208a597bc1a4c77f2665f39f98e7401c157 diff --git a/src/xunit.execution/xunit.execution.csproj b/src/xunit.execution/xunit.execution.csproj index 43174d1f7..90ec93954 100644 --- a/src/xunit.execution/xunit.execution.csproj +++ b/src/xunit.execution/xunit.execution.csproj @@ -6,7 +6,7 @@ $(DefineConstants);XUNIT_FRAMEWORK true Xunit.Sdk - net452;netstandard1.1 + net452;netstandard1.1;netstandard2.0 diff --git a/src/xunit.extensibility.core.nuspec b/src/xunit.extensibility.core.nuspec index 4063c36ee..f3cad4d16 100644 --- a/src/xunit.extensibility.core.nuspec +++ b/src/xunit.extensibility.core.nuspec @@ -23,6 +23,9 @@ + + + @@ -36,5 +39,8 @@ + + + diff --git a/src/xunit.extensibility.execution.nuspec b/src/xunit.extensibility.execution.nuspec index 3c5039fc0..d42c30c07 100644 --- a/src/xunit.extensibility.execution.nuspec +++ b/src/xunit.extensibility.execution.nuspec @@ -20,6 +20,9 @@ + + + @@ -30,5 +33,8 @@ + + + - \ No newline at end of file + diff --git a/test/test.xunit.assert/Asserts/CollectionAssertsTests.cs b/test/test.xunit.assert/Asserts/CollectionAssertsTests.cs index b2f0bbbf4..9b51915d7 100644 --- a/test/test.xunit.assert/Asserts/CollectionAssertsTests.cs +++ b/test/test.xunit.assert/Asserts/CollectionAssertsTests.cs @@ -925,6 +925,14 @@ public static void Equivalence() Assert.Equal(expected, actual); } + + [Fact] + public static void EnumeratesOnlyOnce() + { + var expected = new[] { 1, 2, 3, 4, 5 }; + var actual = new RunOnceEnumerable(expected); + Assert.Equal(expected, actual); + } } public class EqualDictionary @@ -1350,6 +1358,26 @@ public static void PredicateTooManyMatches() } } + sealed class RunOnceEnumerable : IEnumerable + { + private readonly IEnumerable _source; + private bool _called; + + public RunOnceEnumerable(IEnumerable source) + { + _source = source; + } + + public IEnumerator GetEnumerator() + { + Assert.False(_called, "GetEnumerator() was called more than once"); + _called = true; + return _source.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } + sealed class SpyEnumerator : IEnumerable, IEnumerator { IEnumerator? innerEnumerator;