🕷 zenspider.com

by ryan davis

Looking for the Ruby Quickref?

Heckle: Another Rubyconf Hack

Published 2006-10-22 @ 10:22

Tagged rubysadism, parsetree, rails, ruby, Seattle.rb, heckle

Jester is a java test tool that finds code that is not covered by tests. It does this via bytecode mutation to modify code paths of the class under test. First it runs your tests and they should all pass (ass usual). Then it will modify conditionals for branching, change literals, and generally wreck havok, making one change at a time. By rerunning the tests per change, if they don’t fail, then you’ve missed a test case. All in all this is pretty damn cool.

It turns out that getting a simple prototype up and running with ‘if’ node flipping takes about 100 lines of code. The meat of it is:

  def process_defn(exp)
    self.method = exp.shift
    result = [:defn, method]
    result << process(exp.shift) until exp.empty?

    heckle(result) if should_heckle?

    return result

  def process_if(exp)
    cond = process(exp.shift)
    t = process(exp.shift)
    f = process(exp.shift)

    if should_heckle? then
      [:if, cond, f, t]
      [:if, cond, t, f]

I’ve named it heckle and released it on rubyforge and Kevin Clark went insane last night and poured through it, ruby2ruby, and ParseTree to dig deeper. I haven’t seen him this morning yet so I don’t know if he’s succeeded extending it yet. We’ll see. There will be a more official release soon.