require "./web/examples.rb"
require "./lazylib.rb"
require "./run.rb"
require "stringio"

def output(str)
  $output << str
end

pass = true

tests = ExamplesAndTests
tests.each{|name, prog, input, expected|
  $output = ""
  input_stream = Array === input ? input : StringIO.new(input)
  begin
    run_and_do_io(prog,input_stream,false,false)
  rescue Exception
    errored = $!
    $output << $!.message.gsub(IogiiError.new("").message, "ERROR: ").lines.map(&:rstrip).join("\n")
  end

  if $output != expected
    STDERR.puts "FAIL: #{name}"
    STDERR.puts prog
    STDERR.puts "expected:"
    STDERR.print expected
    STDERR.puts "EOF"
    STDERR.puts "found:"
    STDERR.print $output
    STDERR.puts "EOF"
    pass = false
  end
}

puts "PASS #{tests.size} examples" if pass
