A code autograder for student homework submissions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
681 B

  1. require 'fileutils'
  2. require 'timeout'
  3. module KGrader
  4. module Runtime
  5. MAX_COLS = 79
  6. def testcase(options)
  7. puts " running test: #{File.basename $0} ".center MAX_COLS, '='
  8. begin
  9. Timeout::timeout options[:alarm] { yield }
  10. rescue Timeout::Error
  11. comment "timeout"
  12. grade 0
  13. end
  14. puts "no grade received?"
  15. comment "autograde error (no grade reported); please contact staff"
  16. grade 0
  17. end
  18. def grade(score)
  19. IO.new(3).write score
  20. puts " done ".center MAX_COLS, '-'
  21. exit
  22. end
  23. def comment(text)
  24. IO.new(4).write text + "\n"
  25. end
  26. def shake
  27. ARGV[0]
  28. end
  29. end
  30. end