-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
F# support #573
Comments
Hey @KeterSCP . In all honesty I've never used F# but if it all compiles down to the same IL code, is there any reason this doesnt work with F#? Thats a genuine question. If changes or tweaks need to be made please let me know. A reproduction of any issues would be helpful, and if you want to help solve any challenges I'm open to that as like I said I'm not too versed in F# |
Hi @thomhurst! Thanks for the quick reply (and also nice job with this project!) So here are the problems I encountered while trying minimal example in F# (it doesn't even assert anything, just returns 0): module Tests
open TUnit.Core
[<Test>]
let ``My test`` () = 0
dotnet test
Restore complete (0.2s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
TestProject2 succeeded (1.3s) → bin\Debug\net8.0\TestProject2.dll
TestProject2 test failed with 1 error(s) (0.2s)
...\TestProject2\bin\Debug\net8.0\TestProject2.dll : error run failed: Tests failed: '...\TestProject2\bin\Debug\net8.0\TestResults\TestProject2_net8.0_x64.log' [net8.0|x64]
Test summary: total: 0, failed: 0, succeeded: 0, skipped: 0, duration: 0.2s
Build failed with 1 error(s) in 2.0s Log file contains following output:
|
Hmmm... Could you create a new repo with minimal repo please? Should help debug issues. I'll take a look but also might need your help if that's okay! |
Sure thing! Here is a separate repo, which demonstrates working example with XUnit and non-working example with TUnit: |
My understanding is that TUnit relies on C# code generation. What 'should' work however, is having a dedicated C# project just for the tests that references the F# project with the logic to be tested. I don't think that F# has support for source generation in the same way that C# has, so I don't think it's an option at this stage. |
Ah interesting. Does this essentially mean it's not a TUnit bug? I just (maybe naively) assumed that the nugrt packages I published would work for any .net language because it all compiles down to the same thing. If not I just need to see if I can tweak the source generator depending on theangjage |
You potentially know more in this space than me ;) So I'd say it's not a TUnit 'bug' at all. It's just one of the limitations of using the (C#) Source Generator concept. In an F# project, there is no C# compiler invocation, so I don't believe your source generator is even called. https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview |
Thanks for the detailed description that's really helpful! So would the solution basically be to determine whether we're in an F# solution and if so generate F# code instead of C#? I haven't actually done any experimentation on source generators with F# but I assume it's possible to check the language. The TUnit source generation isn't too complicated, so if F# needs it's own F# generated code, then let's make that happen :) |
Unfortunately the F# compiler doesn't support this. I'm not well versed in F#, but I think it's also missing core language support for things like 'partial classes' that were introduced to the C# language to help support source generation. I think the things lacking from F# in the source generator space make it problematic to support at all for something like TUnit. Two possible options might be:
Of the two options, the first one is probably 'nicer' (easier, with less maintenance hassle). |
FYI: Because both VB.NET and C# are based within the Roslyn compiler, it does appear that Source Generation might be possible for VB... dotnet/vblang#586 But F# isn't a Roslyn thing... so has some quite different interfaces. I guess technically it would be possible to use something like these: To do a pre-build trigger, parse the F# and do like a source generator for it... and then the Microsoft F# compiler would kick in and compile the 'proper' F# project (which would include all the source generated files). |
Oh damn this seems pretty complicated then. I guess for now I'll have to brand TUnit as C# only 😢 |
I think based on this, the answer to the original question is that there is no plans to support F#, mainly due to the lack of compiler APIs. Very sorry about this, but it's out of my control really 😢 |
Project description states that this is a
But .NET != C#
Are there any plans to support F# projects?
The text was updated successfully, but these errors were encountered: