Class: AtCoderFriends::TestRunner::Base
- Inherits:
-
Object
- Object
- AtCoderFriends::TestRunner::Base
show all
- Includes:
- PathUtil
- Defined in:
- lib/at_coder_friends/test_runner/base.rb
Overview
run tests for the specified program.
Constant Summary
Constants included
from PathUtil
PathUtil::CASES_DIR, PathUtil::SMP_DIR, PathUtil::TMP_DIR
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#call_remote_test(infile) ⇒ Object
-
#config ⇒ Object
-
#detail_str(input, result, expected) ⇒ Object
-
#initialize(ctx) ⇒ Base
constructor
-
#local_test(infile, outfile) ⇒ Object
-
#remote_test(infile, outfile) ⇒ Object
-
#result_str(is_success, result, expected) ⇒ Object
-
#run_test(id, infile, outfile, expfile) ⇒ Object
-
#show_result(is_success, input, result, expected) ⇒ Object
-
#test_cmd ⇒ Object
-
#test_loc ⇒ Object
-
#test_mtd ⇒ Object
-
#which_os ⇒ Object
Methods included from PathUtil
cases_dir, contest_name, makedirs_unless, smp_dir, split_prg_path, tmp_dir
Constructor Details
#initialize(ctx) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 14
def initialize(ctx)
@ctx = ctx
@path, @dir, @prg, @base, @ext, @q = split_prg_path(ctx.path)
end
|
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def base
@base
end
|
#ctx ⇒ Object
Returns the value of attribute ctx.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def ctx
@ctx
end
|
#dir ⇒ Object
Returns the value of attribute dir.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def dir
@dir
end
|
#ext ⇒ Object
Returns the value of attribute ext.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def ext
@ext
end
|
#path ⇒ Object
Returns the value of attribute path.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def path
@path
end
|
#prg ⇒ Object
Returns the value of attribute prg.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def prg
@prg
end
|
#q ⇒ Object
Returns the value of attribute q.
12
13
14
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 12
def q
@q
end
|
Instance Method Details
#call_remote_test(infile) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 67
def call_remote_test(infile)
res = ctx.scraping_agent.code_test(infile)
(res && res['Result']) || (return [false, 'Remote test failed.'])
puts "Exit code: #{res.dig('Result', 'ExitCode')}"
puts "Time: #{res.dig('Result', 'TimeConsumption')}ms"
puts "Memory: #{res.dig('Result', 'MemoryConsumption')}KB"
res.dig('Result', 'ExitCode').zero? || (return [false, res['Stderr']])
[true, res['Stdout']]
end
|
#config ⇒ Object
19
20
21
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 19
def config
ctx.config
end
|
#detail_str(input, result, expected) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 84
def detail_str(input, result, expected)
ret = ''
ret += "-- input --\n"
ret += input
ret += "-- expected --\n"
ret += expected
ret += "-- result --\n"
ret += result
ret
end
|
#local_test(infile, outfile) ⇒ Object
57
58
59
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 57
def local_test(infile, outfile)
system("#{test_cmd} < #{infile} > #{outfile}")
end
|
#remote_test(infile, outfile) ⇒ Object
61
62
63
64
65
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 61
def remote_test(infile, outfile)
is_success, result = call_remote_test(infile)
File.write(outfile, result)
is_success
end
|
#result_str(is_success, result, expected) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 95
def result_str(is_success, result, expected)
if !is_success
'!!!!! RE !!!!!'.red
elsif result != expected
'!!!!! WA !!!!!'.red
else
'<< OK >>'.green
end
end
|
#run_test(id, infile, outfile, expfile) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 41
def run_test(id, infile, outfile, expfile)
return false unless File.exist?(infile) && File.exist?(expfile)
puts "==== #{id} ===="
makedirs_unless(File.dirname(outfile))
is_success = send(test_mtd, infile, outfile)
show_result(
is_success,
File.read(infile),
File.read(outfile),
File.read(expfile)
)
true
end
|
#show_result(is_success, input, result, expected) ⇒ Object
79
80
81
82
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 79
def show_result(is_success, input, result, expected)
print detail_str(input, result, expected)
puts result_str(is_success, result, expected)
end
|
#test_cmd ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 23
def test_cmd
@test_cmd ||= begin
cmds = config.dig('ext_settings', ext, 'test_cmd')
cmd = cmds && (cmds[which_os.to_s] || cmds['default'])
return nil unless cmd
cmd.gsub('{dir}', dir).gsub('{base}', base)
end
end
|
#test_loc ⇒ Object
33
34
35
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 33
def test_loc
test_cmd ? 'local' : 'remote'
end
|
#test_mtd ⇒ Object
37
38
39
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 37
def test_mtd
test_cmd ? :local_test : :remote_test
end
|
#which_os ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/at_coder_friends/test_runner/base.rb', line 105
def which_os
@which_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
|