#line directive contains only filename instead of relative path for subdirectory feature files
Bug Description
When feature files are located in subdirectories, the generated code-behind files (.feature.cs) contain incorrect #line directives that reference only the filename instead of the full relative path.
Root Cause
In Reqnroll.Generator/Generation/LinePragmaHandler.cs:22, the code uses:
_codeDomHelper.BindTypeToSourceFile(testType, Path.GetFileName(sourceFile));
This should be:
_codeDomHelper.BindTypeToSourceFile(testType, sourceFile);
Problem Impact
- IDE debugging broken: IDEs cannot map generated code back to original .feature files
- Incorrect stack traces: Error stack traces show only filename without path
- Navigation failures: "Go to definition" doesn't work from generated code
Steps to Reproduce
- Create a feature file in a subdirectory:
Features/MyModule/Test.feature - Build the project
- Check generated file:
obj/.../Features/MyModule/Test.feature.cs - Observe:
#line 1 "Test.feature"instead of#line 1 "Features/MyModule/Test.feature"
Expected Behavior
Generated #line directives should contain the full relative path from project root:
#line 1 "Features/MyModule/Test.feature"
Current Behavior
Generated #line directives contain only the filename:
#line 1 "Test.feature"
Environment
- Reqnroll version: 3.0.0
- .NET version: 8.0
- OS: macOS, Windows, Linux (cross-platform issue)
Proposed Fix
Replace Path.GetFileName(sourceFile) with sourceFile in LinePragmaHandler.cs:22 to preserve the full relative path.
Thank you for the extensively detailed report. You seem to have done all the research for a solution. The project would welcome a PR from you on this, if you are able.
Before making a PR...
I cannot reproduce this. I have a feature file in a subfolder:
The code behind contains a file name path...
And debugging works fine...
The line pragma file names should be relative to the .cs file, not to the project root! If the code behind file is in the same folder as the feature file, the file name should be fine!
Do you have maybe any other configuration or plugin or some tricky setup that causes this?
Are there any specs of the line directive in C#?
I only found this, but it's missing the information about the paths. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#error-and-warning-information
Are there any specs of the line directive in C#?
I only found this, but it's missing the information about the paths. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#error-and-warning-information
I'm not aware of one. But I wouldn't over worry this issue. Maybe @stgmt should respond with a concrete case that fails. E.g. about the exact IDE they used.
Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info - thanks!