Skip to content

Conversation

@licon4812
Copy link
Contributor

@licon4812 licon4812 commented May 16, 2025

This PR will allow people to create the TUnit project in either VB.NET or F#.

image
image

@licon4812
Copy link
Contributor Author

licon4812 commented May 16, 2025

A couple of challenges so far.

Both VB and F#

  • Cannot use Generic type in Attribute
    image
    image

F#

  • Due to F# handling type resolution differently than C# and VB.NET. I cannot do assertions in one line as GetAwaiter is ambiguous. Instead I had to handle assertions like the example bellow. PR FSharp Assertions #2388 should hopefully make this a lot better
[<Test>]
[<Arguments(1, 2, 3)>]
[<Arguments(2, 3, 5)>]
member _.DataDrivenArguments(a: int, b: int, c: int): Task =
    task {
        Console.WriteLine("This one can accept arguments from an attribute")
        let result = a + b
        // Properly await the assertion`
        let assertion = Assert.That(result).IsEqualTo(c)
        let awaiter = (assertion :> InvokableValueAssertionBuilder<int>).GetAwaiter()
        awaiter.GetResult() |> ignore
    }

@licon4812 licon4812 changed the title Adding F# and VB.NET Basic template Adding F# and VB.NET Basic templates May 16, 2025
@thomhurst
Copy link
Owner

Thanks @licon4812 !

I've spent this evening looking at the FSharp assertions. First time really using F# and I'm not enjoying it haha.

But I think I've figured out a custom operator to "await" the assertion in F#.

do! check Assert.That(...).IsSomething()

Back to being a one-liner, and I think it still reads okay. What do you think?

https://github.com/thomhurst/TUnit/blob/8e850b12773712368ae155a71c9ba58cda006481/TUnit.TestProject.FSharp/Tests.fs

@licon4812
Copy link
Contributor Author

Thanks @licon4812 !

I've spent this evening looking at the FSharp assertions. First time really using F# and I'm not enjoying it haha.

But I think I've figured out a custom operator to "await" the assertion in F#.

do! check Assert.That(...).IsSomething()

Back to being a one-liner, and I think it still reads okay. What do you think?

https://github.com/thomhurst/TUnit/blob/8e850b12773712368ae155a71c9ba58cda006481/TUnit.TestProject.FSharp/Tests.fs

I like that syntax. Simple to see and does allow us to use async instead of a task. Just a shame F# requires us to return or use something for it to not be ignored. Definetly way better than what I had to do in the template

@licon4812
Copy link
Contributor Author

@thomhurst I tried having a crack at making a non-generic implementation of ClassDataSourceAttribute. I didn't have much luck due to trimmer warnings

@thomhurst
Copy link
Owner

@thomhurst I tried having a crack at making a non-generic implementation of ClassDataSourceAttribute. I didn't have much luck due to trimmer warnings

That's next on my list to try and sort 😄 probably won't get a chance until Sunday now though

@licon4812
Copy link
Contributor Author

Updated the F# assertions in the template to utilize the new library provided in #2388

@thomhurst
Copy link
Owner

Pushing out a version as we speak with non-generic attributes which should unblock F# and VB 😄

@licon4812
Copy link
Contributor Author

licon4812 commented May 18, 2025

Pushing out a version as we speak with non-generic attributes which should unblock F# and VB 😄

Thanks @thomhurst

That worked well in both VB and F#.

Something else has come up now 😞

F#

image

VB

image

When I control-click on the attribute in VS, it takes me to this abstract constructor

image

@thomhurst
Copy link
Owner

I saw something similar. But it built fine.

Maybe restart your ide?

@licon4812 licon4812 marked this pull request as ready for review May 19, 2025 23:33
@licon4812
Copy link
Contributor Author

Just making some template tests now

@licon4812
Copy link
Contributor Author

should be ready to go @thomhurst

This is due to package not automatically being resolved
@licon4812
Copy link
Contributor Author

I had to add a specific package reference to FSharp Template for FSharpAssertions

<PackageReference Include="TUnit.Assertions.FSharp" Version="0.21.1" />	

This is due to the dotnet cli being unable to resolve it from the main TUnit package on build or restore. It worked perfectly fine in VS just not in the cli

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