Skip to content

TUnit Support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 17, 2025
Merged

Conversation

thomhurst
Copy link
Contributor

Description

A project/package for easy integration with the TUnit testing framework.

Closed issues

#1

Checklist

  • Reviewed the contribution guidelines
  • Linked the issue(s) the PR closes
  • Implemented automated tests and checked coverage
  • Provided inline documentation comments for new public API
  • Ran the full solution build and validation locally

@thomhurst
Copy link
Contributor Author

@aivascu

The TUnit versioning system is unclear. Are you using ZeroVer for TUnit or a stable v1 is planned somewhere in the future?

There will be a v1. But Rider and VS have some issues still with the new Microsoft Testing Platform. So I want to wait for those fixes before I release v1, because I don't want to do an "official" release and it be an unpleasant experience for some people.

@aivascu
Copy link
Member

aivascu commented Apr 8, 2025

There will be a v1. But Rider and VS have some issues still with the new Microsoft Testing Platform. So I want to wait for those fixes before I release v1, because I don't want to do an "official" release and it be an unpleasant experience for some people.

@thomhurst I see. In this case I'll release the package under a zero-based version as well until you publish v1.

@thomhurst
Copy link
Contributor Author

@aivascu Did you review this?

@aivascu
Copy link
Member

aivascu commented May 10, 2025

@thomhurst hi, yeah kinda. I was just doing some changes to it.
Finally got a couple free days to work on open source. )

Copy link
Member

@aivascu aivascu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomhurst I'm going to push a few changes in a bit. Building the project in validation mode with all code style rules enabled, and .NET 8, kinda sent me down a rabbit hole of refactoring. )

There is one more issue I found in TUnit's source generator file StackTraceHiddenAttribute. This class uses the C# 12 bodyless class declaration (can't remember what it's called), that is not available for when building against older SDKs.
IMO since TUnit supports .NET Standard 2.0 I think it should also support use the version of the C# syntax available at the time when it came out (i.e. C# 8.0).
I haven't checked yet but it's likely that a test project on .NET Framework 4.8 with older build build tools might not be able to build TUnit tests.

@thomhurst
Copy link
Contributor Author

@thomhurst I'm going to push a few changes in a bit. Building the project in validation mode with all code style rules enabled, and .NET 8, kinda sent me down a rabbit hole of refactoring. )

There is one more issue I found in TUnit's source generator file StackTraceHiddenAttribute. This class uses the C# 12 bodyless class declaration (can't remember what it's called), that is not available for when building against older SDKs. IMO since TUnit supports .NET Standard 2.0 I think it should also support use the version of the C# syntax available at the time when it came out (i.e. C# 8.0). I haven't checked yet but it's likely that a test project on .NET Framework 4.8 with older build build tools might not be able to build TUnit tests.

Do you mean file scoped namespaces?

@aivascu
Copy link
Member

aivascu commented May 12, 2025

Do you mean file scoped namespaces?

No, I mean declarations like public class MyClass;. I'm not at my PC ATM, I'll send you the exact declaration later today.
But since you mentioned it, file scoped namespaces could also be an issue, depending on the SDK building the test project.
It's not a blocker for this PR, but it might be something you'd want to look into.

@aivascu
Copy link
Member

aivascu commented May 12, 2025

@thomhurst the generated file I mentioned looks like below. I couldn't reproduce a syntax error under older SDKs since it was not generated. Probably because the polyfill is not necessary under those targets?

image

namespace System.Diagnostics;

using System;
using System.Diagnostics.CodeAnalysis;

[AttributeUsage(
    AttributeTargets.Class |
    AttributeTargets.Method |
    AttributeTargets.Constructor |
    AttributeTargets.Struct,
    Inherited = false)]
sealed class StackTraceHiddenAttribute : Attribute;

I could however reproduce a primary constructor syntax error when I set the language version to 10 while building under .NET 8.0 SDK.

0>StackTraceHiddenAttribute.g.cs(12,51): Error CS8936 : Feature 'primary constructors' is not available in C# 10.0. Please use language version 12.0 or greater.

and the namespace error when I set the language version even lower.

0>StackTraceHiddenAttribute.g.cs(1,1): Error CS8400 : Feature 'file-scoped namespace' is not available in C# 8.0. Please use language version 10.0 or greater.

IMO auto-generated code should be as unambiguous and backward compatible as possible.

namespace System.Diagnostics
{
    [global::System.AttributeUsage(
        global::System.AttributeTargets.Class |
        global::System.AttributeTargets.Method |
        global::System.AttributeTargets.Constructor |
        global::System.AttributeTargets.Struct,
        Inherited = false)]
    internal sealed class StackTraceHiddenAttribute : global::System.Attribute
    {
    }
}

@thomhurst
Copy link
Contributor Author

I'll add it to my to-do list to make it more legacy friendly

@thomhurst
Copy link
Contributor Author

Apart from that, is the rest of the pr okay?

@aivascu
Copy link
Member

aivascu commented May 14, 2025

Apart from that, is the rest of the pr okay?

I think so, yes. I should have some time near eow to finish the changes and merge the PR.

@aivascu aivascu merged commit 655911c into AutoFixture:master May 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants