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

Fake MsgBox crashes after setting return value for input box for all invocations #3720

Closed
rbloehm opened this issue Jan 22, 2018 · 1 comment · Fixed by #4132
Closed

Fake MsgBox crashes after setting return value for input box for all invocations #3720

rbloehm opened this issue Jan 22, 2018 · 1 comment · Fixed by #4132
Labels
bug Identifies work items for known bugs critical Marks a bug as a must-fix, showstopper issue feature-unit-testing
Milestone

Comments

@rbloehm
Copy link

rbloehm commented Jan 22, 2018

I am currently testing code in Excel VBA that involves a MsgBox and an InputBox. So I used "Fakes.InputBox.ReturnsWhen..." and "Fakes.MsgBox.Returns" statements as I thought appropriate.

In some cases this (reproducibly) leads to crashes and I can quickly glimpse the error message "Test raised an error. Specified cast is not valid."

Here you can find a minimal example to reproduce the issue (new, empty Excel 2016 *xlsm Workbook):

Option Explicit

Option Private Module

'@TestModule
'@Folder("Tests")

Private Assert As Rubberduck.AssertClass
Private Fakes As Rubberduck.FakesProvider

'@ModuleInitialize
Public Sub ModuleInitialize()
    'this method runs once per module.
    Set Assert = New Rubberduck.AssertClass
    Set Fakes = New Rubberduck.FakesProvider
End Sub

'@ModuleCleanup
Public Sub ModuleCleanup()
    'this method runs once per module.
    Set Assert = Nothing
    Set Fakes = Nothing
End Sub

'@TestMethod
Public Sub MsgBoxAfterInputBoxAnyInvocationFakeWorks()
    On Error GoTo TestFail
    
    Dim userInput As String

    Fakes.InputBox.ReturnsWhen "Prompt", "Second", "User entry 2"
    Fakes.MsgBox.Returns vbOK
    
    'This line crashes:
    MsgBox "This is faked", Title:="My Title"
    
    Fakes.MsgBox.Verify.Once

TestExit:
    Exit Sub
TestFail:
    Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
End Sub

Another version that leads to the same crash is:
'Fakes.InputBox.ReturnsWhen "Prompt", "Second", "User entry 2", 1
But this will not crash:
'Fakes.InputBox.ReturnsWhen "Prompt", "Second", "User entry 2", 2

Rubberduck version: Version 2.1.2.2738
Operating System: Microsoft Windows NT 10.0.14393.0, x64
Host Product: Microsoft Office 2016 x64
Host Version: 16.0.8431.2131
Host Executable: EXCEL.EXE

@Vogel612 Vogel612 added bug Identifies work items for known bugs feature-unit-testing critical Marks a bug as a must-fix, showstopper issue labels Jan 22, 2018
@retailcoder
Copy link
Member

Thanks for reporting! Could the setup with invocation index 2 isn't failing just because InputBox is only invoked once? We'll use that MCVE to get ourselves a stack trace, looks like there's a cast somewhere that's throwing... thanks a bunch!

@Vogel612 Vogel612 added this to ToDo in Semi-automatic bug tracker via automation Jan 26, 2018
@Vogel612 Vogel612 added this to TODO in Release 2.3.0 Apr 9, 2018
@Vogel612 Vogel612 added this to the 2.3.0 Release milestone Jun 20, 2018
@tommy9 tommy9 mentioned this issue Jun 26, 2018
Semi-automatic bug tracker automation moved this from ToDo to Done Jun 27, 2018
Release 2.3.0 automation moved this from TODO to Done Jun 27, 2018
Vogel612 added a commit that referenced this issue Jun 27, 2018
@Vogel612 Vogel612 modified the milestone: 2.3.0 Release Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies work items for known bugs critical Marks a bug as a must-fix, showstopper issue feature-unit-testing
Projects
Development

Successfully merging a pull request may close this issue.

3 participants