我想將故障注入Pharo方法。喜歡的東西如何以編程方式將故障注入Pharo方法?
- 變化
ifTrue:ifFalse:
到ifFalse:ifTrue:
, - 變化
+
到-
, - 變化
and:
到or:
,
等
我怎麼能這樣做? Pharo 3有新的/其他的可能性嗎?
我想將故障注入Pharo方法。喜歡的東西如何以編程方式將故障注入Pharo方法?
ifTrue:ifFalse:
到ifFalse:ifTrue:
,+
到-
,and:
到or:
,等
我怎麼能這樣做? Pharo 3有新的/其他的可能性嗎?
菲羅4將有一個解決方案,但現在你必須做手工......
對於像#+,#正常的消息 - 等等......你可以修改文字陣列但它不能用於#ifTrue:ifFalse:和#ifFalse:ifTrue之類的消息:因爲編譯器將代碼內聯以獲得更好的性能。一種解決方案是複製方法的AST,修改它,編譯它並將其安裝到類中。這樣的東西應該工作:
FaultInjector>>#replace: aSelector with: anotherSelector in: aCompiledMethod
| newAST |
"Save the original method to restore it later"
replacedMethods add: aCompiledMethod.
"Copy the AST"
newAST := aCompiledMethod ast copy.
"Rewriting the AST"
newAST nodesDo: [ :each |
(each isMessage and: [ each selector = aSelector ])
ifTrue: [ each selector: anotherSelector ] ].
"Compile the AST and install the new method"
aCompiledMethod methodClass
addSelectorSilently: aCompiledMethod selector
withMethod: (newAST generate: aCompiledMethod trailer).
那麼你應該有恢復您更換方法的方法:
FaultInjector>>#restore
replacedMethods do: [ :each |
each methodClass
addSelectorSilently: each selector
withMethod: each ].
replacedMethods removeAll
從前有對佳樂這樣的框架時,搜索MutationTesting
http://www.slideshare.net/esug/mutation-testing
http://www.squeaksource.com/MutationTesting.html
我懷疑它可以像Pharo 2.0/3.0一樣工作,我不知道是否已經有Pharo端口,但它可能值得嘗試,並且在任何情況下它都應該是一個不錯的起點。
而且從哈索普列特納研究所
http://lists.squeakfoundation.org/pipermail/squeak-dev/2012-October/166011.html
作品在菲羅3搜索MutationEngine,是非常酷!謝謝! (在Pharo 2中,RBMethodNode還不理解#generate:但這只是一個提示,我對Pharo 3很好) – MartinW