Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

152 lines (135 sloc) 2.776 kb
require "test/unit"
require "fileutils"
require "tempfile"
require "timeout"
require "thread"
Dir.chdir(File.dirname(__FILE__))
class Rp5Test < Test::Unit::TestCase
OUTPUT_FILE = File.join(Dir.pwd, "output.txt")
def test_normal
queue = write_and_run_sketch <<EOF
def setup
size(300, 300)
frame_rate(10)
end
def draw
println "ok"
if frame_count == 10
exit
end
end
EOF
10.times do
assert_equal "ok", queue.pop
end
end
def test_opengl
queue = write_and_run_sketch <<EOF
load_library "opengl"
def setup
size(300, 300, OPENGL)
end
def draw
println "ok"
exit
end
EOF
assert_equal "ok", queue.pop
end
def test_setup_exception
queue = write_and_run_sketch <<EOF
def setup
size(300, 300)
unknown_method()
end
def draw
end
EOF
assert queue.pop.index("undefined method `unknown_method'")
end
def test_draw_exception
queue = write_and_run_sketch <<EOF
def setup
size(300, 300)
end
def draw
unknown_method()
end
EOF
assert queue.pop.index("undefined method `unknown_method'")
end
def test_inner_classes_proxy
queue = write_and_run_sketch <<EOF
def setup
size(300, 300)
begin
MyInnerClass.new
rescue
println("inner class proxy doesn't work")
end
exit
end
class MyInnerClass
def initialize
println(width)
end
end
EOF
assert_equal "300", queue.pop
end
def test_rp5_watch
tf = Tempfile.new("rp5_watch_tester")
sketch_source = <<EOF
def setup
size(200, 200)
end
def draw
println "ok"
no_loop
end
EOF
tf.write(sketch_source)
tf.close
lines = []
watcher_thread = Thread.new do
open("|../bin/rp5 watch #{tf.path}", "r") do |io|
while l = io.gets
lines << l
end
end
end
sleep 10
assert_equal "ok\n", lines.shift
File.open(tf.path, "w") { |f| f.puts(sketch_source.sub(/no_loop/, "exit")) }
sleep 5
assert_equal "reloading sketch...\n", lines.shift
assert_equal "ok\n", lines.shift
# terminated normally
assert_equal false, watcher_thread.status
assert lines.empty?
end
def write_and_run_sketch(sketch_content)
queue = Queue.new
Thread.new do
Tempfile.open("rp5_tester") do |tf|
tf.write(sketch_content)
tf.close
#FileUtils.cp(tf.path, "/tmp/sketch.rb", :verbose => true)
output = nil
begin
Timeout.timeout(15) do
open("|../bin/rp5 run #{tf.path}", "r") do |io|
while l = io.gets
queue.push(l.chop)
end
end
end
assert $?.exited?
rescue Timeout::Error
assert false, "rp5 timed out"
end
end
end
return queue
end
end
Jump to Line
Something went wrong with that request. Please try again.