Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Support for C# source generators?
niklaslundberg
#1 Posted : Thursday, November 19, 2020 9:12:09 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/19/2020(UTC)
Posts: 3
Location: Sweden

Are there any plans to support tests generated with C# source generators? Currently a generated xunit test is not discovered by NCrunch.
Remco
#2 Posted : Thursday, November 19, 2020 11:19:15 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,201

Thanks: 807 times
Was thanked: 1065 time(s) in 1012 post(s)
Hi,

It really depends on the generator. NCrunch doesn't have any mechanism to specifically exclude generators, but there is an infinite number of ways in which the generators can work.

How is the test being generated? Is it through a build task?
niklaslundberg
#3 Posted : Friday, November 20, 2020 7:07:33 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/19/2020(UTC)
Posts: 3
Location: Sweden

In this case it is Roslyn powered C# 9 source generators.
Remco
#5 Posted : Friday, November 20, 2020 8:56:30 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,201

Thanks: 807 times
Was thanked: 1065 time(s) in 1012 post(s)
Does it make any difference if you turn on the 'Copy referenced assemblies to workspace' setting?

Your success with generator will depend entirely on:

- When the generation is performed
- What is being generated
- What dependencies the generation has

You may need to delve into the generation code and reconcile this with the NCrunch constraints. It's impossible for us to warrant whether the product will work with any given generator as code generation allows virtually limitless possibility when it comes to development, and we have no control over the boundaries.
niklaslundberg
#6 Posted : Friday, November 20, 2020 10:55:26 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/19/2020(UTC)
Posts: 3
Location: Sweden

I'm doing some experiments to source generate a valid xunit test in a test project, using a source generator defined in another project within the solution. https://devblogs.microso...ng-c-source-generators/

So for instance there is a class in the test project
ATest
{
public object When() {...}
public void ThenSomething(object result)
{
// some assert based on the result, object would likely be a specific type
Assert.Eqaul("Something", result.ToString());
}
}

The code generator will generate an xunit test something like
ATest_Generated
{
private object _result;
private ATest _sut;
public ATest_Generated() {
_sut = new ATest();
_result = _sut.When();
}
[Fact]
public void ThenSomething() {
_sut.ThenSomething(_result);
}
}

That code will be part of the test projects compiled assembly.

My view is that any roslyn source generator sources should be picked up by NCrunch.

Currently the tests are not shown at all inNCrunch, but they appear In ReSharper's test runner since it compiles the code in a standard way before discovering and running the tests.
Remco
#7 Posted : Friday, November 20, 2020 11:47:25 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,201

Thanks: 807 times
Was thanked: 1065 time(s) in 1012 post(s)
I think that most likely the problem here is going to be the cross-project interaction. This would break NCrunch's project atomicity constraints.

Do you have any option for your code generation to be moved into the test project instead? So that it generates its own tests?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.071 seconds.