Class: AtCoderFriends::TestRunner
- Inherits:
-
Object
- Object
- AtCoderFriends::TestRunner
- Includes:
- PathUtil
- Defined in:
- lib/at_coder_friends/test_runner.rb
Overview
run tests for the specified program.
Direct Known Subclasses
Constant Summary
Constants included from PathUtil
PathUtil::CASES_DIR, PathUtil::SMP_DIR
Instance Method Summary collapse
-
#edit_cmd ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(path) ⇒ TestRunner
constructor
A new instance of TestRunner.
-
#run_test(id, infile, outfile, expfile) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#which_os ⇒ Object
rubocop:enable Metrics/MethodLength.
Methods included from PathUtil
cases_dir, contest_name, smp_dir, split_prg_path
Constructor Details
#initialize(path) ⇒ TestRunner
Returns a new instance of TestRunner.
10 11 12 |
# File 'lib/at_coder_friends/test_runner.rb', line 10 def initialize(path) @path, @dir, @prg, @base, @ext, @q = split_prg_path(path) end |
Instance Method Details
#edit_cmd ⇒ Object
rubocop:disable Metrics/MethodLength
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/at_coder_friends/test_runner.rb', line 41 def edit_cmd case @ext when 'java' "java -cp #{@dir} Main" when 'rb' "ruby #{@dir}/#{@base}.rb" when 'cs' case which_os when :windows "#{@dir}/#{@base}.exe" else "mono #{@dir}/#{@base}.exe" end else # c, cxx case which_os when :windows "#{@dir}/#{@base}.exe" else "#{@dir}/#{@base}" end end end |
#run_test(id, infile, outfile, expfile) ⇒ Object
rubocop:disable Metrics/MethodLength
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/at_coder_friends/test_runner.rb', line 15 def run_test(id, infile, outfile, expfile) return false unless File.exist?(infile) && File.exist?(expfile) puts "==== #{id} ====" ec = system("#{edit_cmd} < #{infile} > #{outfile}") input, result, expected = [infile, outfile, expfile].map { |file| File.read(file) } puts '-- input --' print input puts '-- expected --' print expected puts '-- result --' print result if !ec puts '!!!!! RE !!!!!' elsif result != expected puts '!!!!! WA !!!!!' else puts '<< OK >>' end true end |
#which_os ⇒ Object
rubocop:enable Metrics/MethodLength
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/at_coder_friends/test_runner.rb', line 65 def which_os @os ||= begin case RbConfig::CONFIG['host_os'] when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ :windows when /darwin|mac os/ :macosx when /linux/ :linux when /solaris|bsd/ :unix else :unknown end end end |