June 12, 2006

BDD Meta–programming

I'm working on a Boo macro library for Rhino Mocks . I'm "dog-fooding" my Specter behaviour driven development framework in the process.
I have to be able to specify how a macro should expand into real code. The spec code is now looking like this:
specify "x as int arg is sent as 0":
check(
ast { disallow foo.Bar(x as int) },
ast { foo.Bar(0); Rhino.Mocks.LastCall.Repeat.Never() }
)

I'm loving how flexible the Boo language is. It's hard to believe that the code is still Boo!

"check" is a function that expands the first argument using the macro being spec'd and makes sure it matches the second argument. (check is actual a partial application of a general check function that takes the macro first)

check = { input as MacroStatement, expected as Node | CheckMacro(macro, input, expected) }
def CheckMacro(macro as AbstractAstMacro, input as MacroStatement, expected as Node):
m = Method()
m.Body.Add(input)
NUnit.Framework.Assert.AreEqual(
expected.ToCodeString().Trim(),
macro.Expand(input).ToCodeString().Trim()
)

- No comments Not publicly viewable


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help http://www.webmd.com/eye–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry

Tags

June 2006

Mo Tu We Th Fr Sa Su
May |  Today  | Jul
         1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30      

Galleries

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXX