tryouts 0.8.8 → 2.0.0
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.
- data/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +64 -228
- data/Rakefile +42 -65
- data/VERSION.yml +5 -0
- data/bin/try +26 -0
- data/lib/sysinfo.rb +278 -0
- data/lib/tryouts.rb +405 -320
- data/try/step1_try.rb +51 -0
- data/try/step2_try.rb +59 -0
- data/try/step3_try.rb +19 -0
- data/try/step4_try.rb +6 -0
- metadata +20 -75
- data/CHANGES.txt +0 -202
- data/bin/mockout +0 -54
- data/bin/sergeant +0 -66
- data/lib/tryouts/cli/run.rb +0 -229
- data/lib/tryouts/cli.rb +0 -15
- data/lib/tryouts/drill/context.rb +0 -33
- data/lib/tryouts/drill/dream.rb +0 -57
- data/lib/tryouts/drill/reality.rb +0 -49
- data/lib/tryouts/drill/response.rb +0 -117
- data/lib/tryouts/drill/sergeant/api.rb +0 -42
- data/lib/tryouts/drill/sergeant/benchmark.rb +0 -76
- data/lib/tryouts/drill/sergeant/cli.rb +0 -66
- data/lib/tryouts/drill/sergeant/rbenchmark.rb +0 -132
- data/lib/tryouts/drill.rb +0 -224
- data/lib/tryouts/mixins.rb +0 -37
- data/lib/tryouts/orderedhash.rb +0 -199
- data/lib/tryouts/stats.rb +0 -96
- data/lib/tryouts/tryout.rb +0 -176
- data/tryouts/01_mixins_tryouts.rb +0 -23
- data/tryouts/10_syntax_tryouts.rb +0 -44
- data/tryouts/14_set_tryouts.rb +0 -26
- data/tryouts/15_dreams_tryouts.rb +0 -54
- data/tryouts/20_cli_tryouts.rb +0 -40
- data/tryouts/30_benchmark_tryouts.rb +0 -27
- data/tryouts/50_class_context_tryouts.rb +0 -33
- data/tryouts/X1_new_api_syntax.rb +0 -78
- data/tryouts/X2_new_cli_syntax.rb +0 -36
- data/tryouts/standalone_test.rb +0 -39
- data/tryouts.gemspec +0 -84
data/lib/tryouts/cli/run.rb
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
|
2
|
-
class Tryouts; module CLI
|
3
|
-
|
4
|
-
# = Run
|
5
|
-
#
|
6
|
-
# The logic bin/tryouts uses for running tryouts.
|
7
|
-
class Run < Drydock::Command
|
8
|
-
|
9
|
-
def init
|
10
|
-
@tryouts_globs = [GYMNASIUM_GLOB, File.join(Dir.pwd, '*_tryouts.rb')]
|
11
|
-
end
|
12
|
-
|
13
|
-
# $ sergeant dreams [path/2/tryouts]
|
14
|
-
# Display the dreams from all known tryouts
|
15
|
-
def dreams
|
16
|
-
load_available_tryouts_files
|
17
|
-
if Tryouts.verbose > 0
|
18
|
-
puts Tryouts.dreams.to_yaml
|
19
|
-
else
|
20
|
-
Tryouts.dreams.each_pair do |n,dreams|
|
21
|
-
puts n
|
22
|
-
dreams.each_pair do |n, dream|
|
23
|
-
puts " " << n
|
24
|
-
dream.each_pair do |n, drill|
|
25
|
-
puts " " << n
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# $ sergeant run [path/2/tryouts]
|
33
|
-
# Executes all tryouts that can be found from the current working directory.
|
34
|
-
def run
|
35
|
-
start = Time.now
|
36
|
-
|
37
|
-
Tryouts.enable_debug if Drydock.debug?
|
38
|
-
Tryouts.verbose = @global.quiet ? -1 : @global.verbose
|
39
|
-
|
40
|
-
if Tryouts.verbose > 0
|
41
|
-
print "Tryouts #{Tryouts::VERSION} -- "
|
42
|
-
print "#{Tryouts.sysinfo.to_s}@#{RUBY_VERSION} -- "
|
43
|
-
puts "#{start.strftime("%Y-%m-%d %H:%M:%S")}"
|
44
|
-
puts
|
45
|
-
end
|
46
|
-
|
47
|
-
load_available_tryouts_files
|
48
|
-
|
49
|
-
passed, failed = 0, 0
|
50
|
-
Tryouts.instances.each_pair do |group,tryouts_inst|
|
51
|
-
puts unless group == Tryouts.instances.keys.first
|
52
|
-
puts ' %-79s'.att(:reverse) % group unless Tryouts.verbose < 0
|
53
|
-
puts " #{tryouts_inst.paths.join("\n ")}" if Tryouts.verbose > 0
|
54
|
-
tryouts_inst.tryouts.each_pair do |name,to|
|
55
|
-
begin
|
56
|
-
to.run
|
57
|
-
to.report
|
58
|
-
rescue SyntaxError, LoadError, Exception, TypeError,
|
59
|
-
RuntimeError, NoMethodError, NameError => ex
|
60
|
-
tryouts_inst.errors << ex
|
61
|
-
end
|
62
|
-
STDOUT.flush
|
63
|
-
passed += to.passed
|
64
|
-
failed += to.failed
|
65
|
-
end
|
66
|
-
|
67
|
-
unless tryouts_inst.errors.empty?
|
68
|
-
title = '%-78s' % " RUNTIME ERRORS !?"
|
69
|
-
puts $/, ' ' << title.color(:red).att(:reverse).bright
|
70
|
-
tryouts_inst.errors.each do |ex|
|
71
|
-
|
72
|
-
puts '%4s%s: %s' % ['', ex.class, ex.message.to_s.split($/).join($/ + ' '*16)]
|
73
|
-
puts
|
74
|
-
|
75
|
-
if [SyntaxError].member? ex.class
|
76
|
-
# don't print anymore.
|
77
|
-
else
|
78
|
-
unless ex.backtrace.nil?
|
79
|
-
trace = Tryouts.verbose > 1 ? ex.backtrace : [ex.backtrace.first]
|
80
|
-
puts '%14s %s' % ["", trace.join($/ + ' '*16)]
|
81
|
-
puts
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
if Tryouts.verbose < 0
|
89
|
-
if (passed == 0 && failed == 0)
|
90
|
-
exit -1
|
91
|
-
elsif failed == 0 && !Tryouts.failed?
|
92
|
-
puts "PASS"
|
93
|
-
exit 0
|
94
|
-
else
|
95
|
-
puts "FAIL"
|
96
|
-
exit 1
|
97
|
-
end
|
98
|
-
else
|
99
|
-
if Tryouts.verbose > 0
|
100
|
-
elapsed = Time.now - start
|
101
|
-
puts $/, " Elapsed: %.3f seconds" % elapsed.to_f #if elapsed > 0.01
|
102
|
-
end
|
103
|
-
if (passed == 0 && failed == 0)
|
104
|
-
puts DEV if Tryouts.verbose > 4
|
105
|
-
msg = " You didn't even try to acheive your dreams :[ "
|
106
|
-
puts $/, msg.att(:reverse)
|
107
|
-
exit -1
|
108
|
-
elsif failed == 0 && !Tryouts.failed?
|
109
|
-
puts PUG if Tryouts.verbose > 4
|
110
|
-
msg = passed > 1 ? "All %s dreams" : "Your only dream"
|
111
|
-
msg = (" #{msg} came true " % [passed+failed]).color(:green)
|
112
|
-
puts $/, msg.att(:reverse)
|
113
|
-
exit 0
|
114
|
-
else
|
115
|
-
puts BUG if Tryouts.verbose > 4
|
116
|
-
score = (passed.to_f / (passed.to_f+failed.to_f)) * 100
|
117
|
-
msg = " %s of %s dreams came true (%d%%) ".color(:red)
|
118
|
-
msg = msg % [passed, passed+failed, score.to_i]
|
119
|
-
puts $/, msg.att(:reverse)
|
120
|
-
exit 1
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# $ sergeant list
|
127
|
-
# Displays all known tryouts from the current working directory
|
128
|
-
def list
|
129
|
-
load_available_tryouts_files
|
130
|
-
Tryouts.instances.each_pair do |n,tryouts_inst|
|
131
|
-
puts n
|
132
|
-
if Tryouts.verbose > 0
|
133
|
-
puts " #{tryouts_inst.paths.join("\n ")}"
|
134
|
-
end
|
135
|
-
tryouts_inst.tryouts.each_pair do |t2,tryout|
|
136
|
-
puts " " << tryout.name
|
137
|
-
tryout.drills.each do |drill|
|
138
|
-
puts " " << drill.name
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
# Find and load all tryouts files
|
147
|
-
def load_available_tryouts_files
|
148
|
-
@tryouts_files = []
|
149
|
-
# If file paths were given, check those only.
|
150
|
-
unless @argv.empty?
|
151
|
-
@argv.each do |file|
|
152
|
-
unless File.exists?(file)
|
153
|
-
raise Tryouts::Exception, "Not found: #{file}"
|
154
|
-
end
|
155
|
-
file = File.join(file, '**', '*_tryouts.rb') if File.directory?(file)
|
156
|
-
@tryouts_files += Dir.glob file
|
157
|
-
end
|
158
|
-
# Otherwise check the default globs
|
159
|
-
else
|
160
|
-
@tryouts_globs.each do |glob|
|
161
|
-
@tryouts_files += Dir.glob glob
|
162
|
-
end
|
163
|
-
end
|
164
|
-
@tryouts_files.uniq! # Don't load the same file twice
|
165
|
-
@tryouts_files.each { |f| puts "LOADING: #{f}"} if Tryouts.verbose > 1
|
166
|
-
@tryouts_files.each { |file| Tryouts.parse_file file }
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end; end
|
170
|
-
|
171
|
-
class Tryouts::CLI::Run
|
172
|
-
DEV = %q{
|
173
|
-
^^ @@@@@@@@@
|
174
|
-
^^ ^^ @@@@@@@@@@@@@@@
|
175
|
-
@@@@@@@@@@@@@@@@@@ ^^
|
176
|
-
@@@@@@@@@@@@@@@@@@@@
|
177
|
-
~~~ ~~~~~~~~ ~~ &&&&&&&&&&&&&&&&&&&& ~~~~~~~ ~~~~~~~~~~~ ~~
|
178
|
-
~~ ~ ~ ~~~~~~~~~~~~~~~~~~~~ ~ ~~ ~~ ~
|
179
|
-
~ ~~ ~~ ~~ ~~~~~~~~~~~~~ ~~~~ ~ ~~~ ~ ~~~ ~
|
180
|
-
~ ~ ~~~~~~ ~~ ~~~ ~~ ~ ~~ ~~ ~
|
181
|
-
~ ~ ~ ~~ ~~~~~~ ~ ~~ ~ ~~~
|
182
|
-
~ ~ ~ ~~ ~ ~
|
183
|
-
}
|
184
|
-
BUG = %q{
|
185
|
-
,--.____ ____.--.
|
186
|
-
/ .'.'"``--...----------.___.----------...--''"`.`. \
|
187
|
-
| .'.' . . `.`. |
|
188
|
-
`. .'| . ' - . _ `-----' _ . - ' . |`. .'
|
189
|
-
`.' `| .' _ "-._ _.-" _ `. |' `.'
|
190
|
-
| | " -. .- " | |
|
191
|
-
\| ;;.. "|i. .i|" ..;; |/
|
192
|
-
`| ,---.``. ' ' .'',---. |'
|
193
|
-
| <'(__.'>.'---` '---`.<`.__)`> |
|
194
|
-
| `. `~ .' ,-------. `. ~'.' |
|
195
|
-
| |=_"`=.' . `-.___.-' . `.='"_=| |
|
196
|
-
| | ==/ : ` : i : ' : \== | |
|
197
|
-
| | ==/ /\___|___/\ \== | |
|
198
|
-
`.| =Y .' """_""" `. Y= |.'
|
199
|
-
L || ; .=="==. ; || J
|
200
|
-
\ ; .' ' ` `. ; /
|
201
|
-
`. ; ; .'
|
202
|
-
; ;'\ /`; ;
|
203
|
-
`; .'.'/. ,\`.`. ;'
|
204
|
-
`-=;_-' `-----' `-_;=-' -bodom-
|
205
|
-
}
|
206
|
-
PUG = %q{
|
207
|
-
__,-----._ ,-.
|
208
|
-
,' ,-. \`---. ,-----<._/
|
209
|
-
(,.-. o:.` )),"\\\-._ ,' `.
|
210
|
-
('"-` .\ \`:_ )\ `-;'-._ \
|
211
|
-
,,-. \` ; : \( `-' ) -._ : `:
|
212
|
-
( \ `._\\\ ` ; ; ` : )
|
213
|
-
\`. `-. __ , / \ ;, (
|
214
|
-
`.`-.___--' `- / ; | : |
|
215
|
-
`-' `-.`--._ ' ; |
|
216
|
-
(`--._`. ; /\ |
|
217
|
-
\ ' \ , ) :
|
218
|
-
| `--::---- \' ; ;|
|
219
|
-
\ .__,- ( ) : :|
|
220
|
-
\ : `------; \ | | ;
|
221
|
-
\ : / , ) | | (
|
222
|
-
\ \ `-^-| | / , ,\
|
223
|
-
) ) | -^- ; `-^-^'
|
224
|
-
_,' _ ; | |
|
225
|
-
/ , , ,' /---. :
|
226
|
-
`-^-^' ( : :,'
|
227
|
-
`-^--' -hrr-
|
228
|
-
}
|
229
|
-
end
|
data/lib/tryouts/cli.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Tryouts
|
4
|
-
class Tryout
|
5
|
-
|
6
|
-
# All :api and :benchmark drills are run within this context.
|
7
|
-
# Each Drill is executed in a new instance of this class. That means
|
8
|
-
# instance variables are not carried through, but class variables are.
|
9
|
-
# The before and after blocks are also run in this context.
|
10
|
-
class DrillContext
|
11
|
-
# An ordered Hash of stashed objects.
|
12
|
-
attr_writer :stash
|
13
|
-
|
14
|
-
def initialize; @stash = Tryouts::HASH_TYPE.new; @has_dream = false; end
|
15
|
-
|
16
|
-
# Set to to true by DrillContext#dream
|
17
|
-
def has_dream?; @has_dream; end
|
18
|
-
|
19
|
-
# If called with no arguments, returns +@stash+.
|
20
|
-
# If called with arguments, it will add a new value to the +@stash+
|
21
|
-
# and return the new value. e.g.
|
22
|
-
#
|
23
|
-
# stash :name, 'some value' # => 'some value'
|
24
|
-
#
|
25
|
-
def stash(*args)
|
26
|
-
return @stash if args.empty?
|
27
|
-
@stash[args[0]] = args[1]
|
28
|
-
args[1]
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/tryouts/drill/dream.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Tryouts::Drill
|
4
|
-
# = Dream
|
5
|
-
#
|
6
|
-
# Contains the expected response of a Drill
|
7
|
-
#
|
8
|
-
class Dream < Tryouts::Drill::Response
|
9
|
-
|
10
|
-
# A proc which is run just before the associated drill.
|
11
|
-
# The return value overrides <tt>@output</tt>.
|
12
|
-
attr_accessor :output_block
|
13
|
-
|
14
|
-
# Populates <tt>@output</tt> with the return value of
|
15
|
-
# <tt>output_block</tt> or <tt>&definition</tt> if provided.
|
16
|
-
def execute_output_block(&definition)
|
17
|
-
definition ||= @output_block
|
18
|
-
return if definition.nil?
|
19
|
-
self.output = instance_eval &definition
|
20
|
-
end
|
21
|
-
|
22
|
-
# Takes a String +val+ and splits the lines into an Array.
|
23
|
-
def inline(val=nil)
|
24
|
-
lines = (val.split($/) || [])
|
25
|
-
lines.shift if lines.first.strip == ""
|
26
|
-
lines.pop if lines.last.strip == ""
|
27
|
-
lines
|
28
|
-
end
|
29
|
-
|
30
|
-
def ==(reality)
|
31
|
-
return @answer unless @answer.nil?
|
32
|
-
@answer = Response.compare(self, reality)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_to_string(reality)
|
36
|
-
return @test_string unless @test_string.nil?
|
37
|
-
@test_string = Response.compare_string(self, reality)
|
38
|
-
end
|
39
|
-
|
40
|
-
def comparison_value
|
41
|
-
return @ret unless @ret.nil?
|
42
|
-
@ret = case @format
|
43
|
-
when :gt, :gte, :lt, :lte, :ne
|
44
|
-
op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == @format }
|
45
|
-
@output
|
46
|
-
when :proc
|
47
|
-
true
|
48
|
-
when :respond_to?, :is_a?, :kind_of?
|
49
|
-
true
|
50
|
-
when :grep
|
51
|
-
@output
|
52
|
-
else
|
53
|
-
@output
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
class Tryouts::Drill
|
2
|
-
|
3
|
-
# = Reality
|
4
|
-
#
|
5
|
-
# Contains the actual response of a Drill
|
6
|
-
#
|
7
|
-
class Reality < Tryouts::Drill::Response
|
8
|
-
# An ordered hash taken from the DrillContext that created this Reality.
|
9
|
-
attr_accessor :stash
|
10
|
-
attr_accessor :error
|
11
|
-
attr_accessor :trace
|
12
|
-
attr_accessor :ecode
|
13
|
-
attr_accessor :etype
|
14
|
-
# For :cli drills only. Contains the shell command string.
|
15
|
-
attr_accessor :command
|
16
|
-
def initialize
|
17
|
-
@stash = Tryouts::HASH_TYPE.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def ==(dream)
|
21
|
-
Response.compare(dream, self)
|
22
|
-
end
|
23
|
-
|
24
|
-
def comparison_value(dream)
|
25
|
-
case dream.format
|
26
|
-
when :proc
|
27
|
-
test = dream.output
|
28
|
-
(test.arity > 0 ? test.call(@output) : test.call)
|
29
|
-
when :exception
|
30
|
-
@etype
|
31
|
-
when :respond_to?, :is_a?, :kind_of?, :grep
|
32
|
-
@output.send(dream.format, dream.output)
|
33
|
-
when nil
|
34
|
-
@output
|
35
|
-
else
|
36
|
-
return nil if @output.nil?
|
37
|
-
|
38
|
-
if !dream.format.is_a?(Symbol)
|
39
|
-
"This dream format is not a Symbol: #{dream.format}"
|
40
|
-
elsif @output.respond_to?(dream.format)
|
41
|
-
@output.send(dream.format)
|
42
|
-
else
|
43
|
-
@output
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
|
2
|
-
class Tryouts::Drill
|
3
|
-
# = Response
|
4
|
-
#
|
5
|
-
# A generic base class for Dream and Reality
|
6
|
-
#
|
7
|
-
class Response
|
8
|
-
attr_accessor :output, :format
|
9
|
-
def initialize(output=nil, format=nil)
|
10
|
-
@output, @format = output, format
|
11
|
-
end
|
12
|
-
|
13
|
-
def format(val=nil); @format = val.to_sym unless val.nil?; @format; end
|
14
|
-
def format=(val); @format = val.to_sym; @format; end
|
15
|
-
|
16
|
-
def Response.compare(dream, reality)
|
17
|
-
return false if reality.nil?
|
18
|
-
|
19
|
-
## I don't think this check is necessary or useful
|
20
|
-
##return false unless reality.error.nil? && reality.trace.nil?
|
21
|
-
return true if reality.output == true and dream.nil?
|
22
|
-
|
23
|
-
# Refactor like:
|
24
|
-
# http://github.com/why/hpricot/blob/master/lib/hpricot/elements.rb#L475
|
25
|
-
|
26
|
-
begin
|
27
|
-
case dream.format
|
28
|
-
when :exception
|
29
|
-
reality.etype == dream.output
|
30
|
-
when :match
|
31
|
-
reality.output.respond_to?(:match) &&
|
32
|
-
!reality.output.match(dream.output).nil?
|
33
|
-
when :proc
|
34
|
-
dream.output.is_a?(Proc) &&
|
35
|
-
reality.comparison_value(dream) == dream.comparison_value
|
36
|
-
when :mean, :sdev
|
37
|
-
reality.comparison_value(dream) <= dream.comparison_value
|
38
|
-
when :gt
|
39
|
-
reality.output > dream.output
|
40
|
-
when :gte
|
41
|
-
reality.output >= dream.output
|
42
|
-
when :lt
|
43
|
-
reality.output < dream.output
|
44
|
-
when :lte
|
45
|
-
reality.output <= dream.output
|
46
|
-
when :ne
|
47
|
-
reality.output != dream.output
|
48
|
-
when :respond_to?, :kind_of?, :is_a?
|
49
|
-
reality.output.send(dream.format, dream.output)
|
50
|
-
when :grep
|
51
|
-
!reality.output.grep(dream.output).empty?
|
52
|
-
else
|
53
|
-
|
54
|
-
if dream.format.nil?
|
55
|
-
reality.output == dream.output
|
56
|
-
elsif reality.output.respond_to?(dream.format)
|
57
|
-
reality.comparison_value(dream) == dream.output
|
58
|
-
else
|
59
|
-
false
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
rescue => ex
|
64
|
-
puts ex.message, ex.backtrace if Tryouts.debug?
|
65
|
-
reality.error, reality.trace, reality.etype = ex.message, ex.backtrace, ex.class
|
66
|
-
return false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def Response.compare_string(dream, reality)
|
71
|
-
return "[noreality]" if reality.nil?
|
72
|
-
|
73
|
-
if reality.output == true and dream.nil?
|
74
|
-
return "#{reality.output.inspect} == true"
|
75
|
-
end
|
76
|
-
|
77
|
-
begin
|
78
|
-
case dream.format
|
79
|
-
when :proc
|
80
|
-
test = dream.output
|
81
|
-
test.arity > 0 ? "Proc.call(reality) == true" : "Proc.call == true"
|
82
|
-
when :exception
|
83
|
-
"#{reality.etype} == #{dream.output}"
|
84
|
-
when :mean, :sdev
|
85
|
-
"#{reality.comparison_value(dream)} <= #{dream.output}"
|
86
|
-
when :match
|
87
|
-
"#{reality.output.inspect}.match(#{dream.output.inspect})"
|
88
|
-
when :gt, :gte, :lt, :lte, :ne
|
89
|
-
op = {:gt=>'>',:gte=>'>=', :lt=>'<', :lte => '<=', :ne => '!='}.find { |i| i[0] == dream.format }
|
90
|
-
"#{reality.output.inspect} #{op[1]} #{dream.output.inspect}"
|
91
|
-
when :respond_to?, :kind_of?, :is_a?
|
92
|
-
"#{reality.output.class}.#{dream.format} #{dream.output.inspect}"
|
93
|
-
when :grep
|
94
|
-
"!#{reality.output}.grep(#{dream.output.inspect}).empty?"
|
95
|
-
else
|
96
|
-
|
97
|
-
if dream.format.nil?
|
98
|
-
"#{reality.output.inspect} == #{dream.output.inspect}"
|
99
|
-
elsif reality.output.respond_to?(dream.format)
|
100
|
-
"#{reality.output.inspect}.#{dream.format} == #{dream.output.inspect}"
|
101
|
-
else
|
102
|
-
"Unknown method #{dream.format.inspect} for #{reality.output.class} "
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
rescue => ex
|
107
|
-
puts ex.message, ex.backtrace if Tryouts.debug?
|
108
|
-
reality.error, reality.trace, reality.etype = ex.message, ex.backtrace, ex.class
|
109
|
-
return ""
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
class Tryouts; class Drill; module Sergeant
|
5
|
-
|
6
|
-
# = API
|
7
|
-
#
|
8
|
-
# The sergeant responsible for running Ruby code (API) drills.
|
9
|
-
#
|
10
|
-
class API
|
11
|
-
|
12
|
-
attr_reader :output
|
13
|
-
|
14
|
-
# +opts+ is a Hash with the following optional keys:
|
15
|
-
#
|
16
|
-
# * +:output+ specify a return value. This will be
|
17
|
-
# used if no block is specified for the drill.
|
18
|
-
def initialize(output=nil)
|
19
|
-
@output = output
|
20
|
-
end
|
21
|
-
|
22
|
-
def run(block, context, &inline)
|
23
|
-
# A Proc object takes precedence over an inline block.
|
24
|
-
runtime = (block.nil? ? inline : block)
|
25
|
-
response = Tryouts::Drill::Reality.new
|
26
|
-
if runtime.nil?
|
27
|
-
response.output = @output
|
28
|
-
else
|
29
|
-
begin
|
30
|
-
response.output = context.instance_eval &runtime
|
31
|
-
rescue => e
|
32
|
-
puts e.message, e.backtrace if Tryouts.verbose > 2
|
33
|
-
response.etype = e.class
|
34
|
-
response.error = e.message
|
35
|
-
response.trace = e.backtrace
|
36
|
-
end
|
37
|
-
end
|
38
|
-
response
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end; end; end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
class Tryouts; class Drill; module Sergeant
|
6
|
-
|
7
|
-
# = Benchmark
|
8
|
-
#
|
9
|
-
# The sergeant responsible for running benchmarks
|
10
|
-
#
|
11
|
-
class Benchmark
|
12
|
-
require 'benchmark'
|
13
|
-
|
14
|
-
attr_reader :output
|
15
|
-
|
16
|
-
FIELDS = [:utime, :stime, :cutime, :cstime, :total, :real].freeze
|
17
|
-
|
18
|
-
# * +reps+ Number of times to execute drill (>= 0, <= 1000000). Default: 3
|
19
|
-
#
|
20
|
-
def initialize(reps=nil)
|
21
|
-
reps = 1 if reps.nil?
|
22
|
-
@reps = (1..1000000).include?(reps) ? reps : 5
|
23
|
-
@warmups = reps < 10 ? 1 : 10
|
24
|
-
@stats = {}
|
25
|
-
end
|
26
|
-
|
27
|
-
def run(block, context, &inline)
|
28
|
-
# A Proc object takes precedence over an inline block.
|
29
|
-
runtime = (block.nil? ? inline : block)
|
30
|
-
response = Tryouts::Drill::Reality.new
|
31
|
-
|
32
|
-
if runtime.nil?
|
33
|
-
raise "We need a block to benchmark"
|
34
|
-
else
|
35
|
-
begin
|
36
|
-
|
37
|
-
@warmups.times do
|
38
|
-
tms = ::Benchmark.measure {
|
39
|
-
context.instance_eval &runtime
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
@stats[:rtotal] = Tryouts::Stats.new(:rtotal)
|
44
|
-
@reps.times do
|
45
|
-
tms = ::Benchmark.measure {
|
46
|
-
context.instance_eval &runtime
|
47
|
-
}
|
48
|
-
process_tms(tms)
|
49
|
-
end
|
50
|
-
@stats[:rtotal].tick
|
51
|
-
|
52
|
-
# We add the output after we run the block so that
|
53
|
-
# that it'll remain nil if an exception was raised
|
54
|
-
response.output = @stats
|
55
|
-
|
56
|
-
rescue => e
|
57
|
-
puts e.message, e.backtrace if Tryouts.verbose > 2
|
58
|
-
response.etype = e.class
|
59
|
-
response.error = e.message
|
60
|
-
response.trace = e.backtrace
|
61
|
-
end
|
62
|
-
end
|
63
|
-
response
|
64
|
-
end
|
65
|
-
|
66
|
-
def process_tms(tms)
|
67
|
-
FIELDS.each do |f|
|
68
|
-
@stats[f] ||= Tryouts::Stats.new(f)
|
69
|
-
@stats[f].sample tms.send(f)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.fields() FIELDS end
|
74
|
-
|
75
|
-
end
|
76
|
-
end; end; end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
autoload :Rye, 'rye' # Make sure rye is loaded
|
2
|
-
|
3
|
-
class Tryouts; class Drill; module Sergeant
|
4
|
-
|
5
|
-
# = CLI
|
6
|
-
#
|
7
|
-
# The sergeant responsible for running command-line interface drills.
|
8
|
-
#
|
9
|
-
class CLI
|
10
|
-
|
11
|
-
attr_accessor :rbox
|
12
|
-
|
13
|
-
# An Array of arguments to be sent to <tt>rbox.send(@command, *rbox_args)</tt>
|
14
|
-
attr_accessor :rbox_args
|
15
|
-
|
16
|
-
# The command name to execute <tt>rbox.send(@command, *rbox_args)</tt>
|
17
|
-
attr_accessor :command
|
18
|
-
|
19
|
-
def initialize(*args)
|
20
|
-
@command = args.shift
|
21
|
-
@rbox_args = args
|
22
|
-
@rbox = Rye::Box.new
|
23
|
-
end
|
24
|
-
|
25
|
-
# NOTE: Context is ignored for the CLI Sergeant.
|
26
|
-
def run(block, context=nil, &inline)
|
27
|
-
# A Proc object takes precedence over an inline block.
|
28
|
-
runtime = (block.nil? ? inline : block)
|
29
|
-
response = Tryouts::Drill::Reality.new
|
30
|
-
|
31
|
-
if @command.nil?
|
32
|
-
response.command = '[block]'
|
33
|
-
else
|
34
|
-
response.command = '$ ' << @rbox.preview_command(@command, *@rbox_args)
|
35
|
-
end
|
36
|
-
|
37
|
-
begin
|
38
|
-
if runtime.nil?
|
39
|
-
ret = @rbox.send @command, *@rbox_args
|
40
|
-
response.output = ret.stdout
|
41
|
-
response.ecode = ret.exit_code
|
42
|
-
response.error = ret.stderr unless ret.stderr.empty?
|
43
|
-
else
|
44
|
-
response.output = @rbox.instance_eval &runtime
|
45
|
-
end
|
46
|
-
|
47
|
-
rescue Rye::CommandNotFound => ex
|
48
|
-
puts ex.message, ex.backtrace if Tryouts.verbose > 2
|
49
|
-
response.etype = ex.class
|
50
|
-
response.ecode = ex.exit_code
|
51
|
-
response.error = "[#{@rbox.host}] Command not found: #{ex.message}"
|
52
|
-
response.trace = ex.backtrace
|
53
|
-
rescue Rye::CommandError => ex
|
54
|
-
puts ex.message, ex.backtrace if Tryouts.verbose > 2
|
55
|
-
response.etype = ex.class
|
56
|
-
response.ecode = ex.exit_code
|
57
|
-
response.output = ex.stdout
|
58
|
-
response.error = ex.stderr.join $/
|
59
|
-
response.trace = ex.backtrace
|
60
|
-
end
|
61
|
-
response
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end; end; end
|