Reqnroll icon indicating copy to clipboard operation
Reqnroll copied to clipboard

#line directive contains only filename instead of relative path for subdirectory feature files

Open stgmt opened this issue 6 months ago • 4 comments

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

  1. IDE debugging broken: IDEs cannot map generated code back to original .feature files
  2. Incorrect stack traces: Error stack traces show only filename without path
  3. Navigation failures: "Go to definition" doesn't work from generated code

Steps to Reproduce

  1. Create a feature file in a subdirectory: Features/MyModule/Test.feature
  2. Build the project
  3. Check generated file: obj/.../Features/MyModule/Test.feature.cs
  4. 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.

stgmt avatar Aug 25 '25 00:08 stgmt

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.

clrudolphi avatar Aug 26 '25 10:08 clrudolphi

Before making a PR...

I cannot reproduce this. I have a feature file in a subfolder:

Image

The code behind contains a file name path...

Image

And debugging works fine...

Image

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?

gasparnagy avatar Aug 26 '25 11:08 gasparnagy

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

304NotModified avatar Aug 27 '25 21:08 304NotModified

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.

gasparnagy avatar Aug 28 '25 18:08 gasparnagy

Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info - thanks!

304NotModified avatar Dec 19 '25 04:12 304NotModified