我想将故障注入pharo方法。像
- 将
ifTrue:ifFalse:
更改为ifFalse:ifTrue:
, - 将
+
更改为-
, - 将
and:
更改为or:
,
等。
我该怎么做?Pharo 3中是否有新的/其他可能性?
pharo 4将有一个解决方案,但是目前您必须手工做...
对于# ,# - 等的普通消息...您可以修改该方法的文字数组,但是它对#iftrue:iffalse:iffalse:and #iffalse:iftrue: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
曾经有这样的尖叫框架,搜索突变
http://www.slideshare.net/esug/muarn-testing
http://www.squeaksource.com/munttesting.html
我怀疑它可以像Pharo 2.0/3.0中的工作一样工作,而且我不知道是否已经有一个Pharo端口,但值得一试,在任何情况下,这应该是一个不错的起点。p>也从Hasso Plattner Institute搜索Mutation Engene
http://lists.squeakfoundation.org/pipermail/squeak-dev/2012-october/166011.html