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

Fix: Reqnroll generates invalid code for rule backgrounds in Visual Basic #284

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# [vNext]
* Fix: Rule Backgounds cause External Data Plugin to fail (#271) @clrudolphi

## Bug fixes:
* Modified VersionInfo class to force it to pull version information from the Reqnroll assembly

* Fix: Rule Backgounds cause External Data Plugin to fail (#271)
* Fix: VersionInfo class might provide the version of the runner instead of the version of Reqnroll (#248)
* Fix: Reqnroll.CustomPlugin NuGet package has a version mismatch for the System.CodeDom dependency (#244)
* Reqnroll.Verify fails to run parallel tests determinately (#254). See our [verify documentation](docs/integrations/verify.md) on how to set up your test code to enable parallel testing.
* Fix: Reqnroll.Verify fails to run parallel tests determinately (#254). See our [verify documentation](docs/integrations/verify.md) on how to set up your test code to enable parallel testing.
* Fix: Reqnroll generates invalid code for rule backgrounds in Visual Basic (#283)

*Contributors of this release (in alphabetical order):* @ajeckmans, @clrudolphi, @UL-ChrisGlew
*Contributors of this release (in alphabetical order):* @ajeckmans, @clrudolphi, @gasparnagy, @UL-ChrisGlew

# v2.1.0 - 2024-08-30

Expand Down
4 changes: 2 additions & 2 deletions Reqnroll.Generator/CodeDom/CodeDomHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public CodeStatement GetDisableWarningsPragma()
case CodeDomProviderLanguage.CSharp:
return new CodeSnippetStatement("#pragma warning disable");
case CodeDomProviderLanguage.VB:
return new CodeCommentStatement("#pragma warning disable"); //not supported in VB
return new CodeSnippetStatement("#Disable Warning BC42356"); //in VB warning codes must be listed explicitly
}
return new CodeCommentStatement("#pragma warning disable");
}
Expand All @@ -119,7 +119,7 @@ public CodeStatement GetEnableWarningsPragma()
case CodeDomProviderLanguage.CSharp:
return new CodeSnippetStatement("#pragma warning restore");
case CodeDomProviderLanguage.VB:
return new CodeCommentStatement("#pragma warning restore"); //not supported in VB
return new CodeSnippetStatement("#Enable Warning BC42356"); //in VB warning codes must be listed explicitly
}
return new CodeCommentStatement("#pragma warning restore");
}
Expand Down
7 changes: 2 additions & 5 deletions Reqnroll.Generator/Generation/ScenarioPartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ private IEnumerable<CodeStatement> GenerateBackgroundStatementsForRule(TestClass
if (background == null) return new List<CodeStatement>();

var statements = new List<CodeStatement>();
using (new SourceLineScope(_reqnrollConfiguration, _codeDomHelper, statements, context.Document.SourceFilePath, background.Location))
foreach (var step in background.Steps)
{
foreach (var step in background.Steps)
{
GenerateStep(context, statements, step, null);
}
GenerateStep(context, statements, step, null);
}

return statements;
Expand Down
12 changes: 12 additions & 0 deletions Tests/Reqnroll.SystemTests/Generation/GenerationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public void GeneratorAllIn_sample_can_be_handled()
ShouldAllScenariosPass();
}

[TestMethod]
public void GeneratorAllIn_sample_can_be_handled_with_VisualBasic()
{
_testRunConfiguration.ProgrammingLanguage = ProgrammingLanguage.VB;

PrepareGeneratorAllInSamples();

ExecuteTests();

ShouldAllScenariosPass();
}

[TestMethod]
public void Handles_simple_scenarios_without_namespace_collisions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,66 @@ Public Class {0}

public override ProjectFile GenerateLoggerClass(string pathToLogFile)
{
string fileContent = $@"
Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Threading.Tasks

Friend Module Log
Private Const LogFileLocation As String = ""{pathToLogFile}""

Friend Sub LogStep(<CallerMemberName()> Optional stepName As String = Nothing)
File.AppendAllText(LogFileLocation, $""-> step: {{stepName}}{{Environment.NewLine}}"")
End Sub

Friend Sub LogHook(<CallerMemberName()> Optional stepName As String = Nothing)
File.AppendAllText(LogFileLocation, $""-> hook: {{stepName}}{{Environment.NewLine}}"")
End Sub

Friend Async Function LogHookIncludingLockingAsync(
<CallerMemberName> ByVal Optional stepName As String = Nothing) As Task
File.AppendAllText(LogFileLocation, $""->waiting for hook lock: {{stepName}}{{Environment.NewLine}}"")
Await WaitForLockAsync()
File.AppendAllText(LogFileLocation, $""-> hook: {{stepName}}{{Environment.NewLine}}"")
End Function

Private Async Function WaitForLockAsync() As Task
Dim lockFile = LogFileLocation & "".lock""

While True

Dim succeeded = True
Try
Using File.Open(lockFile, FileMode.CreateNew)
End Using
Exit While
Catch __unusedIOException1__ As IOException
succeeded = False
End Try
If Not succeeded Then
Await Task.Delay(1000)
End If
End While

File.Delete(lockFile)
End Function
End Module
";
string fileContent =
$$"""
Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Threading.Tasks

Friend Module Log
Private Const LogFileLocation As String = "{{pathToLogFile}}"

Private Sub Retry(number As Integer, action As Action)
Try
action
Catch ex As Exception
Dim i = number - 1
If (i = 0)
Throw
End If
System.Threading.Thread.Sleep(500)
Retry(i, action)
End Try
End Sub

Friend Sub LogStep(<CallerMemberName()> Optional stepName As String = Nothing)
Retry(5, sub() File.AppendAllText(LogFileLocation, $"-> step: {stepName}{Environment.NewLine}"))
End Sub

Friend Sub LogHook(<CallerMemberName()> Optional stepName As String = Nothing)
Retry(5, sub() File.AppendAllText(LogFileLocation, $"-> hook: {stepName}{Environment.NewLine}"))
End Sub

Friend Async Function LogHookIncludingLockingAsync(
<CallerMemberName> ByVal Optional stepName As String = Nothing) As Task
File.AppendAllText(LogFileLocation, $"->waiting for hook lock: {stepName}{Environment.NewLine}")
Await WaitForLockAsync()
File.AppendAllText(LogFileLocation, $"-> hook: {stepName}{Environment.NewLine}")
End Function

Private Async Function WaitForLockAsync() As Task
Dim lockFile = LogFileLocation & ".lock"

While True

Dim succeeded = True
Try
Using File.Open(lockFile, FileMode.CreateNew)
End Using
Exit While
Catch __unusedIOException1__ As IOException
succeeded = False
End Try
If Not succeeded Then
Await Task.Delay(1000)
End If
End While

File.Delete(lockFile)
End Function
End Module
""";
return new ProjectFile("Log.vb", "Compile", fileContent);
}

Expand Down