-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Description
Not entirely sure whether this is a bug or a feature request, but...
When code generators emit code that references TUnit.Core types, they probably should consistently use the global:: prefix for all type references. Without this, projects with certain namespace patterns will fail to compile due to C# namespace resolution rules.
Expected Behavior
Code generators that emit TUnit test code should probably always use the global:: prefix for all TUnit.Core type references.
Actual Behavior
C# namespace resolution walks up the namespace hierarchy before checking global scope. If a project's namespace contains TUnit as a segment (e.g. MySolution.TUnit.Tests), then a reference to TUnit.Core.SomeType will first look for MySolution.TUnit.Core.SomeType, which doesn't exist.
Steps to Reproduce
namespace MySolution.TUnit.Tests
{
public class MyTestClass
{
[global::TUnit.Core.BeforeAttribute(TUnit.Core.HookType.Class)]
public void Setup() { }
}
}
This code fails, as C# looks for MySolution.TUnit.Core.HookType first.
error CS0234: The type or namespace name "Core" does not exist in the namespace "MySolution.TUnit"
TUnit Version
1.12.82
.NET Version
.NET 10
Operating System
Windows
IDE / Test Runner
dotnet CLI (dotnet test / dotnet run)
Error Output / Stack Trace
CS0234 The type or namespace name 'Core' does not exist in the namespace 'Reqnroll.Retry.TUnit' (are you missing an assembly reference?)Additional Context
A (potentially incomplete) list of types for which this reproduces includes:
TUnit.Core.HookTypeTUnit.Core.TestContextTUnit.Core.RetryAttributeTUnit.Core.TestAttribute
IDE-Specific Issue?
- I've confirmed this issue occurs when running via
dotnet testordotnet run, not just in my IDE