Skip to content

Commit fb4e7af

Browse files
committed
Remove async-without-await warnings in CoreAssertionFixture
1 parent 9370bf5 commit fb4e7af

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,4 @@ async\method: Suffix with `Async` =\> `GetDataAsync()`
418418

419419
- Expression compilation can emit invalid IL on some runtimes; fall back to `Compile(preferInterpretation: true)` when evaluating expressions to avoid CI-only `InvalidProgramException`.
420420
- Byref-like expression trees (e.g., `Span<T>`, `ReadOnlySpan<T>`) cannot be boxed; convert them to arrays before evaluation to avoid interpreter type load errors.
421+
- `NUnit.Assert.ThrowsAsync<T>()` returns the exception instance (not a `Task`), so async tests should await a real async assertion (e.g., `action.Should().ThrowAsync<T>()`) to avoid CS1998 warnings.

learnings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ This document is organized by topic to consolidate key learnings about the proje
129129
- **DynamicInvoke Cross-Platform Issues:** Using `Expression.Lambda(expression).Compile().DynamicInvoke()` can fail on CI/certain runtimes with `NotSupportedException: Specified method is not supported` - use strongly-typed `Expression.Lambda<Func<object>>(Expression.Convert(expression, typeof(object))).Compile()()` for direct invocation without reflection
130130
- **Expression.Compile InvalidProgramException:** Expression compilation can emit invalid IL on some runtimes; prefer `Compile(preferInterpretation: true)` or catch `InvalidProgramException` and recompile in interpreted mode to ensure value extraction works on CI
131131
- **ByRef-like expression evaluation:** Ref structs (e.g., `Span<T>`, `ReadOnlySpan<T>`) cannot be boxed to `object`; convert them to arrays (e.g., `MemoryExtensions.ToArray`) before value extraction to avoid interpreter `TypeLoadException`/`ArgumentException`.
132+
- **NUnit Assert.ThrowsAsync return type:** `Assert.ThrowsAsync<T>()` returns the exception instance, not a `Task`, so async test methods need an explicit awaitable (e.g., `action.Should().ThrowAsync<T>()`) to avoid CS1998 warnings.
132133

133134
## String Diffing Implementation (Increment 5)
134135

src/SharpAssert.Tests/CoreAssertionFixture.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ public async Task ThrowsAsync_should_pass_when_expected_exception()
101101
throw new InvalidOperationException();
102102
});
103103

104-
var action = async () => Assert(result);
105-
await action.Should().NotThrowAsync();
104+
Action action = () => Assert(result);
105+
action.Should().NotThrow();
106106
}
107107

108108
[Test]
109109
public async Task ThrowsAsync_should_fail_wrong_type()
110110
{
111-
NUnit.Framework.Assert.ThrowsAsync<SharpAssertionException>(async () =>
112-
await ThrowsAsync<NullReferenceException>(async () =>
113-
{
114-
await Task.Yield();
115-
throw new ArgumentException();
116-
}));
111+
var action = async () => await ThrowsAsync<NullReferenceException>(async () =>
112+
{
113+
await Task.Yield();
114+
throw new ArgumentException();
115+
});
116+
117+
await action.Should().ThrowAsync<SharpAssertionException>();
117118
}
118119
}
119120
}

0 commit comments

Comments
 (0)