I would love to get a functionality that dynamically removes from my code all the self halt that are encountered during test execution. This way I will not need to run the test, walk the stack, edit the code and retart the process. It would be really cool |
Hi Stef,
see an idea below.. Stephane Ducasse wrote:
One approach I have used is to have a global called "DebugMode" which is s boolean. The, usie two types of debugging statements, like: DebugMode ifTrue: [self halt]. and DebugMode: ifTrue: [Transcrip show: somethingUseful ] Then you can just turn DebugMode on or off. This could be made simpler if the self halt of the system at object level checked such a flag and if the Transcript had a subclass which wouldn't log if DebugMode was false. KR Graham graham.vcf (484 bytes) Download Attachment
Graham McLeod
graham@inspired.org www.inspired.org |
In reply to this post by Stephane Ducasse-3
Here is an example of using the ast to remove -all- halts from the code if one or more is encountered during execution.
------------------------------------------------------------ | haltTypes haltingMethods testCode | haltTypes := #( halt halt: haltIf: haltIfNil haltOnCount: haltOnce). haltingMethods := IdentitySet new. "example code" Object compile: 'aMethod | a | self halt. a := 42. self haltIf: a = 42; haltOnCount: 2; yourself. self haltOnce; halt: ''Halting!''. self yourself;
haltIfNil; yourself. [ 1 halt ] value. ^ a'. testCode := (Object >> #aMethod) ast formattedCode. [ "do stuff here"
Object new perform: #aMethod
] on: Halt do: [ :ex |
haltingMethods add: ex signalerContext method.
"ex debug" "<- show debugger on a halt" ex resume. ]. haltingMethods do: [ :method | | ast cascades |
ast := method ast copy. cascades := IdentitySet new.
ast allChildren
select: [ :child | child isMessage and: [ haltTypes includes: child selector ] ]
thenDo: [ :child | | parent | parent := child parent. parent isCascade
ifTrue: [
parent messages remove: child.
cascades add: parent
] ifFalse: [ parent removeNode: child ]. ].
cascades
select: [ :cascadeNode | cascadeNode messages isEmpty]
thenDo: [ :cascadeNode | cascadeNode parent removeNode: cascadeNode ].
method origin
compile: ast formattedCode classified: method protocol.
]. ( DiffMorph
from: testCode
to: (Object >>#aMethod) sourceCode
contextClass: Object ) openInWindow
------------------------------------------------------------ Best regards, Henrik Fra: Pharo-dev [mailto:[hidden email]]
På vegne av Stephane Ducasse I would love to get a functionality that dynamically removes from my code all the self halt that are encountered during test execution. This way I will not need to run the test, walk the stack, edit the code and retart the process. It would be really cool |
In reply to this post by Stephane Ducasse-3
On Thu, Jan 19, 2017 at 06:46:22PM +0100, Stephane Ducasse wrote:
> I would love to get a functionality that dynamically removes from my code > all the self halt that are encountered during test execution. > This way I will not need to run the test, walk the stack, edit the code and > retart the process. > > It would be really cool You mean to _permanently_ remove them after the test passed, or just temporarily disable them during the execution? The latter can be done with MetaLinks, e.g.: Something>>add: aNumber to: anotherNumber self halt. ^ anotherNumber + aNumber SomethingTest>>testAddTo self assert: (Something new add: 4 to: 10) equals: 14 SomethingTest>>setUp | halts | super setUp. halts := (Something >> #add:to:) ast sendNodes select: [ :each | each selector = #halt ]. link := MetaLink new control: #instead. halts do: [ :each | each link: link ]. SomethingTest>>tearDown super tearDown. link uninstall Now if I call the method by hand it will halt, but the test will skip the halts. Peter |
Free forum by Nabble | Edit this page |