BAM Weblog

Roy - Tests (finally)

Brian McKenna — 2011-07-17

Anybody following along could probably tell that I’m not practising TDD with Roy. Only this week I started writing some tests. As expected, I’m finding lots of bugs!

I’m going to work on cleaning it up but the test runner currently stands at 24 lines of Roy code:

let fs = require 'fs'
let path = require 'path'
let child_process = require 'child_process'

let dir = "test"
let files = fs.readdirSync dir

let tests = files.filter (fn x =
  (x.lastIndexOf '.roy') == (x.length - 4)
)

tests.forEach (fn t =
  let name = path.join dir t
  let outFile = (path.join dir (path.basename t '.roy')) ++ '.out'
  child_process.exec './roy -r ' ++ name (fn error stdout stderr =
    if error then
      console.log "Error:" error.message
    else
      let expected = fs.readFileSync outFile 'utf8'
      let actual = stdout.toString ()
      console.assert actual == expected "Output of " ++ t ++ ": " ++ (JSON.stringify actual) ++ " does not match " ++ (JSON.stringify expected)
      console.log "Pass:" name
  )
)

Not too ugly. It seems like some standard library functions could make it nicer.

Please enable JavaScript to view the comments powered by Disqus.