Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 31d3757e58
Fetching contributors…

Cannot retrieve contributors at this time

file 80 lines (71 sloc) 1.866 kb
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
require 'rubygems'
require 'open4'
require 'quick_attr'
require 'std_capture'
#require 'sandbox'

#what happens if you are running a sandbox, but you give it something with a syntax error?

class MonkeyBox
extend QuickAttr
quick_attr :code,:output,:returned,:error

def wrap monkeys
%{
require 'std_capture'
require 'yaml'
out = nil
err = nil
ret = nil
out = StdCapture.capture {
begin
ret = eval {#{code}}
rescue Exception => e
err = exception
end
}
puts {:output => out,
:returned => ret,
:error => {:class => err.class,
:message => err.message,
:backtrace => err.backtrace}
}
}
end
def upwrap (output)
result = YAML::load(output)
end

def run

Open4::popen4("ruby #{__FILE__}") do |pid, stdin, stdout, stderr|

#puts code
stdin.puts code
       stdin.close
       yaml = stdout.read.strip
       puts "YAML: <#{yaml}>"
       report = YAML::load(yaml) || {} #need to catch puts, because the test prints a message if the test fails.
  output report[:output]
  returned report[:returned]
  error report[:error]
puts "==================================="
puts error
puts "==================================="
  err = stderr.read
raise(err) if (err != "" )

#you have to check if there was an error your self.

end
self
end
end
if __FILE__ == $0 then
returned = nil

error = nil
output = StdCapture.capture {
code = $stdin.read
begin
returned = eval(code)
rescue Exception => e
error = e
end
}
r = {:returned => returned,:output => output}
r[:error] = {:class => error.class.name, :message => error.message, :backtrace => error.backtrace } if error
puts r.to_yaml
puts "end".to_yaml #there is a problem with returning null, stdout seems to drop the last new line, so need something acceptable after.
end
Something went wrong with that request. Please try again.