Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Compiler warning TUnit0023 for variable that cannot be disposed #4243

Copy link
Copy link

Description

@FlukeFan
Issue body actions

Description

The warning TUnit0023 is given for a member variable of type Func<IDisposable>, but the member variable itself cannot be disposed of.

Expected Behavior

I would not expect a compiler warning.

Actual Behavior

Compiling the below code results in the warning error TUnit0023: _factory should be disposed within a clean up method.

Steps to Reproduce

Compile the following code in a TUnit project:

public interface IMyInterface : IDisposable
{
}

public class MyClass : IMyInterface
{
    public void Dispose()
    {
        Console.WriteLine("disposed");
    }
}

public class ExampleTest
{
    private readonly Func<IMyInterface> _factory = () => new MyClass();

    [Test]
    public async Task Test1()
    {
        using var t = _factory();
    }
}

TUnit Version

1.9.2

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

error TUnit0023: _factory should be disposed within a clean up method

Additional Context

Image

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE
Reactions are currently unavailable

Metadata

Metadata

Labels

bugSomething isn't workingSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.