Improved documentation for `Rack::Builder`.
[rack.git] / Rakefile
blob9691af8272aff9ed50ac553ded50a6a790cc25ac
1 # frozen_string_literal: true
3 require "bundler/gem_tasks"
4 require "rake/testtask"
6 desc "Run all the tests"
7 task default: :test
9 desc "Install gem dependencies"
10 task :deps do
11   require 'rubygems'
12   spec = Gem::Specification.load('rack.gemspec')
13   spec.dependencies.each do |dep|
14     reqs = dep.requirements_list
15     reqs = (["-v"] * reqs.size).zip(reqs).flatten
16     # Use system over sh, because we want to ignore errors!
17     system Gem.ruby, "-S", "gem", "install", '--conservative', dep.name, *reqs
18   end
19 end
21 desc "Make an archive as .tar.gz"
22 task dist: %w[chmod changelog spec rdoc] do
23   sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
24   sh "pax -waf #{release}.tar -s ':^:#{release}/:' SPEC.rdoc ChangeLog doc rack.gemspec"
25   sh "gzip -f -9 #{release}.tar"
26 end
28 desc "Make an official release"
29 task :officialrelease do
30   puts "Official build for #{release}..."
31   sh "rm -rf stage"
32   sh "git clone --shared . stage"
33   sh "cd stage && rake officialrelease_really"
34   sh "mv stage/#{release}.tar.gz stage/#{release}.gem ."
35 end
37 task officialrelease_really: %w[spec dist gem] do
38   sh "shasum #{release}.tar.gz #{release}.gem"
39 end
41 def release
42   "rack-" + File.read('lib/rack/version.rb')[/RELEASE += +([\"\'])([\d][\w\.]+)\1/, 2]
43 end
45 desc "Make binaries executable"
46 task :chmod do
47   Dir["bin/*"].each { |binary| File.chmod(0755, binary) }
48   Dir["test/cgi/test*"].each { |binary| File.chmod(0755, binary) }
49 end
51 desc "Generate a ChangeLog"
52 task changelog: "ChangeLog"
54 file '.git/index'
55 file "ChangeLog" => '.git/index' do
56   File.open("ChangeLog", "w") { |out|
57     log = `git log -z`
58     log.force_encoding(Encoding::BINARY)
59     log.split("\0").map { |chunk|
60       author = chunk[/Author: (.*)/, 1].strip
61       date = chunk[/Date: (.*)/, 1].strip
62       desc, detail = $'.strip.split("\n", 2)
63       detail ||= ""
64       detail = detail.gsub(/.*darcs-hash:.*/, '')
65       detail.rstrip!
66       out.puts "#{date}  #{author}"
67       out.puts "  * #{desc.strip}"
68       out.puts detail  unless detail.empty?
69       out.puts
70     }
71   }
72 end
74 desc "Generate Rack Specification"
75 task spec: "SPEC.rdoc"
77 file 'lib/rack/lint.rb'
78 file "SPEC.rdoc" => 'lib/rack/lint.rb' do
79   File.open("SPEC.rdoc", "wb") { |file|
80     IO.foreach("lib/rack/lint.rb") { |line|
81       if line =~ /^\s*## ?(.*)/
82         file.puts $1
83       end
84     }
85   }
86 end
88 Rake::TestTask.new("test:regular") do |t|
89   t.libs << "test"
90   t.test_files = FileList["test/**/*_test.rb", "test/**/spec_*.rb", "test/gemloader.rb"]
91   t.warning = false
92   t.verbose = true
93 end
95 desc "Run tests with coverage"
96 task "test_cov" do
97   ENV['COVERAGE'] = '1'
98   Rake::Task['test:regular'].invoke
99 end
101 desc "Run separate tests for each test file, to test directly requiring components"
102 task "test:separate" do
103   fails = []
104   FileList["test/**/spec_*.rb"].each do |file|
105     puts "#{FileUtils::RUBY} -w #{file}"
106     fails << file unless system({'SEPARATE'=>'1'},  FileUtils::RUBY, '-w', file)
107   end
108   if fails.empty?
109     puts 'All test files passed'
110   else
111     puts "Failures in the following test files:"
112     puts fails
113     raise "At least one separate test failed"
114   end
117 desc "Run all the fast + platform agnostic tests"
118 task test: %w[spec test:regular test:separate]
120 desc "Run all the tests we run on CI"
121 task ci: :test
123 task gem: :spec do
124   sh "gem build rack.gemspec"
127 task doc: :rdoc
129 desc "Generate RDoc documentation"
130 task rdoc: %w[changelog spec] do
131   sh(*%w{rdoc --line-numbers --main README.rdoc
132               --title 'Rack\ Documentation' --charset utf-8 -U -o doc} +
133               %w{README.rdoc KNOWN-ISSUES SPEC.rdoc ChangeLog} +
134               `git ls-files lib/\*\*/\*.rb`.strip.split)
135   cp "contrib/rdoc.css", "doc/rdoc.css"
138 def clone_and_test(url, name, command)
139   path = "external/#{name}"
140   FileUtils.rm_rf path
141   FileUtils.mkdir_p path
143   sh("git clone #{url} #{path}")
145   # I tried using `bundle config --local local.async ../` but it simply doesn't work.
146   File.open("#{path}/Gemfile", "a") do |file|
147     file.puts("gem 'rack', path: '../../'")
148     file.puts("gem 'rack-session', github: 'rack/rack-session'") if name == 'rack-attack'
149   end
151   sh("cd #{path} && bundle install && #{command}")
154 task :external do
155   # In order not to interfere with external tests: rename our config file
156   FileUtils.mv ".rubocop.yml", ".rack.rubocop.yml.disabled"
158   Bundler.with_clean_env do
159     clone_and_test("https://github.com/rack/rack-attack", "rack-attack", "bundle exec rake test")
160     clone_and_test("https://github.com/rack/rack-cache", "rack-cache", "bundle exec rake")
161     clone_and_test("https://github.com/socketry/falcon", "falcon", "bundle exec rspec")
162   end