forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrazy_fun.rb
93 lines (74 loc) · 2.02 KB
/
crazy_fun.rb
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'rake-tasks/crazy_fun/main.rb'
module Rake
class Task
attr_accessor :out
end
end
class CrazyFun
def initialize
@mappings = {}
end
def add_mapping(type_name, handler)
if [email protected]_key? type_name
@mappings[type_name] = []
end
@mappings[type_name].push handler
end
def prebuilt_roots
@roots ||= []
end
def find_prebuilt(of)
if of =~ %r"build([/\\])"
of_parts = of.split($1)[1..-1]
else
of_parts = of.split(Platform.dir_separator)
end
prebuilt_roots.each do |root|
root_parts = root.split("/")
if root_parts.first == of_parts.first
of_parts[0] = root
src = of_parts.join("/")
else
src = "#{root}/#{of}"
end
if File.exists? src
return src
end
end
nil
end
def create_tasks(files)
files.each do |f|
puts "Parsing #{f}" if $DEBUG
outputs = BuildFile.new().parse_file(f)
outputs.each do |type|
if [email protected]_key? type.name
raise RuntimeError, "No mapping for type: " + type.name
end
mappings = @mappings[type.name]
mappings.each do |mapping|
mapping.handle(self, File.dirname(f), type.args)
end
end
end
end
end
if __FILE__ == $0
require "rubygems"
require "spec/autorun"
describe CrazyFun do
let(:fun) { CrazyFun.new }
it "finds prebuilts with normal paths" do
fun.prebuilt_roots << "firefox/prebuilt"
expected_result = "firefox/prebuilt/i386/libnoblur.so"
File.should_receive(:exists?).with(expected_result).and_return(true)
fun.find_prebuilt("build/firefox/i386/libnoblur.so").should == expected_result
end
it "finds prebuilts with windows paths" do
fun.prebuilt_roots << "firefox/prebuilt"
expected_result = "firefox/prebuilt/i386/libnoblur.so"
File.should_receive(:exists?).with(expected_result).and_return(true)
fun.find_prebuilt("build\\firefox\\i386\\libnoblur.so").should == expected_result
end
end
end