most 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. data/Copying.txt +679 -0
  2. data/History.txt +15 -0
  3. data/Manifest.txt +95 -0
  4. data/PostInstall.txt +6 -0
  5. data/Rakefile +44 -0
  6. data/Readme.rdoc +146 -0
  7. data/bin/most +31 -0
  8. data/lib/most.rb +52 -0
  9. data/lib/most/context.rb +244 -0
  10. data/lib/most/core.rb +171 -0
  11. data/lib/most/di/container.rb +148 -0
  12. data/lib/most/di/proxy.rb +55 -0
  13. data/lib/most/di/service.rb +63 -0
  14. data/lib/most/di/service_factory.rb +40 -0
  15. data/lib/most/environment.rb +67 -0
  16. data/lib/most/executor.rb +80 -0
  17. data/lib/most/helpers/array.rb +31 -0
  18. data/lib/most/helpers/hash.rb +25 -0
  19. data/lib/most/helpers/kernel.rb +35 -0
  20. data/lib/most/helpers/memory_out.rb +93 -0
  21. data/lib/most/helpers/numeric.rb +59 -0
  22. data/lib/most/helpers/object.rb +65 -0
  23. data/lib/most/helpers/symbol.rb +31 -0
  24. data/lib/most/interfaces/meta_programmable.rb +59 -0
  25. data/lib/most/starter.rb +126 -0
  26. data/lib/most/structures/box.rb +199 -0
  27. data/lib/most/structures/submission.rb +117 -0
  28. data/lib/most/structures/test_case.rb +173 -0
  29. data/lib/most/structures/test_runner.rb +103 -0
  30. data/lib/most/structures/types/options.rb +67 -0
  31. data/lib/most/structures/types/path.rb +39 -0
  32. data/lib/most/structures/types/report.rb +84 -0
  33. data/lib/most/submissions/cpp_memory_out_sample.rb +34 -0
  34. data/lib/most/submissions/cpp_sample.rb +36 -0
  35. data/lib/most/submissions/cpp_timeout_sample.rb +34 -0
  36. data/lib/most/submissions/cs_sample.rb +36 -0
  37. data/lib/most/submissions/erlang_sample.rb +36 -0
  38. data/lib/most/submissions/haskell_sample.rb +36 -0
  39. data/lib/most/submissions/java_sample.rb +36 -0
  40. data/lib/most/submissions/lisp_sample.rb +32 -0
  41. data/lib/most/submissions/lua_sample.rb +36 -0
  42. data/lib/most/submissions/ocaml_sample.rb +36 -0
  43. data/lib/most/submissions/pascal_sample.rb +36 -0
  44. data/lib/most/submissions/perl_sample.rb +32 -0
  45. data/lib/most/submissions/php_sample.rb +32 -0
  46. data/lib/most/submissions/python_sample.rb +32 -0
  47. data/lib/most/submissions/ruby_sample.rb +32 -0
  48. data/lib/most/submissions/vb_sample.rb +36 -0
  49. data/lib/most/tasks/general/win/cs.rb +60 -0
  50. data/lib/most/tasks/general/win/erlang.rb +86 -0
  51. data/lib/most/tasks/general/win/gcc.rb +39 -0
  52. data/lib/most/tasks/general/win/haskell.rb +75 -0
  53. data/lib/most/tasks/general/win/java.rb +72 -0
  54. data/lib/most/tasks/general/win/lisp.rb +59 -0
  55. data/lib/most/tasks/general/win/lua.rb +75 -0
  56. data/lib/most/tasks/general/win/ocaml.rb +77 -0
  57. data/lib/most/tasks/general/win/pascal.rb +73 -0
  58. data/lib/most/tasks/general/win/perl.rb +61 -0
  59. data/lib/most/tasks/general/win/php.rb +59 -0
  60. data/lib/most/tasks/general/win/python.rb +59 -0
  61. data/lib/most/tasks/general/win/ruby.rb +61 -0
  62. data/lib/most/tasks/general/win/vb.rb +60 -0
  63. data/lib/most/tasks/general/win/vc.rb +79 -0
  64. data/lib/most/tasks/general/win/vs.rb +52 -0
  65. data/samples/problem/solutions/cpp/main.cpp +9 -0
  66. data/samples/problem/solutions/cpp/tests.yml +19 -0
  67. data/samples/problem/solutions/cs/main.cs +17 -0
  68. data/samples/problem/solutions/cs/tests.yml +19 -0
  69. data/samples/problem/solutions/erlang/main.erl +2 -0
  70. data/samples/problem/solutions/erlang/tests.yml +19 -0
  71. data/samples/problem/solutions/haskell/main.hs +5 -0
  72. data/samples/problem/solutions/haskell/tests.yml +19 -0
  73. data/samples/problem/solutions/java/Main.java +14 -0
  74. data/samples/problem/solutions/java/tests.yml +19 -0
  75. data/samples/problem/solutions/lisp/main.lisp +1 -0
  76. data/samples/problem/solutions/lisp/tests.yml +19 -0
  77. data/samples/problem/solutions/lua/main.lua +4 -0
  78. data/samples/problem/solutions/lua/tests.yml +19 -0
  79. data/samples/problem/solutions/ocaml/main.ml +3 -0
  80. data/samples/problem/solutions/ocaml/tests.yml +19 -0
  81. data/samples/problem/solutions/pascal/main.pas +5 -0
  82. data/samples/problem/solutions/pascal/tests.yml +19 -0
  83. data/samples/problem/solutions/perl/main.pl +2 -0
  84. data/samples/problem/solutions/perl/tests.yml +19 -0
  85. data/samples/problem/solutions/php/main.php +1 -0
  86. data/samples/problem/solutions/php/tests.yml +19 -0
  87. data/samples/problem/solutions/python/main.py +1 -0
  88. data/samples/problem/solutions/python/tests.yml +19 -0
  89. data/samples/problem/solutions/ruby/main.rb +1 -0
  90. data/samples/problem/solutions/ruby/tests.yml +19 -0
  91. data/samples/problem/solutions/vb/main.vb +14 -0
  92. data/samples/problem/solutions/vb/tests.yml +19 -0
  93. data/samples/time_memory/solutions/cpp/main.cpp +21 -0
  94. data/samples/time_memory/solutions/cpp/tests.yml +19 -0
  95. data/tasks/samples.rb +31 -0
  96. metadata +242 -0
