 argv = (require 'minimist') process.argv.slice 2
+EOL = (require 'os').EOL
 fs = require 'fs'
 path = require 'path'
 spawn = (require 'child_process').spawn

      diag "Executing tests..."
      go (createContext host), done

  cloud.stdout.on 'data', (data) ->
    diag data
    if match = data.toString().match /listen.+http.+http:\/\/(.+)\//i
      host = match[1]
      diag "H2O cloud started at #{host}"
      setTimeout (runTests host), 1000

  cloud.stderr.on 'data', (data) -> diag data
  cloud.on 'close', (code, signal) -> diag "H2O exited with code #{code}, signal #{signal}."

# Pass -jar /path/to/h2o.jar to override the default jar
JAR_PATH = if argv.jar then path.resolve argv.jar else path.resolve process.cwd(), '..', path.join 'h2o-app', 'build', 'libs', 'h2o-app.jar'

throw "H2O jar '#{JAR_PATH}' not found!" unless fs.existsSync JAR_PATH

DATA_PATH = if argv.data then path.resolve argv.data else path.resolve process.cwd(), '..', 'smalldata'

throw "Data path '#{DATA_PATH}' not found!" unless fs.existsSync DATA_PATH

GOLD_PATH = if argv.gold then path.resolve argv.gold else path.resolve process.cwd(), path.join 'src', 'main', 'steam', 'tests', 'gold'

throw "Gold file path '#{GOLD_PATH}' not found!" unless fs.existsSync GOLD_PATH

readGoldFile = (name) -> fs.readFileSync (path.join GOLD_PATH, name), encoding: 'utf8'
readGoldJson = (name) -> JSON.parse readGoldFile name

if argv.s # spool
  spool = (data) ->
    fs.appendFileSync 'spool.log', data + EOL + EOL
else
  spool = ->

# Node.js equivalent of Steam.Xhr
Xhr = (_, host) ->
