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:pharo-dev-boun...@lists.pharo.org] På vegne av Stephane Ducasse Sendt: 19 January 2017 18:46 Til: Pharo Development List <pharo-dev@lists.pharo.org> Emne: [Pharo-dev] In the need of Pharo magic 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