data/lib/most/core.rb ADDED
@@ -0,0 +1,171 @@
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 'rake/clean'
21
+
22
+ require 'most/structures/submission'
23
+
24
+ module Most
25
+
26
+ class Core
27
+ class UnregisteredExtensionError < Exception; end
28
+
29
+ def initialize()
30
+ @environment = SERVICES[:environment]
31
+ @options = @environment.options
32
+
33
+ @strategies = register_strategies()
34
+
35
+ @last_eval_result = nil
36
+
37
+ load_objects()
38
+ end
39
+
40
+ def run()
41
+ result = nil
42
+
43
+ submission = @options[:submission]
44
+
45
+ paths = form_paths(submission)
46
+ extension = File.extname(submission)
47
+
48
+ proc = @strategies[extension]
49
+ unless proc.nil?
50
+ result = proc.call(paths)
51
+ else
52
+ exception = UnregisteredExtensionError.new("#{extension} is not registered")
53
+ @environment.log_error(exception, "Only 'rb' or 'yml' extensions are allowed")
54
+ end
55
+
56
+ result
57
+ end
58
+
59
+ private
60
+ def form_paths(submission)
61
+ paths = DIRECTORIES[:submissions].collect do |directory|
62
+ File.expand_path(File.join(directory, submission))
63
+ end
64
+
65
+ paths << File.expand_path(submission)
66
+
67
+ paths
68
+ end
69
+
70
+ def register_strategies()
71
+ result = {}
72
+
73
+ result['.yml'] = process_yaml_lambda()
74
+ result['.rb'] = process_ruby_lambda()
75
+
76
+ result
77
+ end
78
+
79
+ def process_yaml_lambda()
80
+ lambda do |paths|
81
+ result = ''
82
+
83
+ klass = nil; last_exception = nil
84
+ paths.each do |path|
85
+ begin
86
+ klass = YAML.load_file(path)
87
+ rescue LoadError => e
88
+ last_exception = e; next
89
+ rescue Exception => e
90
+ last_exception = e
91
+ end
92
+
93
+ break
94
+ end
95
+
96
+ unless klass.nil?
97
+ begin
98
+ result = klass.run()
99
+ rescue Exception => e
100
+ @environment.log_error(e, 'Failed to execute submission')
101
+ end
102
+ else
103
+ if last_exception.nil?
104
+ exception = TypeError.new("Invalid submission type")
105
+ else
106
+ exception = last_exception
107
+ end
108
+ @environment.log_error(exception, 'Submission load or execution failure')
109
+ end
110
+
111
+ result
112
+ end
113
+ end
114
+
115
+ def process_ruby_lambda()
116
+ lambda do |paths|
117
+ result = ''
118
+
119
+ code = nil; exception = nil
120
+ paths.each do |path|
121
+ begin
122
+ code = File.read(path)
123
+ rescue Exception => e
124
+ exception = e; next
125
+ end
126
+
127
+ break
128
+ end
129
+
130
+ unless code.nil?
131
+ begin
132
+ instance_eval(code); result = @last_eval_result
133
+ rescue Exception => e
134
+ @environment.log_error(e, 'Failed to execute submission')
135
+ end
136
+ else
137
+ @environment.log_error(exception, 'Submission load or execution failure')
138
+ end
139
+
140
+ result
141
+ end
142
+ end
143
+
144
+ def submission(*args, &block)
145
+ @last_eval_result = Submission.new(*args, &block).run()
146
+ end
147
+
148
+ def load_objects()
149
+ result = DIRECTORIES[:tasks]
150
+
151
+ if result.is_a?(Array)
152
+ result.each do |directory|
153
+ load_from_directory(directory)
154
+ end
155
+ else
156
+ load_from_directory(result)
157
+ end
158
+ end
159
+
160
+ def load_from_directory(directory)
161
+ Dir[File.join(directory, '**', '*.{rb,task,tasks}')].each do |file|
162
+ begin
163
+ require(file)
164
+ rescue Exception => e
165
+ @environment.log_error(e, 'Failed to load executor')
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ end
@@ -0,0 +1,148 @@
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/di/proxy'
22
+ require 'most/di/service_factory'
23
+
24
+ module Most
25
+ module DI
26
+
27
+ class Container
28
+ class TrapError < Exception; end
29
+
30
+ attr_reader :services
31
+
32
+ def initialize(&block)
33
+ @services = {}
34
+ @current_service = nil
35
+
36
+ instance_eval(&block) if block_given?
37
+ end
38
+
39
+ def service(name, &block)
40
+ @current_service = name
41
+
42
+ instance_eval(&block) if block_given?
43
+
44
+ @current_service = nil
45
+ end
46
+
47
+ def on_creation(&block)
48
+ asset(@current_service, &block)
49
+ end
50
+
51
+ def asset(name, options = {}, &block)
52
+ instance = nil
53
+
54
+ path = options[:file]
55
+ unless path.nil?
56
+ instance = YAML.load_file(File.expand_path(path)) rescue nil
57
+ end
58
+
59
+ if block_given? or not instance.nil?
60
+ service = get_service(name)
61
+
62
+ service[:block] = block
63
+ service[:instance] = instance
64
+ service[:file] = path
65
+ end
66
+ end
67
+
68
+ def interface(name, service_name = nil, &block)
69
+ service_name = @current_service if service_name.nil?
70
+
71
+ if block_given?
72
+ service = get_service(service_name)
73
+ service[:interfaces][name.intern()] = block unless service.nil?
74
+ end
75
+ end
76
+
77
+ def [](name)
78
+ result = nil
79
+
80
+ name = name.intern()
81
+ service = @services[name]
82
+
83
+ unless service.nil?
84
+ result = service[:instance]
85
+ if result.nil?
86
+ instance = service[:block].call()
87
+ unless instance.nil?
88
+ result = service[:instance] = Proxy.new(instance, service[:interfaces])
89
+ end
90
+ end
91
+ end
92
+
93
+ result
94
+ end
95
+
96
+ def serialize_marked()
97
+ @services.each do |key, service|
98
+ serialize(service)
99
+ end
100
+ end
101
+
102
+ def update(service)
103
+ serialize(service) if service[:file]
104
+ end
105
+
106
+ private
107
+ def serialize(service)
108
+ path = service[:file]
109
+ instance = service[:instance]
110
+
111
+ unless path.nil? and instance.nil?
112
+ begin
113
+ file = File.open(File.expand_path(path), 'w+')
114
+ file.write(instance.to_yaml())
115
+ rescue Exception => e
116
+ puts "DI container failed to serialize service to #{path}"
117
+ puts e.message, e.backtrace
118
+ ensure
119
+ file.close() unless file.nil?
120
+ end
121
+ end
122
+ end
123
+
124
+ def get_service(name)
125
+ result = nil
126
+
127
+ unless name.nil?
128
+ name = name.intern()
129
+
130
+ result = @services[name]
131
+ if result.nil?
132
+ new_service = DummyServiceFactory.get_service()
133
+ new_service.add_observer(self)
134
+
135
+ result = @services[name] = new_service
136
+ end
137
+ end
138
+
139
+ result
140
+ end
141
+
142
+ def teardown()
143
+ serialize_marked()
144
+ end
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,55 @@
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
+ module Most
20
+ module DI
21
+
22
+ class Proxy
23
+ instance_methods.each do |method|
24
+ undef_method method unless method =~ /(^__|^send$|^object_id$)/
25
+ end
26
+
27
+ attr_reader :delegate, :interfaces
28
+
29
+ def initialize(delegate, interfaces = {})
30
+ @delegate = delegate
31
+ @interfaces = interfaces
32
+ end
33
+
34
+ private
35
+ def method_missing(name, *args, &block)
36
+ result = nil
37
+
38
+ begin
39
+ interface = @interfaces[name.intern()]
40
+ unless interface.nil?
41
+ args << block if block_given?
42
+ result = interface.call(@delegate, *args)
43
+ else
44
+ result = @delegate.send(name, *args, &block)
45
+ end
46
+ rescue Exception => e
47
+ raise(e, "delegate - #{@delegate.class}, method - #{name} #{args}")
48
+ end
49
+
50
+ result
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,63 @@
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 'observer'
20
+
21
+ module Most
22
+ module DI
23
+
24
+ class Service
25
+ include Observable
26
+
27
+ attr_reader :definition
28
+
29
+ def initialize(definition = default_definition())
30
+ @definition = definition; state_update()
31
+ end
32
+
33
+ def [](key)
34
+ @definition[key]
35
+ end
36
+
37
+ def []=(key, value)
38
+ result = nil
39
+
40
+ previous_value = @definition[key]
41
+ result = @definition[key] = value
42
+
43
+ state_update() if previous_value != value
44
+
45
+ result
46
+ end
47
+
48
+ def nil?()
49
+ @definition.nil?
50
+ end
51
+
52
+ private
53
+ def state_update()
54
+ changed(); notify_observers(@definition)
55
+ end
56
+
57
+ def default_definition()
58
+ {:block => nil, :instance => nil, :interfaces => nil, :file => nil}
59
+ end
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,40 @@
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 'most/di/service'
20
+
21
+ module Most
22
+ module DI
23
+
24
+ class ServiceFactory
25
+ def self.get_service()
26
+ Service.new()
27
+ end
28
+ end
29
+
30
+ class DummyServiceFactory < ServiceFactory
31
+ def self.get_service()
32
+ service = Service.new()
33
+ service.definition[:interfaces] = {}
34
+
35
+ service
36
+ end
37
+ end
38
+
39
+ end
40
+ end