From 9923f261a38df4d7bbcd0b2f8ff80ebf7860c78a Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 21 Apr 2016 22:34:39 -0500 Subject: [PATCH] Add runtime library. --- lib/kgrader/runtime.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/kgrader/runtime.rb diff --git a/lib/kgrader/runtime.rb b/lib/kgrader/runtime.rb new file mode 100644 index 0000000..ca99a65 --- /dev/null +++ b/lib/kgrader/runtime.rb @@ -0,0 +1,31 @@ +require 'timeout' + +module KGrader + module Runtime + MAX_COLS = 79 + + def testcase(options) + puts " running test: #{$0} ".center MAX_COLS, '=' + begin + Timeout::timeout options[:alarm] { yield } + rescue Timeout::Error + comment "timeout" + grade 0 + end + puts " done ".center MAX_COLS, '-' + end + + def grade(score) + IO.new(3).write score + exit + end + + def comment(text) + IO.new(4).write text + "\n" + end + + def shake + ARGV[0] + end + end +end