Skip to content
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

Reqnroll in RootNamespace breaks generated Files #44

Closed
priveLupus opened this issue Feb 20, 2024 · 9 comments
Closed

Reqnroll in RootNamespace breaks generated Files #44

priveLupus opened this issue Feb 20, 2024 · 9 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@priveLupus
Copy link

priveLupus commented Feb 20, 2024

Reqnroll Version

1.0.1

Which test runner are you using?

xUnit

Test Runner Version Number

2.5.6

.NET Implementation

.NET 6.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

No response

Issue Description

We use several frameworks in our solution, so using the names as part of the project name, assembly name and root namespace seemed logical. Putting Reqnroll in the root namespace however creates the following errors:

  • The type or namespace name 'ScenarioInfo' does not exist in the namespace 'Lupus.Reqnroll' (are you missing an assembly reference?)
  • he type or namespace name 'ITestRunner' does not exist in the namespace 'Lupus.Reqnroll' (are you missing an assembly reference?)
    Any other name works.

Steps to Reproduce

create new Reqnroll Project in Visual Studio and add
<RootNamespace>Whatever.Reqnroll</RootNamespace>
to the project file

Link to Repro Project

No response

@priveLupus priveLupus added the bug Something isn't working label Feb 20, 2024
@gasparnagy
Copy link
Contributor

Yes, this seems to be a problem. (SpecFlow has the "TechTalk." prefix in the namespace, and that's why it was better working there.)

@priveLupus Could you please try to simulate the problem in a standard C# class library (without any feature file or Reqnroll package ref), that contains a file with an arbitrary class and a file that contains a class similar to the one Reqnroll generates?

Maybe that would help to figure out what we need to change in the generator to fix this issue. Maybe we just need to include a couple of more global:: prefix somewhere...

@priveLupus
Copy link
Author

I did. And it seems that adding the global:: prefix to all of them would fix my issues. Works with both solutions. Want me to try it out in the source code and open an PR if it works?

@gasparnagy
Copy link
Contributor

@priveLupus would be really appreciated. feel free to ask for help if you get stuck. The generator part of Reqnroll is pretty tricky sometimes.

@gasparnagy gasparnagy added the good first issue Good for newcomers label Mar 27, 2024
@gasparnagy
Copy link
Contributor

With the new Reqnroll.SystemTests the fix could be well guided. I think this will need a test in the GeneratorTestBase, so that it will be checked with all 3 test runners.

This would be a good feedback for the new system test concept.

@reqnroll/core-team anyone up for this?

@clrudolphi
Copy link
Contributor

I will attempt it.

Anything special or particular to be aware of with this issue?

@gasparnagy
Copy link
Contributor

@clrudolphi As mentioned above, hopefully the fix will be to just add some "global" prefixes to the type declarations. I think the trickier will be to make the test. The test can be very similar to the one in the smoke test class, but we probably need to have a step with data table as well. I haven't checked, but surely there must be a way to configure the project name to be generated, so you can set it to something ends with ".Reqnroll".

I can help if you get stuck.

@clrudolphi
Copy link
Contributor

clrudolphi commented Mar 27, 2024

OK. I think we have two options and would like your direction.
Option 1:
modify all references to ReqnRoll types in the generated source such as global::Reqnroll.ITestRunner

Option 2:
Set up a using alias at the top of the generated file such as:
using Reqnroll = Reqnroll;
and then modify all references to Reqnroll types as Reqnroll::ITestRunner

The first works because the Reqnroll namespace is opened at the global level in the ImplicitUsings.cs file.
The second works only if an alias is established within each generated file.

In either case, the referencing syntax has to change to include the namespace alias qualifier ::

Which would you prefer?

@gasparnagy
Copy link
Contributor

@clrudolphi I would go for option 1.

clrudolphi added a commit to clrudolphi/Reqnroll that referenced this issue Mar 28, 2024
This fix changes all references to Reqnroll types in the generated code as global:: references.
gasparnagy pushed a commit that referenced this issue Mar 28, 2024
* Fix for #44 Reqnroll in RootNamespace breaks generated Files
This fix changes all references to Reqnroll types in the generated code as global:: references.

* Moved test to GenerationTestBase.
Modified Xunit2TestGenerationProvider so that it's reference to Reqnroll.xUnit classes were prefixed with global::
Modified GeneratorTests unit test to include the global:: prefix when looking for the FeatureInfo constructor in generated source.

* Adjusted handling of Xunit generator's handling of references to Reqnroll types in order to not break VB generation.

* Revised comment in CodeDomHelper regarding support for global:: namespace resolution for VB.NET.
@gasparnagy
Copy link
Contributor

Fixed by #85, thx @clrudolphi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants