boc 0.3.2 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +5 -0
- data/README.rdoc +5 -5
- data/Rakefile +133 -7
- data/devel/levitate.rb +234 -340
- data/ext/boc/boc.c +6 -12
- data/jext/boc/BocService.java +111 -0
- data/lib/boc/version.rb +1 -1
- data/lib/boc.rb +80 -60
- data/test/basic_test.rb +58 -9
- data/test/jruby_trial.rb +20 -0
- data/test/readme_test.rb +7 -3
- metadata +5 -4
- data/MANIFEST +0 -14
data/devel/levitate.rb
CHANGED
@@ -1,231 +1,33 @@
|
|
1
1
|
|
2
2
|
class Levitate
|
3
|
-
|
4
|
-
|
5
|
-
require 'fileutils'
|
6
|
-
require 'rbconfig'
|
7
|
-
require 'find'
|
8
|
-
|
9
|
-
rb_root = RbConfig::CONFIG["sitelibdir"]
|
10
|
-
@spec = []
|
11
|
-
|
12
|
-
Find.find "lib" do |source|
|
13
|
-
next if source == "lib"
|
14
|
-
next unless File.directory?(source) || File.extname(source) == ".rb"
|
15
|
-
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
16
|
-
@spec << { :source => source, :dest => dest }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def install
|
21
|
-
@spec.each do |entry|
|
22
|
-
source, dest = entry.values_at(:source, :dest)
|
23
|
-
if File.directory?(source)
|
24
|
-
unless File.directory?(dest)
|
25
|
-
puts "mkdir #{dest}"
|
26
|
-
FileUtils.mkdir(dest)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
puts "install #{source} --> #{dest}"
|
30
|
-
FileUtils.install(source, dest)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def uninstall
|
36
|
-
@spec.reverse.each do |entry|
|
37
|
-
source, dest = entry.values_at(:source, :dest)
|
38
|
-
if File.directory?(source)
|
39
|
-
if File.directory?(dest)
|
40
|
-
puts "rmdir #{dest}"
|
41
|
-
FileUtils.rmdir(dest)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
if File.file?(dest)
|
45
|
-
puts "rm #{dest}"
|
46
|
-
FileUtils.rm(dest)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module AttrLazy
|
54
|
-
def attr_lazy(name, &block)
|
55
|
-
AttrLazy.define_reader(class << self ; self ; end, name, &block)
|
56
|
-
end
|
57
|
-
|
58
|
-
def attr_lazy_accessor(name, &block)
|
59
|
-
attr_lazy(name, &block)
|
60
|
-
AttrLazy.define_writer(class << self ; self ; end, name, &block)
|
61
|
-
end
|
62
|
-
|
63
|
-
class << self
|
64
|
-
def included(mod)
|
65
|
-
(class << mod ; self ; end).class_eval do
|
66
|
-
def attr_lazy(name, &block)
|
67
|
-
AttrLazy.define_reader(self, name, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
def attr_lazy_accessor(name, &block)
|
71
|
-
attr_lazy(name, &block)
|
72
|
-
AttrLazy.define_writer(self, name, &block)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
3
|
+
def initialize(gem_name)
|
4
|
+
@gem_name = gem_name
|
76
5
|
|
77
|
-
|
78
|
-
(class << instance ; self ; end).class_eval do
|
79
|
-
remove_method name rescue nil
|
80
|
-
define_method name do
|
81
|
-
value
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
6
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
85
7
|
|
86
|
-
|
87
|
-
klass.class_eval do
|
88
|
-
remove_method name rescue nil
|
89
|
-
define_method name do
|
90
|
-
value = instance_eval(&block)
|
91
|
-
AttrLazy.define_evaluated_reader(self, name, value)
|
92
|
-
value
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
8
|
+
yield self
|
96
9
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
remove_method writer rescue nil
|
101
|
-
define_method writer do |value|
|
102
|
-
AttrLazy.define_evaluated_reader(self, name, value)
|
103
|
-
value
|
104
|
-
end
|
105
|
-
end
|
10
|
+
self.class.instance_methods(false).each do |name|
|
11
|
+
if name.to_s =~ %r!\Adefine_!
|
12
|
+
send(name)
|
106
13
|
end
|
107
14
|
end
|
108
15
|
end
|
109
16
|
|
110
|
-
|
111
|
-
module_function
|
112
|
-
|
113
|
-
def executable
|
114
|
-
require 'rbconfig'
|
115
|
-
|
116
|
-
name = File.join(
|
117
|
-
RbConfig::CONFIG["bindir"],
|
118
|
-
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
119
|
-
)
|
17
|
+
attr_reader :gem_name
|
120
18
|
|
121
|
-
|
122
|
-
|
123
|
-
|
19
|
+
def self.attribute(name, &block)
|
20
|
+
var = :"@#{name}"
|
21
|
+
define_method name do
|
22
|
+
if instance_variable_defined?(var)
|
23
|
+
instance_variable_get(var)
|
124
24
|
else
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def run(*args)
|
130
|
-
cmd = [executable, *args]
|
131
|
-
unless system(*cmd)
|
132
|
-
cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
|
133
|
-
raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def run_code_and_capture(code)
|
138
|
-
IO.popen(%{"#{executable}"}, "r+") { |pipe|
|
139
|
-
pipe.print(code)
|
140
|
-
pipe.flush
|
141
|
-
pipe.close_write
|
142
|
-
pipe.read
|
143
|
-
}
|
144
|
-
end
|
145
|
-
|
146
|
-
def run_file_and_capture(file)
|
147
|
-
unless File.file? file
|
148
|
-
raise "file does not exist: `#{file}'"
|
149
|
-
end
|
150
|
-
IO.popen(%{"#{executable}" "#{file}"}, "r") { |pipe|
|
151
|
-
pipe.read
|
152
|
-
}
|
153
|
-
end
|
154
|
-
|
155
|
-
def with_warnings(value = true)
|
156
|
-
previous = $VERBOSE
|
157
|
-
$VERBOSE = value
|
158
|
-
begin
|
159
|
-
yield
|
160
|
-
ensure
|
161
|
-
$VERBOSE = previous
|
25
|
+
instance_variable_set(var, instance_eval(&block))
|
162
26
|
end
|
163
27
|
end
|
164
|
-
|
165
|
-
def no_warnings(&block)
|
166
|
-
with_warnings(nil, &block)
|
167
|
-
end
|
28
|
+
attr_writer name
|
168
29
|
end
|
169
30
|
|
170
|
-
module Util
|
171
|
-
module_function
|
172
|
-
|
173
|
-
def run_ruby_on_each(*files)
|
174
|
-
files.each { |file|
|
175
|
-
Ruby.run("-w", file)
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
def to_camel_case(str)
|
180
|
-
str.split('_').map { |t| t.capitalize }.join
|
181
|
-
end
|
182
|
-
|
183
|
-
def write_file(file)
|
184
|
-
contents = yield
|
185
|
-
File.open(file, "wb") { |out|
|
186
|
-
out.print(contents)
|
187
|
-
}
|
188
|
-
contents
|
189
|
-
end
|
190
|
-
|
191
|
-
def instance_exec2(obj, *args, &block)
|
192
|
-
method_name = ["_", obj.object_id, "_", Thread.current.object_id].join
|
193
|
-
(class << obj ; self ; end).class_eval do
|
194
|
-
define_method method_name, &block
|
195
|
-
begin
|
196
|
-
obj.send(method_name, *args)
|
197
|
-
ensure
|
198
|
-
remove_method method_name
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
include AttrLazy
|
205
|
-
include Util
|
206
|
-
|
207
|
-
def initialize(gem_name)
|
208
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
209
|
-
|
210
|
-
require 'rubygems/package_task'
|
211
|
-
|
212
|
-
@gem_name = gem_name
|
213
|
-
|
214
|
-
yield self
|
215
|
-
|
216
|
-
self.class.instance_methods(false).select { |t|
|
217
|
-
t.to_s =~ %r!\Adefine_!
|
218
|
-
}.sort.each { |method_name|
|
219
|
-
send(method_name)
|
220
|
-
}
|
221
|
-
end
|
222
|
-
|
223
|
-
class << self
|
224
|
-
alias_method :attribute, :attr_lazy_accessor
|
225
|
-
end
|
226
|
-
|
227
|
-
attr_reader :gem_name
|
228
|
-
|
229
31
|
attribute :version_constant_name do
|
230
32
|
"VERSION"
|
231
33
|
end
|
@@ -288,16 +90,10 @@ class Levitate
|
|
288
90
|
"spec.html"
|
289
91
|
end
|
290
92
|
|
291
|
-
|
93
|
+
attribute :spec_output do
|
292
94
|
"#{spec_output_dir}/#{spec_output_file}"
|
293
95
|
end
|
294
96
|
|
295
|
-
[:gem, :tgz].each { |ext|
|
296
|
-
attribute ext do
|
297
|
-
"pkg/#{gem_name}-#{version}.#{ext}"
|
298
|
-
end
|
299
|
-
}
|
300
|
-
|
301
97
|
attribute :rcov_options do
|
302
98
|
# workaround for the default rspec task
|
303
99
|
Dir["*"].select { |f| File.directory? f }.inject(Array.new) { |acc, dir|
|
@@ -309,14 +105,6 @@ class Levitate
|
|
309
105
|
} + ["--text-report"]
|
310
106
|
end
|
311
107
|
|
312
|
-
attribute :readme_file do
|
313
|
-
"README.rdoc"
|
314
|
-
end
|
315
|
-
|
316
|
-
attribute :manifest_file do
|
317
|
-
"MANIFEST"
|
318
|
-
end
|
319
|
-
|
320
108
|
attribute :generated_files do
|
321
109
|
[]
|
322
110
|
end
|
@@ -326,17 +114,9 @@ class Levitate
|
|
326
114
|
end
|
327
115
|
|
328
116
|
attribute :files do
|
329
|
-
if
|
330
|
-
File.read(manifest_file).split("\n")
|
331
|
-
elsif source_control?
|
117
|
+
if source_control?
|
332
118
|
IO.popen("git ls-files") { |pipe| pipe.read.split "\n" }
|
333
|
-
end.to_a +
|
334
|
-
end
|
335
|
-
|
336
|
-
def files_in_require_paths
|
337
|
-
require_paths.inject([]) { |acc, dir|
|
338
|
-
acc + Dir.glob("#{dir}/**/*.rb")
|
339
|
-
}
|
119
|
+
end.to_a + generated_files
|
340
120
|
end
|
341
121
|
|
342
122
|
attribute :rdoc_files do
|
@@ -380,8 +160,6 @@ class Levitate
|
|
380
160
|
attribute :gemspec do
|
381
161
|
Gem::Specification.new do |g|
|
382
162
|
%w[
|
383
|
-
authors
|
384
|
-
email
|
385
163
|
summary
|
386
164
|
version
|
387
165
|
description
|
@@ -390,7 +168,6 @@ class Levitate
|
|
390
168
|
extra_rdoc_files
|
391
169
|
require_paths
|
392
170
|
required_ruby_version
|
393
|
-
extensions
|
394
171
|
].each do |param|
|
395
172
|
t = send(param) and g.send("#{param}=", t)
|
396
173
|
end
|
@@ -403,6 +180,8 @@ class Levitate
|
|
403
180
|
development_dependencies.each { |dep|
|
404
181
|
g.add_development_dependency(*dep)
|
405
182
|
}
|
183
|
+
g.authors = developers.map { |d| d[0] }
|
184
|
+
g.email = developers.map { |d| d[1] }
|
406
185
|
extra_gemspec.call(g)
|
407
186
|
end
|
408
187
|
end
|
@@ -467,14 +246,6 @@ class Levitate
|
|
467
246
|
nil
|
468
247
|
end
|
469
248
|
|
470
|
-
def authors
|
471
|
-
developers.map { |d| d[0] }
|
472
|
-
end
|
473
|
-
|
474
|
-
def email
|
475
|
-
developers.map { |d| d[1] }
|
476
|
-
end
|
477
|
-
|
478
249
|
attribute :dependencies do
|
479
250
|
[]
|
480
251
|
end
|
@@ -487,17 +258,18 @@ class Levitate
|
|
487
258
|
[]
|
488
259
|
end
|
489
260
|
|
490
|
-
attribute :
|
491
|
-
["
|
261
|
+
attribute :remote_levitate do
|
262
|
+
url = ENV["LEVITATE"] ||
|
263
|
+
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
264
|
+
IO.popen("curl -s #{url}") { |f| f.read }
|
492
265
|
end
|
493
|
-
|
494
|
-
attribute :
|
495
|
-
|
496
|
-
require 'rbconfig'
|
497
|
-
"lib/" + gem_name + "." + RbConfig::CONFIG["DLEXT"]
|
498
|
-
end
|
266
|
+
|
267
|
+
attribute :local_levitate do
|
268
|
+
File.open(__FILE__, "rb") { |f| f.read }
|
499
269
|
end
|
500
270
|
|
271
|
+
#### tasks
|
272
|
+
|
501
273
|
def define_clean
|
502
274
|
require 'rake/clean'
|
503
275
|
task :clean do
|
@@ -507,10 +279,8 @@ class Levitate
|
|
507
279
|
|
508
280
|
def define_package
|
509
281
|
if source_control?
|
510
|
-
|
511
|
-
|
512
|
-
end
|
513
|
-
CLEAN.add manifest_file
|
282
|
+
require 'rubygems/package_task'
|
283
|
+
|
514
284
|
task :package => :clean
|
515
285
|
Gem::PackageTask.new(gemspec).define
|
516
286
|
end
|
@@ -518,7 +288,7 @@ class Levitate
|
|
518
288
|
|
519
289
|
def define_spec
|
520
290
|
unless spec_files.empty?
|
521
|
-
|
291
|
+
no_warnings {
|
522
292
|
require 'spec/rake/spectask'
|
523
293
|
}
|
524
294
|
|
@@ -550,7 +320,7 @@ class Levitate
|
|
550
320
|
|
551
321
|
desc "run specs individually"
|
552
322
|
task :spec_deps do
|
553
|
-
|
323
|
+
run_each_file(*spec_files)
|
554
324
|
end
|
555
325
|
|
556
326
|
task :prerelease => [:spec, :spec_deps]
|
@@ -606,7 +376,7 @@ class Levitate
|
|
606
376
|
|
607
377
|
desc "run tests individually"
|
608
378
|
task :test_deps do
|
609
|
-
|
379
|
+
run_each_file(*test_files)
|
610
380
|
end
|
611
381
|
|
612
382
|
task :prerelease => [:test, :test_deps]
|
@@ -619,7 +389,7 @@ class Levitate
|
|
619
389
|
def define_doc
|
620
390
|
desc "run rdoc"
|
621
391
|
task :doc => :clean_doc do
|
622
|
-
|
392
|
+
gem 'rdoc' rescue nil
|
623
393
|
require 'rdoc/rdoc'
|
624
394
|
args = (
|
625
395
|
gemspec.rdoc_options +
|
@@ -648,6 +418,7 @@ class Levitate
|
|
648
418
|
if source_control?
|
649
419
|
desc "publish docs"
|
650
420
|
task :publish => [:clean, :check_directory, :doc] do
|
421
|
+
current_branch = `git branch`[/^\* (\S+)$/, 1] or raise "??? branch"
|
651
422
|
if rubyforge_info
|
652
423
|
user, project = rubyforge_info
|
653
424
|
Dir.chdir(doc_dir) do
|
@@ -666,6 +437,7 @@ class Levitate
|
|
666
437
|
FileUtils.rmdir "doc"
|
667
438
|
git "add", "."
|
668
439
|
git "commit", "-m", "generated by rdoc"
|
440
|
+
git "checkout", current_branch
|
669
441
|
git "push", "-f", "origin", "gh-pages"
|
670
442
|
end
|
671
443
|
end
|
@@ -681,22 +453,6 @@ class Levitate
|
|
681
453
|
task :uninstall do
|
682
454
|
Installer.new.uninstall
|
683
455
|
end
|
684
|
-
|
685
|
-
if so_file
|
686
|
-
dest = File.join(RbConfig::CONFIG["sitearchdir"], File.basename(so_file))
|
687
|
-
|
688
|
-
task :install => so_file do
|
689
|
-
puts "install #{so_file} --> #{dest}"
|
690
|
-
FileUtils.install(so_file, dest)
|
691
|
-
end
|
692
|
-
|
693
|
-
task :uninstall do
|
694
|
-
if File.file?(dest)
|
695
|
-
puts "rm #{dest}"
|
696
|
-
FileUtils.rm(dest)
|
697
|
-
end
|
698
|
-
end
|
699
|
-
end
|
700
456
|
end
|
701
457
|
|
702
458
|
def define_check_directory
|
@@ -710,7 +466,10 @@ class Levitate
|
|
710
466
|
def define_ping
|
711
467
|
task :ping do
|
712
468
|
require 'rbconfig'
|
713
|
-
|
469
|
+
[
|
470
|
+
"github.com",
|
471
|
+
("rubyforge.org" if rubyforge_info),
|
472
|
+
].compact.each do |server|
|
714
473
|
cmd = "ping " + (
|
715
474
|
if RbConfig::CONFIG["host"] =~ %r!darwin!
|
716
475
|
"-c2 #{server}"
|
@@ -721,23 +480,26 @@ class Levitate
|
|
721
480
|
unless `#{cmd}` =~ %r!0% packet loss!
|
722
481
|
raise "No ping for #{server}"
|
723
482
|
end
|
724
|
-
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
def define_check_levitate
|
488
|
+
task :check_levitate do
|
489
|
+
unless local_levitate == remote_levitate
|
490
|
+
raise "levitate is out of date"
|
491
|
+
end
|
725
492
|
end
|
726
493
|
end
|
727
494
|
|
728
495
|
def define_update_levitate
|
729
|
-
url = ENV["LEVITATE"] ||
|
730
|
-
"https://github.com/quix/levitate/raw/master/levitate.rb"
|
731
496
|
task :update_levitate do
|
732
|
-
if
|
733
|
-
|
734
|
-
puts "Already up-to-date."
|
735
|
-
else
|
736
|
-
git "commit", __FILE__, "-m", "updated levitate"
|
737
|
-
puts "Updated levitate."
|
738
|
-
end
|
497
|
+
if local_levitate == remote_levitate
|
498
|
+
puts "Already up-to-date."
|
739
499
|
else
|
740
|
-
|
500
|
+
File.open(__FILE__, "w") { |f| f.print(remote_levitate) }
|
501
|
+
git "commit", __FILE__, "-m", "update levitate"
|
502
|
+
puts "Updated levitate."
|
741
503
|
end
|
742
504
|
end
|
743
505
|
end
|
@@ -762,30 +524,22 @@ class Levitate
|
|
762
524
|
end
|
763
525
|
end
|
764
526
|
|
765
|
-
def last_release
|
766
|
-
`git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
|
767
|
-
end
|
768
|
-
|
769
|
-
def git(*args)
|
770
|
-
sh "git", *args
|
771
|
-
end
|
772
|
-
|
773
|
-
def create_manifest
|
774
|
-
write_file(manifest_file) {
|
775
|
-
files.sort.join("\n")
|
776
|
-
}
|
777
|
-
end
|
778
|
-
|
779
527
|
def define_release
|
780
|
-
task :prerelease => [
|
528
|
+
task :prerelease => [
|
529
|
+
:clean,
|
530
|
+
:check_directory,
|
531
|
+
:check_levitate,
|
532
|
+
:ping,
|
533
|
+
history_file
|
534
|
+
]
|
781
535
|
|
782
536
|
task :finish_release do
|
783
537
|
git "tag", "#{gem_name}-" + version.to_s
|
784
538
|
git "push", "--tags", "origin", "master"
|
785
|
-
sh "gem", "push", gem
|
539
|
+
sh "gem", "push", "pkg/#{gem_name}-#{version}.gem"
|
786
540
|
end
|
787
541
|
|
788
|
-
task :release => [:prerelease, :package, :finish_release]
|
542
|
+
task :release => [:prerelease, :package, :finish_release, :publish]
|
789
543
|
end
|
790
544
|
|
791
545
|
def define_debug_gem
|
@@ -794,35 +548,22 @@ class Levitate
|
|
794
548
|
end
|
795
549
|
end
|
796
550
|
|
797
|
-
|
798
|
-
if source_control? or (so_file and !File.file?(so_file))
|
799
|
-
require 'rbconfig'
|
800
|
-
require 'rake/extensiontask'
|
801
|
-
|
802
|
-
Rake::ExtensionTask.new gem_name, gemspec do |ext|
|
803
|
-
ext.cross_compile = true
|
804
|
-
ext.cross_platform = 'i386-mswin32'
|
805
|
-
ext.cross_compiling do |gemspec|
|
806
|
-
gemspec.post_install_message =
|
807
|
-
"U got dat binary versionation of this gemination!"
|
808
|
-
end
|
809
|
-
end
|
551
|
+
#### helpers
|
810
552
|
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
553
|
+
def files_in_require_paths
|
554
|
+
require_paths.inject([]) { |acc, dir|
|
555
|
+
acc + Dir.glob("#{dir}/**/*.rb")
|
556
|
+
}
|
557
|
+
end
|
815
558
|
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
Rake.application.top_level
|
820
|
-
end
|
559
|
+
def last_release
|
560
|
+
`git tag`.lines.select { |t| t.index(gem_name) == 0 }.last.chomp
|
561
|
+
end
|
821
562
|
|
822
|
-
|
823
|
-
|
563
|
+
def git(*args)
|
564
|
+
sh "git", *args
|
824
565
|
end
|
825
|
-
|
566
|
+
|
826
567
|
def open_browser(*files)
|
827
568
|
sh(*([browser].flatten + files))
|
828
569
|
end
|
@@ -831,7 +572,7 @@ class Levitate
|
|
831
572
|
task_names.each { |task_name|
|
832
573
|
Rake::Task[task_name].actions.map! { |action|
|
833
574
|
lambda { |*args|
|
834
|
-
|
575
|
+
no_warnings {
|
835
576
|
action.call(*args)
|
836
577
|
}
|
837
578
|
}
|
@@ -847,10 +588,110 @@ class Levitate
|
|
847
588
|
File.directory? ".git"
|
848
589
|
end
|
849
590
|
|
850
|
-
|
851
|
-
|
591
|
+
#### utility for instance and class
|
592
|
+
|
593
|
+
module Util
|
594
|
+
def ruby_bin
|
595
|
+
require 'rbconfig'
|
596
|
+
|
597
|
+
name = File.join(
|
598
|
+
RbConfig::CONFIG["bindir"],
|
599
|
+
RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
600
|
+
)
|
601
|
+
|
602
|
+
if RbConfig::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
|
603
|
+
File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
|
604
|
+
name + RbConfig::CONFIG["EXEEXT"]
|
605
|
+
else
|
606
|
+
name
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def ruby_command
|
611
|
+
[ruby_bin] + Levitate.ruby_opts.to_a
|
612
|
+
end
|
613
|
+
|
614
|
+
def ruby_command_string
|
615
|
+
ruby_command.join(" ")
|
616
|
+
end
|
617
|
+
|
618
|
+
def run(*args)
|
619
|
+
cmd = ruby_command + args
|
620
|
+
unless system(*cmd)
|
621
|
+
cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
|
622
|
+
raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
def run_each_file(*files)
|
627
|
+
files.each { |file|
|
628
|
+
run("-w", file)
|
629
|
+
}
|
630
|
+
end
|
852
631
|
|
853
|
-
|
632
|
+
def run_code_and_capture(code)
|
633
|
+
IO.popen(ruby_command_string, "r+") { |pipe|
|
634
|
+
pipe.print(code)
|
635
|
+
pipe.flush
|
636
|
+
pipe.close_write
|
637
|
+
pipe.read
|
638
|
+
}
|
639
|
+
end
|
640
|
+
|
641
|
+
def run_file_and_capture(file)
|
642
|
+
unless File.file? file
|
643
|
+
raise "file does not exist: `#{file}'"
|
644
|
+
end
|
645
|
+
IO.popen(ruby_command_string + " " + file, "r") { |pipe|
|
646
|
+
pipe.read
|
647
|
+
}
|
648
|
+
end
|
649
|
+
|
650
|
+
def with_warnings(value = true)
|
651
|
+
previous = $VERBOSE
|
652
|
+
$VERBOSE = value
|
653
|
+
begin
|
654
|
+
yield
|
655
|
+
ensure
|
656
|
+
$VERBOSE = previous
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
def no_warnings(&block)
|
661
|
+
with_warnings(nil, &block)
|
662
|
+
end
|
663
|
+
|
664
|
+
def to_camel_case(str)
|
665
|
+
str.split('_').map { |t| t.capitalize }.join
|
666
|
+
end
|
667
|
+
|
668
|
+
def write_file(file)
|
669
|
+
contents = yield
|
670
|
+
File.open(file, "wb") { |out|
|
671
|
+
out.print(contents)
|
672
|
+
}
|
673
|
+
contents
|
674
|
+
end
|
675
|
+
|
676
|
+
def instance_exec2(obj, *args, &block)
|
677
|
+
method_name = ["_", obj.object_id, "_", Thread.current.object_id].join
|
678
|
+
(class << obj ; self ; end).class_eval do
|
679
|
+
define_method method_name, &block
|
680
|
+
begin
|
681
|
+
obj.send(method_name, *args)
|
682
|
+
ensure
|
683
|
+
remove_method method_name
|
684
|
+
end
|
685
|
+
end
|
686
|
+
end
|
687
|
+
end
|
688
|
+
extend Util
|
689
|
+
include Util
|
690
|
+
|
691
|
+
#### public helpers for testing
|
692
|
+
|
693
|
+
class << self
|
694
|
+
# From 'minitest' by Ryan Davis.
|
854
695
|
def capture_io
|
855
696
|
require 'stringio'
|
856
697
|
|
@@ -885,7 +726,7 @@ class Levitate
|
|
885
726
|
Tempfile.open("run-rdoc-code") { |temp_file|
|
886
727
|
temp_file.print(final_code)
|
887
728
|
temp_file.close
|
888
|
-
actual =
|
729
|
+
actual = run_file_and_capture(temp_file.path).chomp
|
889
730
|
}
|
890
731
|
|
891
732
|
instance_exec2(instance, expected, actual, index, &block)
|
@@ -908,6 +749,7 @@ class Levitate
|
|
908
749
|
raise "parse error"
|
909
750
|
end
|
910
751
|
)
|
752
|
+
code.gsub!(/^\s*%.*$/, "") # ignore shell command examples
|
911
753
|
run_doc_code(code, expected, index, instance, &block)
|
912
754
|
index += 1
|
913
755
|
}
|
@@ -954,5 +796,57 @@ class Levitate
|
|
954
796
|
end
|
955
797
|
Object.const_set("Test#{file}".gsub(".", ""), klass)
|
956
798
|
end
|
799
|
+
|
800
|
+
def ruby_opts
|
801
|
+
@ruby_opts ||= []
|
802
|
+
end
|
803
|
+
attr_writer :ruby_opts
|
804
|
+
end
|
805
|
+
|
806
|
+
#### raw install, bypass gems
|
807
|
+
|
808
|
+
class Installer
|
809
|
+
def initialize
|
810
|
+
require 'fileutils'
|
811
|
+
require 'rbconfig'
|
812
|
+
require 'find'
|
813
|
+
|
814
|
+
@fu = FileUtils::Verbose
|
815
|
+
@spec = []
|
816
|
+
|
817
|
+
rb_root = RbConfig::CONFIG["sitelibdir"]
|
818
|
+
|
819
|
+
Find.find "lib" do |source|
|
820
|
+
next if source == "lib"
|
821
|
+
next unless File.directory?(source) || File.extname(source) == ".rb"
|
822
|
+
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
823
|
+
@spec << [source, dest]
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
def install
|
828
|
+
@spec.each do |source, dest|
|
829
|
+
if File.directory?(source)
|
830
|
+
@fu.mkdir(dest) unless File.directory?(dest)
|
831
|
+
else
|
832
|
+
@fu.install(source, dest)
|
833
|
+
end
|
834
|
+
end
|
835
|
+
end
|
836
|
+
|
837
|
+
def uninstall
|
838
|
+
@spec.reverse.each do |source, dest|
|
839
|
+
if File.directory?(source)
|
840
|
+
@fu.rmdir(dest) if File.directory?(dest)
|
841
|
+
else
|
842
|
+
@fu.rm(dest) if File.file?(dest)
|
843
|
+
end
|
844
|
+
end
|
845
|
+
end
|
957
846
|
end
|
958
847
|
end
|
848
|
+
|
849
|
+
lambda do
|
850
|
+
config = File.join(File.dirname(__FILE__), "levitate_config.rb")
|
851
|
+
require config if File.file? config
|
852
|
+
end.call
|