root/version_0/Rakefile

Revision 639, 11.4 kB (checked in by blackhedd, 11 months ago)

tests

  • Property svn:keywords set to Id
Line 
1 #! /usr/bin/env rake
2 #--
3 # Ruby/EventMachine
4 #   http://rubyeventmachine.com
5 #   Copyright (C) 2006-07 by Francis Cianfrocca
6 #
7 #   This program is copyrighted free software. You may use it under
8 #   the terms of either the GPL or Ruby's License. See the file
9 #   COPYING in the EventMachine distribution for full licensing
10 #   information.
11 #
12 # $Id$
13 #++
14
15
16 require 'rake/gempackagetask'
17 require 'rake/clean'
18
19
20 $can_minitar = false
21 begin
22   require 'archive/tar/minitar'
23   require 'zlib'
24   $can_minitar  = true
25 rescue LoadError
26 end
27
28 $: << "lib"
29 require 'eventmachine_version'
30 $version = EventMachine::VERSION
31 $distdir  = "eventmachine-#$version"
32 $tardist  = "#$distdir.tar.gz"
33 $name = "eventmachine"
34
35
36 # The tasks and external gemspecs we used to generate binary gems are now
37 # obsolete. Use Patrick Hurley's gembuilder to build binary gems for any
38 # desired platform.
39 # To build a binary gem on Win32, ensure that the include and lib paths
40 # both contain the proper references to OPENSSL. Use the static version
41 # of the libraries, not the dynamic, otherwise we expose the user to a
42 # runtime dependency.
43
44 =begin
45 # To build a binary gem for win32, first build rubyeventmachine.so
46 # using VC6 outside of the build tree (the normal way: ruby extconf.rb,
47 # and then nmake). Then copy rubyeventmachine.so into the lib directory,
48 # and run rake gemwin32.
49 specwin32 = eval(File.read("eventmachine-win32.gemspec"))
50 specwin32.version = $version
51 desc "Build the RubyGem for EventMachine-win32"
52 task :gemwin32 => ["pkg/eventmachine-win32-#{$version}.gem"]
53 Rake::GemPackageTask.new(specwin32) do |g|
54   if $can_minitar
55     g.need_tar    = false
56     g.need_zip    = false
57   end
58   g.package_dir = "pkg"
59 end
60
61
62 # To build a binary gem for unix platforms, first build rubyeventmachine.so
63 # using gcc outside of the build tree (the normal way: ruby extconf.rb,
64 # and then make). Then copy rubyeventmachine.so into the lib directory,
65 # and run rake gembinary.
66 specbinary = eval(File.read("eventmachine-binary.gemspec"))
67 specbinary.version = $version
68 desc "Build the RubyGem for EventMachine-Binary"
69 task :gembinary => ["pkg/eventmachine-binary-#{$version}.gem"]
70 Rake::GemPackageTask.new(specbinary) do |g|
71   if $can_minitar
72     g.need_tar    = false
73     g.need_zip    = false
74   end
75   g.package_dir = "pkg"
76 end
77
78
79 spec = eval(File.read("eventmachine.gemspec"))
80 =end
81
82 spec = Gem::Specification.new do |s|
83         s.name              = "eventmachine"
84         s.summary           = "Ruby/EventMachine library"
85         s.platform          = Gem::Platform::RUBY
86
87         s.has_rdoc          = true
88         s.rdoc_options      = %w(--title EventMachine --main README --line-numbers)
89         s.extra_rdoc_files = ["README",
90                                 "RELEASE_NOTES",
91                                 "COPYING",
92                                 "EPOLL",
93                                 "GNU",
94                                 "LEGAL",
95                                 "TODO",
96                                 "KEYBOARD",
97                                 "LIGHTWEIGHT_CONCURRENCY",
98                                 "PURE_RUBY",
99                                 "SMTP",
100                                 "SPAWNED_PROCESSES",
101                                 "DEFERRABLES"
102                                 ]
103
104         s.files             = FileList["{bin,tests,lib,ext}/**/*"].exclude("rdoc").to_a
105
106         s.require_paths     = ["lib"]
107
108         s.test_file         = "tests/testem.rb"
109         s.extensions        = "ext/extconf.rb"
110
111         s.author            = "Francis Cianfrocca"
112         s.email             = "garbagecat10@gmail.com"
113         s.rubyforge_project = %q(eventmachine)
114         s.homepage          = "http://rubyeventmachine.com"
115
116
117         description = []
118         File.open("README") do |file|
119                 file.each do |line|
120                         line.chomp!
121                         break if line.empty?
122                         description << "#{line.gsub(/\[\d\]/, '')}"
123                 end
124         end
125         s.description = description[1..-1].join(" ")
126 end
127
128 spec.version = $version
129 desc "Build the EventMachine RubyGem"
130 task :gem => ["pkg/eventmachine-#{$version}.gem"]
131 Rake::GemPackageTask.new(spec) do |g|
132   if $can_minitar
133     g.need_tar    = false
134     g.need_zip    = false
135   end
136   g.package_dir = "pkg"
137 end
138
139
140 jspec = Gem::Specification.new do |s|
141         s.name              = "eventmachine-java"
142         s.summary           = "Ruby/EventMachine library"
143         s.platform          = Gem::Platform::RUBY
144
145         s.has_rdoc          = true
146         s.rdoc_options      = %w(--title EventMachine --main README --line-numbers)
147         s.extra_rdoc_files = ["README", "RELEASE_NOTES", "COPYING", "GNU", "LEGAL", "TODO"]
148
149         s.files             = FileList["{lib}/**/*"].exclude("rdoc").to_a
150
151         s.require_paths     = ["lib"]
152
153         s.author            = "Francis Cianfrocca"
154         s.email             = "garbagecat10@gmail.com"
155         s.rubyforge_project = %q(eventmachine)
156         s.homepage          = "http://rubyeventmachine.com"
157
158
159         description = []
160         File.open("README") do |file|
161                 file.each do |line|
162                         line.chomp!
163                         break if line.empty?
164                         description << "#{line.gsub(/\[\d\]/, '')}"
165                 end
166         end
167         s.description = description[1..-1].join(" ")
168 end
169
170
171 jspec.version = $version
172 desc "Build the EventMachine RubyGem for JRuby"
173 task :jgem => ["pkg/eventmachine-java-#{$version}.gem"]
174 Rake::GemPackageTask.new(jspec) do |g|
175         $>.puts "-----------------"
176         $>.puts "Before executing the :jgem task, be sure to run :clean, and"
177         $>.puts "then make sure an up-to-date em_reactor.jar is present in the"
178         $>.puts "lib directory."
179         $>.puts "-----------------"
180   if $can_minitar
181     g.need_tar    = false
182     g.need_zip    = false
183   end
184   g.package_dir = "pkg"
185 end
186
187
188 desc "Clean extension and JAR builds out of the lib directory"
189 task :clean do |t|
190         files = %W(lib/*.so lib/*.jar)
191         files = FileList[files.map { |file| File.join(".", file) }].to_a
192         files.each {|f|
193                 $>.puts "unlinking file: #{f}"
194                 File.unlink f
195         }
196 end
197
198
199 if $can_minitar
200   desc "Build #$name .tar.gz distribution."
201   task :tar => [ $tardist ]
202   file $tardist => [ ] do |t|
203     current = File.basename(Dir.pwd)
204     Dir.chdir("..") do
205       begin
206         files = %W(ext/**/*.rb ext/**/*.cpp ext/**/*.h bin/**/* lib/**/* tests/**/* README COPYING
207                  GNU LEGAL RELEASE_NOTES INSTALL EPOLL TODO KEYBOARD
208                 LIGHTWEIGHT_CONCURRENCY PURE_RUBY SMTP SPAWNED_PROCESSES DEFERRABLES setup.rb )
209         files = FileList[files.map { |file| File.join(current, file) }].to_a
210         files = files.select {|f| f !~ /lib\/.*[\.](so|jar)\Z/i } # remove any so or jar files in the lib directory
211         files.map! do |dd|
212           ddnew = dd.gsub(/^#{current}/, $distdir)
213           mtime = $release_date || File.stat(dd).mtime
214           if File.directory?(dd)
215             { :name => ddnew, :mode => 0755, :dir => true, :mtime => mtime }
216           else
217             if dd =~ %r{bin/}
218               mode = 0755
219             else
220               mode = 0644
221             end
222             data = File.open(dd, "rb") { |ff| ff.read }
223             { :name => ddnew, :mode => mode, :data => data, :size =>
224               data.size, :mtime => mtime }
225           end
226         end
227
228         ff = File.open(t.name.gsub(%r{^\.\./}o, ''), "wb")
229         gz = Zlib::GzipWriter.new(ff)
230         tw = Archive::Tar::Minitar::Writer.new(gz)
231
232         files.each do |entry|
233           if entry[:dir]
234             tw.mkdir(entry[:name], entry)
235           else
236             tw.add_file_simple(entry[:name], entry) { |os| os.write(entry[:data]) }
237           end
238         end
239       ensure
240         tw.close if tw
241         gz.finish if gz
242         ff.close if ff
243       end
244     end
245   end
246   task $tardist => [ ]
247 end
248
249
250
251
252
253 # This is used by several rake tasks, that parameterize the
254 # behavior so we can use the same tests to test both the
255 # extension and non-extension versions.
256 def run_tests t, libr, test_filename_filter="test_*.rb"
257   require 'test/unit/testsuite'
258   require 'test/unit/ui/console/testrunner'
259
260   runner = Test::Unit::UI::Console::TestRunner
261
262   $eventmachine_library = libr
263   $LOAD_PATH.unshift('tests')
264   $stderr.puts "Checking for test cases:" #if t.verbose
265
266   if test_filename_filter.is_a?(Array)
267     test_filename_filter.each {|testcase|
268       $stderr.puts "\t#{testcase}"
269       load "tests/#{testcase}"
270     }
271   else
272     Dir["tests/#{test_filename_filter}"].each do |testcase|
273       $stderr.puts "\t#{testcase}" #if t.verbose
274       load testcase
275     end
276   end
277
278   suite = Test::Unit::TestSuite.new($name)
279
280   ObjectSpace.each_object(Class) do |testcase|
281     suite << testcase.suite if testcase < Test::Unit::TestCase
282   end
283
284   runner.run(suite)
285 end
286
287 desc "Run tests for #$name."
288 task :test do |t|
289   run_tests t, nil
290 end
291
292 desc "Run tests for #$name."
293 task :test_partial do |t|
294   run_tests t, :extension, [
295     "test_basic.rb",
296     "test_epoll.rb",
297     "test_errors.rb",
298     "test_eventables.rb",
299     "test_exc.rb",
300     "test_futures.rb",
301     "test_hc.rb",
302     "test_httpclient2.rb",
303     "test_httpclient.rb",
304     "test_kb.rb",
305     #"test_ltp2.rb",
306     "test_ltp.rb",
307     "test_next_tick.rb",
308     "test_processes.rb",
309     "test_pure.rb",
310     "test_running.rb",
311     "test_sasl.rb",
312     #"test_send_file.rb",
313     "test_servers.rb",
314     "test_smtpclient.rb",
315     "test_smtpserver.rb",
316     "test_spawn.rb",
317     "test_timers.rb",
318     "test_ud.rb",
319   ]
320 end
321
322
323 desc "Run pure-ruby tests for #$name."
324 task :testpr do |t|
325   run_tests t, :pure_ruby
326 end
327
328 desc "Run extension tests for #$name."
329 task :testext do |t|
330   run_tests t, :extension
331 end
332
333 desc "PROVISIONAL: run tests for user-defined events"
334 task :test_ud do |t|
335   run_tests t, :extension, "test_ud.rb"
336 end
337
338 desc "PROVISIONAL: run tests for line/text protocol handler"
339 task :test_ltp do |t|
340   run_tests t, :extension, "test_ltp*.rb"
341 end
342
343 desc "PROVISIONAL: run tests for header/content protocol handler"
344 task :test_hc do |t|
345   run_tests t, :extension, "test_hc.rb"
346 end
347
348 desc "PROVISIONAL: run tests for exceptions"
349 task :test_exc do |t|
350   run_tests t, :extension, "test_exc.rb"
351 end
352
353 desc "Test protocol handlers"
354 task :test_protocols => [ :test_hc, :test_ltp ]
355
356
357 desc "Test HTTP client"
358 task :test_httpclient do |t|
359   run_tests t, :extension, "test_httpclient.rb"
360 end
361
362 desc "Test HTTP client2"
363 task :test_httpclient2 do |t|
364   run_tests t, :extension, "test_httpclient2.rb"
365 end
366
367 desc "Test futures"
368 task :test_futures do |t|
369   run_tests t, :extension, "test_future*.rb"
370 end
371
372 desc "Test Timers"
373 task :test_timers do |t|
374   run_tests t, :extension, "test_timer*.rb"
375 end
376
377 desc "Test Next Tick"
378 task :test_next_tick do |t|
379   run_tests t, :extension, "test_next_tick*.rb"
380 end
381
382 desc "Test Epoll"
383 task :test_epoll do |t|
384   run_tests t, :extension, "test_epoll*.rb"
385 end
386
387 desc "Test Servers"
388 task :test_servers do |t|
389   run_tests t, :extension, "test_servers*.rb"
390 end
391
392 desc "Test Basic"
393 task :test_basic do |t|
394   run_tests t, :extension, "test_basic*.rb"
395 end
396
397 desc "Test Send File"
398 task :test_send_file do |t|
399   run_tests t, :extension, "test_send_file*.rb"
400 end
401
402 desc "Test Running"
403 task :test_running do |t|
404   run_tests t, :extension, "test_running*.rb"
405 end
406
407 desc "Test Keyboard Events"
408 task :test_keyboard do |t|
409   run_tests t, :extension, "test_kb*.rb"
410 end
411
412 desc "Test Spawn"
413 task :test_spawn do |t|
414   run_tests t, :spawn, "test_spawn*.rb"
415 end
416
417 desc "Test SMTP"
418 task :test_smtp do |t|
419   run_tests t, :extension, "test_smtp*.rb"
420 end
421
422 desc "Test Errors"
423 task :test_errors do |t|
424   run_tests t, :extension, "test_errors*.rb"
425 end
426
427 desc "Test Pure Ruby"
428 task :test_pure do |t|
429   run_tests t, :extension, "test_pure*.rb"
430 end
431
432 desc "Test Processes"
433 task :test_processes do |t|
434   run_tests t, :extension, "test_process*.rb"
435 end
436
437 desc "Test SASL"
438 task :test_sasl do |t|
439   run_tests t, :extension, "test_sasl*.rb"
440 end
441
442
443 desc "Build everything"
444 task :default => [ :gem ]
445
446
447
448 # This task is useful for development.
449 desc "Compile the extension."
450 task :extension do |t|
451         Dir.mkdir "nonversioned" unless File.directory?("nonversioned")
452         Dir.chdir "nonversioned"
453         system "ruby ../ext/extconf.rb"
454         system "make clean"
455         system "make"
456         system "cp *.so ../lib" or system "copy *.so ../lib"
457         Dir.chdir ".."
458 end
459
460
461 # This task creates the JRuby JAR file and leaves it in the lib directory.
462 # This step is required before executing the jgem task.
463 desc "Compile the JAR"
464 task :jar do |t|
465         p "JAR?"
466 end
467
Note: See TracBrowser for help on using the browser.