/
spec_helper.rb
113 lines (97 loc) · 2.94 KB
/
spec_helper.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'rspec'
require File.expand_path( File.dirname(__FILE__) + '/../lib/rake/builder' )
SPEC_PATH = File.expand_path( File.dirname(__FILE__) )
module RakeBuilderHelper
TARGET = {
:executable => 'the_executable',
:static_library => 'libthe_static_library.a',
:shared_library => 'libthe_dynamic_library.so',
}
def cpp_task( type, namespace = nil )
Rake::Builder.new do |builder|
builder.programming_language = 'c++'
builder.target = TARGET[ type ]
builder.task_namespace = namespace
builder.source_search_paths = [ 'cpp_project' ]
builder.header_search_paths = [ 'cpp_project' ]
builder.generated_files << 'rake-builder-testfile.txt'
yield builder if block_given?
end
end
def c_task( type, namespace = nil )
Rake::Builder.new do |builder|
builder.programming_language = 'c'
builder.target = TARGET[ type ]
builder.task_namespace = namespace
builder.source_search_paths = [ 'c_project' ]
builder.header_search_paths = [ 'c_project' ]
builder.generated_files << 'rake-c-testfile.txt'
yield builder if block_given?
end
end
def objective_c_task( type, namespace = nil )
Rake::Builder.new do |builder|
builder.programming_language = 'objective-c'
builder.target = TARGET[ type ]
builder.task_namespace = namespace
builder.source_search_paths = [ 'objective_c_project' ]
builder.header_search_paths = [ 'objective_c_project' ]
builder.generated_files << 'rake-builder-testfile.txt'
builder.library_dependencies = [ 'objc' ]
builder.linker_options = '-framework CoreFoundation -framework Foundation'
yield builder if block_given?
end
end
def touch( file )
`touch #{file}`
end
def exist?( file )
File.exist? file
end
def task_names
Rake::Task.tasks.map( &:to_s )
end
def default_tasks
[ 'build', 'clean', 'compile', 'load_makedepend' ]
end
def expected_tasks( extras, scope = nil )
t = scoped_tasks( default_tasks, scope )
t += extras
t << if scope.nil?
'default'
else
scope
end
t
end
def scoped_tasks( tasks, scope )
return tasks if scope.nil?
tasks.map{ |t| "#{scope}:#{t}" }
end
def capturing_output
output = StringIO.new
$stdout = output
yield
output.string
ensure
$stdout = STDOUT
end
# Most file systems have a 1s resolution
# Force a wait into the next second around a task
# So FileTask's out_of_date? will behave correctly
def isolating_seconds
sec = Time.now.sec
yield
while( Time.now.sec == sec ) do end
end
def touching_temporarily( file, touch_time )
begin
atime = File.atime( file )
mtime = File.mtime( file )
File.utime( atime, touch_time, file )
yield
ensure
File.utime( atime, mtime, file )
end
end
end