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.

42 lines
757 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. comment "autograde error (no grade reported); please contact staff"
  15. grade 0
  16. end
  17. def grade(score)
  18. IO.new(3).write score
  19. puts " done ".center MAX_COLS, '-'
  20. exit
  21. end
  22. def comment(text)
  23. puts "comment: #{text}"
  24. IO.new(4).write text + "\n"
  25. end
  26. def shake
  27. ARGV[0]
  28. end
  29. def getpath(filename)
  30. File.join File.dirname($0), filename
  31. end
  32. end
  33. end