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

Wish: "Jump to error" or "Fix" button #7

Open
cwollenhaupt opened this issue Dec 7, 2017 · 0 comments
Open

Wish: "Jump to error" or "Fix" button #7

cwollenhaupt opened this issue Dec 7, 2017 · 0 comments

Comments

@cwollenhaupt
Copy link
Contributor

When a test fails due to an exception it would helpful to have a "Jump to error" or "Fix" button that uses EDITSOURCE() to jump to the line of code that caused the error. Typically this error is not in the UnitTest, but in the tested class or some class that is used and not mocked. The button could be placed below the "Compare" button and only be enabled, when a test failed due to an exception.

The greatest obstacle to the implementation is FoxUnit's reliance on TRY...CATCH. A VFP exception only has method/procedure name and a line number. More detailed information such as the class library are not available and cannot be collected with ASTACKINFO() in the CATCH block as that is already after the fact.

FoxUnit could instead use the following alternative approach:

Do ____FoxUnit____Execute____TRY_CATCH_Handler

Procedure ____FoxUnit____Execute____TRY_CATCH_Handler
	Private all like *____FoxUnit____
	Dimension ____FoxUnit____AStackInfo[1]
	____FoxUnit____Message = ""
	____FoxUnit____Error = 0
	____FoxUnit____Line = 0
	____FoxUnit____OnError = On("Error")
	On Error ____FoxUnit____HandleErrorException (Message(), Error(), Lineno(1), Program(-1))
	Do UnitTest
	On Error &____FoxUnit____OnError
	Clear
	List Memory like ____FoxUnit____AStackInfo
	?
	? ____FoxUnit____Message
	?  "error #", ____FoxUnit____Error, "in line", ____FoxUnit____Line
	* Show source
	Local lnLevel
	lnLevel = Alen(____FoxUnit____AStackInfo,1) - 1
	EditSource(____FoxUnit____AStackInfo[m.lnLevel,4], ____FoxUnit____AStackInfo[m.lnLevel,5])
EndProc

Procedure ____FoxUnit____HandleErrorException
LParameter tcMessage, tnError, tnLine, tnStackLevel
	AStackInfo(____FoxUnit____AStackInfo)
	Dimension ____FoxUnit____AStackInfo[m.tnStackLevel,6]
	____FoxUnit____Message = m.tcMessage
	____FoxUnit____Error = m.tnError
	____FoxUnit____Line = m.tnLine
Return to ____FoxUnit____Execute____TRY_CATCH_Handler

Procedure UnitTest
	Local loObject
	loObject = CreateObject("SomeClass")
	loObject.CauseError ()
	MessageBox("Don't run this")
EndProc

Define CLASS SomeClass as Custom
	Procedure CauseError()
	
		Accept life, deal with it
	EndProc 
EndDefine 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant