most 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Copying.txt +679 -0
- data/History.txt +15 -0
- data/Manifest.txt +95 -0
- data/PostInstall.txt +6 -0
- data/Rakefile +44 -0
- data/Readme.rdoc +146 -0
- data/bin/most +31 -0
- data/lib/most.rb +52 -0
- data/lib/most/context.rb +244 -0
- data/lib/most/core.rb +171 -0
- data/lib/most/di/container.rb +148 -0
- data/lib/most/di/proxy.rb +55 -0
- data/lib/most/di/service.rb +63 -0
- data/lib/most/di/service_factory.rb +40 -0
- data/lib/most/environment.rb +67 -0
- data/lib/most/executor.rb +80 -0
- data/lib/most/helpers/array.rb +31 -0
- data/lib/most/helpers/hash.rb +25 -0
- data/lib/most/helpers/kernel.rb +35 -0
- data/lib/most/helpers/memory_out.rb +93 -0
- data/lib/most/helpers/numeric.rb +59 -0
- data/lib/most/helpers/object.rb +65 -0
- data/lib/most/helpers/symbol.rb +31 -0
- data/lib/most/interfaces/meta_programmable.rb +59 -0
- data/lib/most/starter.rb +126 -0
- data/lib/most/structures/box.rb +199 -0
- data/lib/most/structures/submission.rb +117 -0
- data/lib/most/structures/test_case.rb +173 -0
- data/lib/most/structures/test_runner.rb +103 -0
- data/lib/most/structures/types/options.rb +67 -0
- data/lib/most/structures/types/path.rb +39 -0
- data/lib/most/structures/types/report.rb +84 -0
- data/lib/most/submissions/cpp_memory_out_sample.rb +34 -0
- data/lib/most/submissions/cpp_sample.rb +36 -0
- data/lib/most/submissions/cpp_timeout_sample.rb +34 -0
- data/lib/most/submissions/cs_sample.rb +36 -0
- data/lib/most/submissions/erlang_sample.rb +36 -0
- data/lib/most/submissions/haskell_sample.rb +36 -0
- data/lib/most/submissions/java_sample.rb +36 -0
- data/lib/most/submissions/lisp_sample.rb +32 -0
- data/lib/most/submissions/lua_sample.rb +36 -0
- data/lib/most/submissions/ocaml_sample.rb +36 -0
- data/lib/most/submissions/pascal_sample.rb +36 -0
- data/lib/most/submissions/perl_sample.rb +32 -0
- data/lib/most/submissions/php_sample.rb +32 -0
- data/lib/most/submissions/python_sample.rb +32 -0
- data/lib/most/submissions/ruby_sample.rb +32 -0
- data/lib/most/submissions/vb_sample.rb +36 -0
- data/lib/most/tasks/general/win/cs.rb +60 -0
- data/lib/most/tasks/general/win/erlang.rb +86 -0
- data/lib/most/tasks/general/win/gcc.rb +39 -0
- data/lib/most/tasks/general/win/haskell.rb +75 -0
- data/lib/most/tasks/general/win/java.rb +72 -0
- data/lib/most/tasks/general/win/lisp.rb +59 -0
- data/lib/most/tasks/general/win/lua.rb +75 -0
- data/lib/most/tasks/general/win/ocaml.rb +77 -0
- data/lib/most/tasks/general/win/pascal.rb +73 -0
- data/lib/most/tasks/general/win/perl.rb +61 -0
- data/lib/most/tasks/general/win/php.rb +59 -0
- data/lib/most/tasks/general/win/python.rb +59 -0
- data/lib/most/tasks/general/win/ruby.rb +61 -0
- data/lib/most/tasks/general/win/vb.rb +60 -0
- data/lib/most/tasks/general/win/vc.rb +79 -0
- data/lib/most/tasks/general/win/vs.rb +52 -0
- data/samples/problem/solutions/cpp/main.cpp +9 -0
- data/samples/problem/solutions/cpp/tests.yml +19 -0
- data/samples/problem/solutions/cs/main.cs +17 -0
- data/samples/problem/solutions/cs/tests.yml +19 -0
- data/samples/problem/solutions/erlang/main.erl +2 -0
- data/samples/problem/solutions/erlang/tests.yml +19 -0
- data/samples/problem/solutions/haskell/main.hs +5 -0
- data/samples/problem/solutions/haskell/tests.yml +19 -0
- data/samples/problem/solutions/java/Main.java +14 -0
- data/samples/problem/solutions/java/tests.yml +19 -0
- data/samples/problem/solutions/lisp/main.lisp +1 -0
- data/samples/problem/solutions/lisp/tests.yml +19 -0
- data/samples/problem/solutions/lua/main.lua +4 -0
- data/samples/problem/solutions/lua/tests.yml +19 -0
- data/samples/problem/solutions/ocaml/main.ml +3 -0
- data/samples/problem/solutions/ocaml/tests.yml +19 -0
- data/samples/problem/solutions/pascal/main.pas +5 -0
- data/samples/problem/solutions/pascal/tests.yml +19 -0
- data/samples/problem/solutions/perl/main.pl +2 -0
- data/samples/problem/solutions/perl/tests.yml +19 -0
- data/samples/problem/solutions/php/main.php +1 -0
- data/samples/problem/solutions/php/tests.yml +19 -0
- data/samples/problem/solutions/python/main.py +1 -0
- data/samples/problem/solutions/python/tests.yml +19 -0
- data/samples/problem/solutions/ruby/main.rb +1 -0
- data/samples/problem/solutions/ruby/tests.yml +19 -0
- data/samples/problem/solutions/vb/main.vb +14 -0
- data/samples/problem/solutions/vb/tests.yml +19 -0
- data/samples/time_memory/solutions/cpp/main.cpp +21 -0
- data/samples/time_memory/solutions/cpp/tests.yml +19 -0
- data/tasks/samples.rb +31 -0
- metadata +242 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
# Most - Modular Open Software Tester.
|
2
|
+
# Copyright (C) 2009 Dmitrii Toksaitov
|
3
|
+
#
|
4
|
+
# This file is part of Most.
|
5
|
+
#
|
6
|
+
# Most is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Most is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Most. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'yaml'
|
20
|
+
require 'stringio'
|
21
|
+
|
22
|
+
require 'most/structures/types/path'
|
23
|
+
require 'most/structures/types/options'
|
24
|
+
require 'most/structures/types/report'
|
25
|
+
|
26
|
+
require 'most/structures/test_runner'
|
27
|
+
|
28
|
+
module Most
|
29
|
+
|
30
|
+
module TestCaseHelpers
|
31
|
+
def create_test_case(*args, &block)
|
32
|
+
TestCase.new(*args, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestCase
|
37
|
+
include MetaProgrammable
|
38
|
+
|
39
|
+
include PathHelpers
|
40
|
+
include OptionsHelpers
|
41
|
+
include RunnerHelpers
|
42
|
+
|
43
|
+
def initialize(name = 'Anonymous Test Case',
|
44
|
+
input = '',
|
45
|
+
output = '',
|
46
|
+
output_destination = nil,
|
47
|
+
output_preprocessor = lambda { |data| data.to_s().strip() },
|
48
|
+
runner = TestRunner.new(),
|
49
|
+
&block)
|
50
|
+
|
51
|
+
@name = name
|
52
|
+
@input = input
|
53
|
+
|
54
|
+
@output = output
|
55
|
+
@output_destination = output_destination
|
56
|
+
@output_preprocessor = output_preprocessor
|
57
|
+
|
58
|
+
@runner = runner
|
59
|
+
|
60
|
+
instance_eval(&block) if block_given?
|
61
|
+
end
|
62
|
+
|
63
|
+
def run(options, entities)
|
64
|
+
result = Report.new("Test Case: #{@name}")
|
65
|
+
|
66
|
+
if options[:tests/:report/:specs]
|
67
|
+
result.specs = {:name => @name,
|
68
|
+
:correct_output => @output,
|
69
|
+
:output_destination => @output_destination,
|
70
|
+
:output_preprocessor => @output_preprocessor,
|
71
|
+
:runner => @runner}
|
72
|
+
end
|
73
|
+
|
74
|
+
result << process(options, entities)
|
75
|
+
result
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def process(options, entities)
|
80
|
+
result = @runner.run(options, entities, @input)
|
81
|
+
|
82
|
+
if result.last[:success]
|
83
|
+
process_result!(result.last, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
def process_result!(result, options)
|
90
|
+
test_output = nil
|
91
|
+
|
92
|
+
if @output_destination.is_a?(Path)
|
93
|
+
test_output = File.read(@output_destination.expand_path()) rescue nil
|
94
|
+
else
|
95
|
+
test_output = result[:process_stdout]
|
96
|
+
end
|
97
|
+
|
98
|
+
unless @output_preprocessor.nil?
|
99
|
+
test_output = @output_preprocessor.call(test_output)
|
100
|
+
end
|
101
|
+
|
102
|
+
result[:processed_output] = test_output
|
103
|
+
|
104
|
+
is_correct = output_equal?(test_output, @output)
|
105
|
+
result[:correct] = is_correct
|
106
|
+
|
107
|
+
if not is_correct and options[:tests/:report/:differences]
|
108
|
+
diffs = differences(test_output, @output)
|
109
|
+
result[:differences] = diffs unless diffs.nil?
|
110
|
+
end
|
111
|
+
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def differences(first_sequence, second_sequence)
|
116
|
+
result = nil
|
117
|
+
|
118
|
+
valid? first_sequence, second_sequence do
|
119
|
+
begin
|
120
|
+
result = SERVICES[:diff].diff(first_sequence, second_sequence)
|
121
|
+
rescue Exception => e
|
122
|
+
SERVICES[:environment].log_error(e, "Failed to process with the 'diff' service")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
result
|
127
|
+
end
|
128
|
+
|
129
|
+
def output_equal?(output, correct_output)
|
130
|
+
result = nil
|
131
|
+
|
132
|
+
valid? output, correct_output do
|
133
|
+
first_stream = get_stream(output)
|
134
|
+
second_stream = get_stream(correct_output)
|
135
|
+
|
136
|
+
result = !first_stream.nil? and !second_stream.nil?
|
137
|
+
|
138
|
+
while result and valid? first_stream, second_stream
|
139
|
+
first_char = first_stream.getc()
|
140
|
+
second_char = second_stream.getc()
|
141
|
+
|
142
|
+
result = first_char == second_char
|
143
|
+
|
144
|
+
break if first_char.nil? or second_char.nil?
|
145
|
+
end
|
146
|
+
|
147
|
+
first_stream.try(:close)
|
148
|
+
second_stream.try(:close)
|
149
|
+
end
|
150
|
+
|
151
|
+
result
|
152
|
+
end
|
153
|
+
|
154
|
+
def get_stream(data)
|
155
|
+
result = nil
|
156
|
+
|
157
|
+
case data
|
158
|
+
when ::String
|
159
|
+
result = StringIO.new(data, 'r')
|
160
|
+
when Path
|
161
|
+
result = File.open(data.expand_path(), 'r')
|
162
|
+
else
|
163
|
+
result.try(:close)
|
164
|
+
|
165
|
+
exception = TypeError.new("Invalid type: #{data.class}")
|
166
|
+
SERVICES[:environment].log_error(exception, 'Invalid data or reference type')
|
167
|
+
end
|
168
|
+
|
169
|
+
result
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Most - Modular Open Software Tester.
|
2
|
+
# Copyright (C) 2009 Dmitrii Toksaitov
|
3
|
+
#
|
4
|
+
# This file is part of Most.
|
5
|
+
#
|
6
|
+
# Most is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Most is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Most. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
require 'most/structures/types/path'
|
22
|
+
require 'most/structures/types/options'
|
23
|
+
require 'most/structures/types/report'
|
24
|
+
|
25
|
+
require 'most/structures/box'
|
26
|
+
|
27
|
+
module Most
|
28
|
+
|
29
|
+
module RunnerHelpers
|
30
|
+
def create_test_runner(*args, &block)
|
31
|
+
TestRunner.new(*args, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class TestRunner
|
36
|
+
include MetaProgrammable
|
37
|
+
|
38
|
+
include PathHelpers
|
39
|
+
include OptionsHelpers
|
40
|
+
|
41
|
+
def initialize(name = 'Anonymous Test Runner', steps = [], &block)
|
42
|
+
@name = name
|
43
|
+
@steps = steps
|
44
|
+
|
45
|
+
instance_eval(&block) if block_given?
|
46
|
+
end
|
47
|
+
|
48
|
+
def run(options, entities, input)
|
49
|
+
result = Report.new("Test Runner: #{@name}")
|
50
|
+
|
51
|
+
if options[:tests/:report/:specs]
|
52
|
+
result.specs = {:name => @name,
|
53
|
+
:steps => @steps}
|
54
|
+
end
|
55
|
+
|
56
|
+
result << execute(options, entities, input)
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_step(step, &block)
|
61
|
+
@steps ||= []
|
62
|
+
if step.is_a?(Class) and block_given?
|
63
|
+
@steps << step.new(&block)
|
64
|
+
else
|
65
|
+
@steps << step
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def execute(options, entities, input)
|
71
|
+
result = {:success => true,
|
72
|
+
:steps => [],
|
73
|
+
:process_stdout => nil}
|
74
|
+
|
75
|
+
globals = {};
|
76
|
+
@steps.each do |step|
|
77
|
+
step_box = Box.new do
|
78
|
+
options options
|
79
|
+
entities entities
|
80
|
+
globals globals
|
81
|
+
input input
|
82
|
+
end
|
83
|
+
|
84
|
+
step_result = step_box.run(step)
|
85
|
+
globals = step_box.globals
|
86
|
+
|
87
|
+
result[:steps] << step_box
|
88
|
+
result[:process_stdout] = step_result.last[:process_stdout]
|
89
|
+
|
90
|
+
unless step_result.last[:success]
|
91
|
+
if options[:tests/:steps/:break/:unsuccessful]
|
92
|
+
result[:success] = false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
break unless result[:success]
|
97
|
+
end
|
98
|
+
|
99
|
+
result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Most - Modular Open Software Tester.
|
2
|
+
# Copyright (C) 2009 Dmitrii Toksaitov
|
3
|
+
#
|
4
|
+
# This file is part of Most.
|
5
|
+
#
|
6
|
+
# Most is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Most is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Most. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
module Most
|
22
|
+
|
23
|
+
module OptionsHelpers
|
24
|
+
def create_options(*args, &block)
|
25
|
+
Options.new(*args, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Options < Hash
|
30
|
+
def initialize(hash = nil)
|
31
|
+
super(); replace(hash) unless hash.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](key, *args)
|
35
|
+
if key.is_a?(Array)
|
36
|
+
args.unshift(*key[1..-1])
|
37
|
+
key = key.first
|
38
|
+
end
|
39
|
+
|
40
|
+
result = super(key)
|
41
|
+
|
42
|
+
args.each do |item|
|
43
|
+
break if result.nil?
|
44
|
+
result = result.try(:[], item)
|
45
|
+
end
|
46
|
+
|
47
|
+
result
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_any?(*args)
|
51
|
+
result = nil
|
52
|
+
|
53
|
+
args.each do |item|
|
54
|
+
if item.is_a?(Array)
|
55
|
+
result = self[*item]
|
56
|
+
else
|
57
|
+
result = self[item]
|
58
|
+
end
|
59
|
+
|
60
|
+
break unless result.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Most - Modular Open Software Tester.
|
2
|
+
# Copyright (C) 2009 Dmitrii Toksaitov
|
3
|
+
#
|
4
|
+
# This file is part of Most.
|
5
|
+
#
|
6
|
+
# Most is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Most is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Most. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
module Most
|
22
|
+
|
23
|
+
module PathHelpers
|
24
|
+
def path(path)
|
25
|
+
Path.new(path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Path < String
|
30
|
+
def initialize(path = '')
|
31
|
+
super(path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def expand_path()
|
35
|
+
File.expand_path(self)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Most - Modular Open Software Tester.
|
2
|
+
# Copyright (C) 2009 Dmitrii Toksaitov
|
3
|
+
#
|
4
|
+
# This file is part of Most.
|
5
|
+
#
|
6
|
+
# Most is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Most is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Most. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'yaml'
|
20
|
+
|
21
|
+
module Most
|
22
|
+
|
23
|
+
class Report
|
24
|
+
attr_accessor :name, :specs
|
25
|
+
|
26
|
+
def initialize(name = 'Untitled Report', specs = {})
|
27
|
+
@name = name
|
28
|
+
@specs = specs
|
29
|
+
|
30
|
+
@units = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_entry(entry)
|
34
|
+
@units << entry
|
35
|
+
end
|
36
|
+
alias << add_entry
|
37
|
+
|
38
|
+
def get_entry(index)
|
39
|
+
@units[index]
|
40
|
+
end
|
41
|
+
alias [] get_entry
|
42
|
+
|
43
|
+
def set_entry(index, value)
|
44
|
+
@units[index] = value
|
45
|
+
end
|
46
|
+
alias []= set_entry
|
47
|
+
|
48
|
+
def delete_entry(entry)
|
49
|
+
@units.delete(entry)
|
50
|
+
end
|
51
|
+
alias delete delete_entry
|
52
|
+
|
53
|
+
def delete_entry_at(index)
|
54
|
+
@units.delete_at(index)
|
55
|
+
end
|
56
|
+
alias delete_at delete_entry_at
|
57
|
+
|
58
|
+
def first_entry()
|
59
|
+
@units.first
|
60
|
+
end
|
61
|
+
alias first first_entry
|
62
|
+
|
63
|
+
def first_entry=(entry)
|
64
|
+
@units.first = entry
|
65
|
+
end
|
66
|
+
alias first= first_entry=
|
67
|
+
|
68
|
+
def last_entry()
|
69
|
+
@units.last
|
70
|
+
end
|
71
|
+
alias last last_entry
|
72
|
+
|
73
|
+
def last_entry=(entry)
|
74
|
+
@units.last = entry
|
75
|
+
end
|
76
|
+
alias last= last_entry=
|
77
|
+
|
78
|
+
def to_s()
|
79
|
+
to_yaml()
|
80
|
+
end
|
81
|
+
alias text to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|