-
Notifications
You must be signed in to change notification settings - Fork 22
/
Rakefile
60 lines (47 loc) · 1.5 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'bundler'
require 'rake/testtask'
require 'tmpdir'
Dir.chdir(File.dirname(__FILE__) + '/..')
tmpdir = Dir.mktmpdir
File.open(tmpdir + '/Gemfile', 'w') do |f|
f << File.read('Gemfile')
f << File.read('test/Gemfile')
end
Dir.chdir tmpdir do
Bundler.setup
end
Rake::TestTask.new do |t|
examples_tests_dir = Dir.mktmpdir('iw_examples')
FileUtils::cp_r(Dir.glob('examples/*'), examples_tests_dir)
Dir.glob('examples/**/**.rb').each do |path|
next unless path =~ %r|examples/(.*)/([^/]+)/\2.rb$|
dir = $1
name = $2
test_path = examples_tests_dir + "/#{dir}/#{name}/test_example_#{name}.rb"
File.open(test_path, 'w') do |out|
out << "require 'helpers'\n"
out << "class #{name.capitalize}Test < Test::Unit::TestCase\n"
out << "def test_example\n"
File.readlines(path).each do |line|
line, assert_str = line.chomp.split /#>/
out << line << "\n"
if assert_str
cond, desc = assert_str.split /--/
out << "assert(" << cond << ", '" <<
(desc or "").gsub(/'/, "\\\\'") << "')\n"
end
end
out << "end\nend\n"
end
end
t.libs << "lib" << "test" << examples_tests_dir
files = FileList['test/**/test_**.rb',
examples_tests_dir + '/**/test_*.rb']
$:.each{ |path| t.ruby_opts << "-I#{path}" }
t.test_files = files.keep_if do |f|
f =~ Regexp.new(ENV['TESTP'] || '') and
not ( r = ENV['EXCLP'] and
f =~ Regexp.new(r) )
end
t.verbose = true
end