irpack 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +57 -0
- data/lib/irpack.rb +16 -38
- data/lib/irpack/application.rb +71 -115
- data/lib/irpack/packager.rb +1 -1
- data/lib/irpack/rake/generateexetask.rb +86 -0
- data/lib/irpack/specification.rb +182 -0
- data/test/fixtures/foo.rb +3 -0
- data/test/test_application.rb +90 -72
- data/test/test_generateexetask.rb +152 -0
- data/test/test_irpack.rb +17 -13
- data/test/test_packager.rb +4 -4
- data/test/test_specification.rb +237 -0
- data/test/utils.rb +1 -0
- metadata +10 -2
@@ -0,0 +1,182 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2011 Ryuichi Sakamoto.
|
3
|
+
|
4
|
+
This software is provided 'as-is', without any express or implied
|
5
|
+
warranty. In no event will the authors be held liable for any damages
|
6
|
+
arising from the use of this software.
|
7
|
+
|
8
|
+
Permission is granted to anyone to use this software for any purpose,
|
9
|
+
including commercial applications, and to alter it and redistribute it
|
10
|
+
freely, subject to the following restrictions:
|
11
|
+
|
12
|
+
1. The origin of this software must not be misrepresented; you must not
|
13
|
+
claim that you wrote the original software. If you use this software
|
14
|
+
in a product, an acknowledgment in the product documentation would be
|
15
|
+
appreciated but is not required.
|
16
|
+
|
17
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
18
|
+
misrepresented as being the original software.
|
19
|
+
|
20
|
+
3. This notice may not be removed or altered from any source
|
21
|
+
distribution.
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'pathname'
|
25
|
+
|
26
|
+
module IRPack
|
27
|
+
class Specification
|
28
|
+
# Generated exe file path (default is entry_file replaced extention by '.exe').
|
29
|
+
attr_accessor :output_file
|
30
|
+
# Path of entry script.
|
31
|
+
attr_accessor :entry_file
|
32
|
+
# Array of files to embed, or Hash maps runtime paths to real files.
|
33
|
+
attr_accessor :files
|
34
|
+
# Base paths stripped from files and entry_file.
|
35
|
+
attr_accessor :base_paths
|
36
|
+
# Type of generated executable. :exe for console app, :winexe for window app (default is :exe).
|
37
|
+
attr_accessor :target
|
38
|
+
# True if compress embeded files (default is false).
|
39
|
+
attr_accessor :compress
|
40
|
+
# True if embed IronRuby assemblies (default is true).
|
41
|
+
attr_accessor :embed_assemblies
|
42
|
+
# True if embed standard libraries (default is true).
|
43
|
+
attr_accessor :embed_stdlibs
|
44
|
+
alias complete embed_stdlibs
|
45
|
+
alias complete= embed_stdlibs=
|
46
|
+
# Namespace of entry point.
|
47
|
+
attr_accessor :module_name
|
48
|
+
# RuntimeOptions passed to script engine.
|
49
|
+
attr_reader :runtime_options
|
50
|
+
|
51
|
+
# Options to script engine passed in runtime.
|
52
|
+
class RuntimeOptions
|
53
|
+
# True if emit debugging information (PDBs) for Visual Studio debugger (default is false).
|
54
|
+
attr_accessor :debug_mode
|
55
|
+
# True if disable adaptive compilation (default is false).
|
56
|
+
attr_accessor :no_adaptive_compilation
|
57
|
+
# The number of iterations before the interpreter starts compiling (default is 32).
|
58
|
+
attr_accessor :compilation_threshold
|
59
|
+
# True if enable ExceptionDetail mode (default is false).
|
60
|
+
attr_accessor :exception_detail
|
61
|
+
# True if display CLS Exception information (default is false).
|
62
|
+
attr_accessor :show_clr_exceptions
|
63
|
+
# Warning level; 0=silence, 1=medium (default), 2=verbose.
|
64
|
+
attr_accessor :warning_level
|
65
|
+
# Debugging flags ($DEBUG) (default is false).
|
66
|
+
attr_accessor :debug_variable
|
67
|
+
# True if enable support for IronRuby::Clr.profile (default is false).
|
68
|
+
attr_accessor :profile
|
69
|
+
# True if enable support for set_trace_func (default is false).
|
70
|
+
attr_accessor :trace
|
71
|
+
# Required libraries before executing entry_file.
|
72
|
+
attr_accessor :required_paths
|
73
|
+
# $LOAD_PATH directories.
|
74
|
+
attr_accessor :search_paths
|
75
|
+
# True if do not catch exceptions that are unhandled by script code.
|
76
|
+
attr_accessor :pass_exceptions
|
77
|
+
# True if enable binding to private members.
|
78
|
+
attr_accessor :private_binding
|
79
|
+
alias d debug_variable
|
80
|
+
alias d= debug_variable=
|
81
|
+
alias r required_paths
|
82
|
+
alias r= required_paths=
|
83
|
+
alias I search_paths
|
84
|
+
alias I= search_paths=
|
85
|
+
alias D debug_mode
|
86
|
+
alias D= debug_mode=
|
87
|
+
alias W warning_level
|
88
|
+
alias W= warning_level=
|
89
|
+
def initialize
|
90
|
+
@debug_mode = false
|
91
|
+
@no_adaptive_compilation = false
|
92
|
+
@compilation_threshold = -1
|
93
|
+
@exception_detail = false
|
94
|
+
@show_clr_exceptions = false
|
95
|
+
@warning_level = 1
|
96
|
+
@debug_variable = false
|
97
|
+
@profile = false
|
98
|
+
@trace = false
|
99
|
+
@required_paths = []
|
100
|
+
@search_paths = []
|
101
|
+
@pass_exceptions = false
|
102
|
+
@private_binding = false
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_hash
|
106
|
+
{
|
107
|
+
DebugMode: @debug_mode,
|
108
|
+
PrivateBinding: @private_binding,
|
109
|
+
NoAdaptiveCompilation: @no_adaptive_compilation,
|
110
|
+
CompilationThreshold: @compilation_threshold,
|
111
|
+
ExceptionDetail: @exception_detail,
|
112
|
+
ShowClrExceptions: @show_clr_exceptions,
|
113
|
+
PassExceptions: @pass_exceptions,
|
114
|
+
Profile: @profile,
|
115
|
+
Verbosity: @warning_level,
|
116
|
+
DebugVariable: @debug_variable,
|
117
|
+
EnableTracing: @trace,
|
118
|
+
RequiredPaths: @required_paths,
|
119
|
+
SearchPaths: @search_paths,
|
120
|
+
}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def initialize
|
125
|
+
@output_file = nil
|
126
|
+
@entry_file = nil
|
127
|
+
@module_name = nil
|
128
|
+
@files = []
|
129
|
+
@base_paths = []
|
130
|
+
@compress = false
|
131
|
+
@target = :exe
|
132
|
+
@embed_assemblies = true
|
133
|
+
@embed_stdlibs = false
|
134
|
+
@runtime_options = RuntimeOptions.new
|
135
|
+
yield self if block_given?
|
136
|
+
end
|
137
|
+
|
138
|
+
# Return entry file path at runtime.
|
139
|
+
def map_entry
|
140
|
+
raise ArgumentError, "No entry file specified" unless @entry_file
|
141
|
+
base_paths = @base_paths.collect {|path| Pathname.new(path).expand_path }
|
142
|
+
(strip_path(base_paths, @entry_file) || @entry_file).to_s
|
143
|
+
end
|
144
|
+
|
145
|
+
# Map runtime file path to real files.
|
146
|
+
def map_files
|
147
|
+
file_map = {}
|
148
|
+
entry_file = Pathname.new(map_entry)
|
149
|
+
entry_found = false
|
150
|
+
case @files
|
151
|
+
when Hash
|
152
|
+
@files.each do |path, file|
|
153
|
+
file_map[path.to_s] = File.expand_path(file.to_s)
|
154
|
+
entry_found = true if path.to_s==entry_file.to_s
|
155
|
+
end
|
156
|
+
else
|
157
|
+
base_paths = @base_paths.collect {|path| Pathname.new(path).expand_path }
|
158
|
+
@files.each do |fn|
|
159
|
+
next unless fn
|
160
|
+
relpath = strip_path(base_paths, fn) || fn
|
161
|
+
file_map[relpath.to_s] = File.expand_path(fn.to_s)
|
162
|
+
entry_found = true if relpath==entry_file
|
163
|
+
end
|
164
|
+
end
|
165
|
+
file_map[entry_file.to_s] = File.expand_path(@entry_file.to_s) unless entry_found
|
166
|
+
file_map
|
167
|
+
end
|
168
|
+
|
169
|
+
def strip_path(base_paths, path)
|
170
|
+
fullpath = Pathname.new(path).expand_path
|
171
|
+
base_paths.collect {|base|
|
172
|
+
if /\A#{Regexp.escape(base.to_s)}/=~fullpath.to_s then
|
173
|
+
fullpath.relative_path_from(base)
|
174
|
+
else
|
175
|
+
nil
|
176
|
+
end
|
177
|
+
}.compact.sort_by {|path| path.to_s.size }.first
|
178
|
+
end
|
179
|
+
private :strip_path
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
data/test/test_application.rb
CHANGED
@@ -26,73 +26,89 @@ require 'irpack/application'
|
|
26
26
|
require 'utils'
|
27
27
|
require 'stringio'
|
28
28
|
|
29
|
-
class
|
29
|
+
class TC_Application < Test::Unit::TestCase
|
30
30
|
include Utils
|
31
|
-
def
|
31
|
+
def test_parse_without_spec
|
32
32
|
argv = []
|
33
33
|
$stderr = StringIO.new
|
34
|
-
assert_nil(IRPack::Application
|
34
|
+
assert_nil(IRPack::Application.parse!(argv))
|
35
35
|
assert_not_equal('', $stderr.to_s)
|
36
|
+
$stderr = STDERR
|
36
37
|
end
|
37
38
|
|
38
39
|
def test_parse
|
39
40
|
argv = ['entry.rb']
|
40
|
-
|
41
|
-
assert(!
|
42
|
-
assert(!
|
43
|
-
assert(
|
44
|
-
assert_equal(:exe,
|
45
|
-
|
46
|
-
assert_equal('entry.rb',
|
47
|
-
assert_equal(
|
48
|
-
assert_equal(
|
49
|
-
|
50
|
-
|
51
|
-
assert_equal(
|
52
|
-
assert(!
|
53
|
-
assert(!
|
54
|
-
|
55
|
-
assert(!
|
56
|
-
|
57
|
-
assert(!
|
58
|
-
assert(!
|
59
|
-
|
41
|
+
spec = IRPack::Application.parse!(argv)
|
42
|
+
assert(!spec.compress)
|
43
|
+
assert(!spec.complete)
|
44
|
+
assert(spec.embed_assemblies)
|
45
|
+
assert_equal(:exe, spec.target)
|
46
|
+
assert_nil(spec.output_file)
|
47
|
+
assert_equal('entry.rb', spec.entry_file)
|
48
|
+
assert_equal('entry.rb', spec.map_entry)
|
49
|
+
assert_equal(0, spec.files.size)
|
50
|
+
pack_files = spec.map_files
|
51
|
+
assert_equal(1, pack_files.size)
|
52
|
+
assert_equal(File.expand_path('entry.rb'), pack_files['entry.rb'])
|
53
|
+
assert(!spec.runtime_options.debug_variable)
|
54
|
+
assert(!spec.runtime_options.debug_mode)
|
55
|
+
assert_equal(1, spec.runtime_options.warning_level)
|
56
|
+
assert(!spec.runtime_options.trace)
|
57
|
+
assert(!spec.runtime_options.profile)
|
58
|
+
assert(!spec.runtime_options.exception_detail)
|
59
|
+
assert(!spec.runtime_options.no_adaptive_compilation)
|
60
|
+
assert_equal(-1, spec.runtime_options.compilation_threshold)
|
61
|
+
assert(!spec.runtime_options.pass_exceptions)
|
62
|
+
assert(!spec.runtime_options.private_binding)
|
63
|
+
assert(!spec.runtime_options.show_clr_exceptions)
|
60
64
|
end
|
61
65
|
|
62
66
|
def test_parse_output_file
|
63
67
|
argv = ['-o', 'foo.exe', 'entry.rb']
|
64
|
-
|
65
|
-
assert_equal(File.expand_path('foo.exe'), File.expand_path(
|
68
|
+
spec = IRPack::Application.parse!(argv)
|
69
|
+
assert_equal(File.expand_path('foo.exe'), File.expand_path(spec.output_file))
|
66
70
|
end
|
67
71
|
|
68
72
|
def test_parse_window_app
|
69
73
|
argv = ['--window', 'entry.rb']
|
70
|
-
|
71
|
-
assert_equal(:winexe,
|
74
|
+
spec = IRPack::Application.parse!(argv)
|
75
|
+
assert_equal(:winexe, spec.target)
|
72
76
|
end
|
73
77
|
|
74
78
|
def test_parse_console_app
|
75
79
|
argv = ['--console', 'entry.rb']
|
76
|
-
|
77
|
-
assert_equal(:exe,
|
80
|
+
spec = IRPack::Application.parse!(argv)
|
81
|
+
assert_equal(:exe, spec.target)
|
78
82
|
end
|
79
83
|
|
80
|
-
def
|
84
|
+
def test_parse_no_embed
|
81
85
|
argv = ['--no-embed', 'entry.rb']
|
82
|
-
|
83
|
-
assert(!
|
86
|
+
spec = IRPack::Application.parse!(argv)
|
87
|
+
assert(!spec.embed_assemblies)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_parse_no_embed_assemblies
|
91
|
+
argv = ['--no-embed-assemblies', 'entry.rb']
|
92
|
+
spec = IRPack::Application.parse!(argv)
|
93
|
+
assert(!spec.embed_assemblies)
|
84
94
|
end
|
85
95
|
|
86
96
|
def test_parse_compress
|
87
97
|
argv = ['--compress', 'entry.rb']
|
88
|
-
|
89
|
-
assert(
|
98
|
+
spec = IRPack::Application.parse!(argv)
|
99
|
+
assert(spec.compress)
|
90
100
|
end
|
91
101
|
|
92
102
|
def test_parse_complete
|
93
103
|
argv = ['--complete', 'entry.rb']
|
94
|
-
|
95
|
-
assert(
|
104
|
+
spec = IRPack::Application.parse!(argv)
|
105
|
+
assert(spec.complete)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_parse_embed_stdlibs
|
109
|
+
argv = ['--embed-stdlibs', 'entry.rb']
|
110
|
+
spec = IRPack::Application.parse!(argv)
|
111
|
+
assert(spec.embed_stdlibs)
|
96
112
|
end
|
97
113
|
|
98
114
|
def test_parse_basedir
|
@@ -103,98 +119,100 @@ class TC_ApplicationArguments < Test::Unit::TestCase
|
|
103
119
|
File.expand_path('foo/bar/hoge.rb'),
|
104
120
|
'foo/bar/hoge/fuga.rb',
|
105
121
|
]
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal('
|
109
|
-
assert_equal(
|
110
|
-
|
111
|
-
assert_equal(
|
112
|
-
assert_equal('
|
113
|
-
assert_equal(
|
122
|
+
spec = IRPack::Application.parse!(argv)
|
123
|
+
assert_nil(spec.output_file)
|
124
|
+
assert_equal('entry.rb', spec.entry_file)
|
125
|
+
assert_equal('entry.rb', spec.map_entry)
|
126
|
+
pack_files = spec.map_files
|
127
|
+
assert_equal(4, pack_files.size)
|
128
|
+
assert_equal(File.expand_path('entry.rb'), pack_files['entry.rb'])
|
129
|
+
assert_equal(File.expand_path('foo/bar/baz.rb'), pack_files['baz.rb'])
|
130
|
+
assert_equal(File.expand_path('foo/bar/hoge.rb'), pack_files['hoge.rb'])
|
131
|
+
assert_equal(File.expand_path('foo/bar/hoge/fuga.rb'), pack_files['hoge/fuga.rb'])
|
114
132
|
end
|
115
133
|
|
116
134
|
def test_parse_debug_variable
|
117
135
|
argv = ['-d', 'entry.rb']
|
118
|
-
|
119
|
-
assert(
|
136
|
+
spec = IRPack::Application.parse!(argv)
|
137
|
+
assert(spec.runtime_options.debug_variable)
|
120
138
|
end
|
121
139
|
|
122
140
|
def test_parse_debug_mode
|
123
141
|
argv = ['-D', 'entry.rb']
|
124
|
-
|
125
|
-
assert(
|
142
|
+
spec = IRPack::Application.parse!(argv)
|
143
|
+
assert(spec.runtime_options.debug_mode)
|
126
144
|
end
|
127
145
|
|
128
146
|
def test_parse_verbose
|
129
147
|
argv = ['-v', 'entry.rb']
|
130
|
-
|
131
|
-
assert_equal(2,
|
148
|
+
spec = IRPack::Application.parse!(argv)
|
149
|
+
assert_equal(2, spec.runtime_options.warning_level)
|
132
150
|
end
|
133
151
|
|
134
152
|
def test_parse_warn
|
135
153
|
argv = ['-w', 'entry.rb']
|
136
|
-
|
137
|
-
assert_equal(2,
|
154
|
+
spec = IRPack::Application.parse!(argv)
|
155
|
+
assert_equal(2, spec.runtime_options.warning_level)
|
138
156
|
end
|
139
157
|
|
140
158
|
def test_parse_warning
|
141
159
|
argv = ['-W', 'entry.rb']
|
142
|
-
|
143
|
-
assert_equal(2,
|
160
|
+
spec = IRPack::Application.parse!(argv)
|
161
|
+
assert_equal(2, spec.runtime_options.warning_level)
|
144
162
|
end
|
145
163
|
|
146
164
|
def test_parse_warning0
|
147
165
|
argv = ['-W0', 'entry.rb']
|
148
|
-
|
149
|
-
assert_equal(0,
|
166
|
+
spec = IRPack::Application.parse!(argv)
|
167
|
+
assert_equal(0, spec.runtime_options.warning_level)
|
150
168
|
end
|
151
169
|
|
152
170
|
def test_parse_trace
|
153
171
|
argv = ['--trace', 'entry.rb']
|
154
|
-
|
155
|
-
assert(
|
172
|
+
spec = IRPack::Application.parse!(argv)
|
173
|
+
assert(spec.runtime_options.trace)
|
156
174
|
end
|
157
175
|
|
158
176
|
def test_parse_profile
|
159
177
|
argv = ['--profile', 'entry.rb']
|
160
|
-
|
161
|
-
assert(
|
178
|
+
spec = IRPack::Application.parse!(argv)
|
179
|
+
assert(spec.runtime_options.profile)
|
162
180
|
end
|
163
181
|
|
164
182
|
def test_parse_exception_detail
|
165
183
|
argv = ['--exception-detail', 'entry.rb']
|
166
|
-
|
167
|
-
assert(
|
184
|
+
spec = IRPack::Application.parse!(argv)
|
185
|
+
assert(spec.runtime_options.exception_detail)
|
168
186
|
end
|
169
187
|
|
170
188
|
def test_parse_no_adaptive_compilation
|
171
189
|
argv = ['--no-adaptive-compilation', 'entry.rb']
|
172
|
-
|
173
|
-
assert(
|
190
|
+
spec = IRPack::Application.parse!(argv)
|
191
|
+
assert(spec.runtime_options.no_adaptive_compilation)
|
174
192
|
end
|
175
193
|
|
176
194
|
def test_parse_compilation_threshold
|
177
195
|
argv = ['--compilation-threshold', '8192', 'entry.rb']
|
178
|
-
|
179
|
-
assert_equal(8192,
|
196
|
+
spec = IRPack::Application.parse!(argv)
|
197
|
+
assert_equal(8192, spec.runtime_options.compilation_threshold)
|
180
198
|
end
|
181
199
|
|
182
200
|
def test_parse_pass_exceptions
|
183
201
|
argv = ['--pass-exceptions', 'entry.rb']
|
184
|
-
|
185
|
-
assert(
|
202
|
+
spec = IRPack::Application.parse!(argv)
|
203
|
+
assert(spec.runtime_options.pass_exceptions)
|
186
204
|
end
|
187
205
|
|
188
206
|
def test_parse_private_binding
|
189
207
|
argv = ['--private-binding', 'entry.rb']
|
190
|
-
|
191
|
-
assert(
|
208
|
+
spec = IRPack::Application.parse!(argv)
|
209
|
+
assert(spec.runtime_options.private_binding)
|
192
210
|
end
|
193
211
|
|
194
212
|
def test_parse_show_clr_exceptions
|
195
213
|
argv = ['--show-clr-exceptions', 'entry.rb']
|
196
|
-
|
197
|
-
assert(
|
214
|
+
spec = IRPack::Application.parse!(argv)
|
215
|
+
assert(spec.runtime_options.show_clr_exceptions)
|
198
216
|
end
|
199
217
|
end
|
200
218
|
|
@@ -0,0 +1,152 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2011 Ryuichi Sakamoto.
|
3
|
+
|
4
|
+
This software is provided 'as-is', without any express or implied
|
5
|
+
warranty. In no event will the authors be held liable for any damages
|
6
|
+
arising from the use of this software.
|
7
|
+
|
8
|
+
Permission is granted to anyone to use this software for any purpose,
|
9
|
+
including commercial applications, and to alter it and redistribute it
|
10
|
+
freely, subject to the following restrictions:
|
11
|
+
|
12
|
+
1. The origin of this software must not be misrepresented; you must not
|
13
|
+
claim that you wrote the original software. If you use this software
|
14
|
+
in a product, an acknowledgment in the product documentation would be
|
15
|
+
appreciated but is not required.
|
16
|
+
|
17
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
18
|
+
misrepresented as being the original software.
|
19
|
+
|
20
|
+
3. This notice may not be removed or altered from any source
|
21
|
+
distribution.
|
22
|
+
=end
|
23
|
+
|
24
|
+
require 'test/unit'
|
25
|
+
require 'irpack/rake/generateexetask'
|
26
|
+
|
27
|
+
class TC_GenerateExeTask < Test::Unit::TestCase
|
28
|
+
def teardown
|
29
|
+
Rake::Task.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_construct
|
33
|
+
spec = IRPack::Specification.new
|
34
|
+
task = IRPack::Rake::GenerateExeTask.new(spec)
|
35
|
+
assert_equal(spec, task.exe_spec)
|
36
|
+
assert_equal(:exe, task.name)
|
37
|
+
assert(!Rake::Task.task_defined?(task.name))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_construct_with_block
|
41
|
+
spec = IRPack::Specification.new {|s|
|
42
|
+
s.output_file = 'main.exe'
|
43
|
+
s.entry_file = 'main.rb'
|
44
|
+
}
|
45
|
+
task_in_block = nil
|
46
|
+
task = IRPack::Rake::GenerateExeTask.new(spec) {|t|
|
47
|
+
task_in_block = t
|
48
|
+
assert_equal(spec, t.exe_spec)
|
49
|
+
assert_equal(:exe, t.name)
|
50
|
+
}
|
51
|
+
assert_same(task, task_in_block)
|
52
|
+
assert(Rake::Task.task_defined?(task.name))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_define_no_entry_file
|
56
|
+
spec = IRPack::Specification.new
|
57
|
+
task = IRPack::Rake::GenerateExeTask.new(spec)
|
58
|
+
assert_raise(ArgumentError) do
|
59
|
+
task.define
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_define_no_output_file
|
64
|
+
spec = IRPack::Specification.new {|s|
|
65
|
+
s.entry_file = 'main.rb'
|
66
|
+
}
|
67
|
+
task = IRPack::Rake::GenerateExeTask.new(spec)
|
68
|
+
assert_raise(ArgumentError) do
|
69
|
+
task.define
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_define_only_entry_file
|
74
|
+
spec = IRPack::Specification.new {|s|
|
75
|
+
s.output_file = 'output/main.exe'
|
76
|
+
s.entry_file = 'bin/main.rb'
|
77
|
+
}
|
78
|
+
IRPack::Rake::GenerateExeTask.new(spec) do
|
79
|
+
end
|
80
|
+
assert(Rake::Task.task_defined?(:exe))
|
81
|
+
task = Rake::Task[:exe]
|
82
|
+
assert_equal([spec.output_file], task.prerequisites)
|
83
|
+
assert(task.actions.empty?)
|
84
|
+
assert(Rake::Task.task_defined?(spec.output_file))
|
85
|
+
task = Rake::Task[spec.output_file]
|
86
|
+
assert_equal([File.expand_path('bin/main.rb')], task.prerequisites.sort)
|
87
|
+
assert(!task.actions.empty?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_define_with_files
|
91
|
+
spec = IRPack::Specification.new {|s|
|
92
|
+
s.output_file = 'output/main.exe'
|
93
|
+
s.entry_file = 'bin/main.rb'
|
94
|
+
s.files << 'bin/main.rb'
|
95
|
+
s.files << 'lib/foo.rb'
|
96
|
+
s.files << 'lib/bar.rb'
|
97
|
+
s.files << '../hoge/../fuga/../piyo.rb'
|
98
|
+
s.files << 'c:/foo/bar/baz.rb'
|
99
|
+
}
|
100
|
+
IRPack::Rake::GenerateExeTask.new(spec) do
|
101
|
+
end
|
102
|
+
task = Rake::Task[spec.output_file]
|
103
|
+
assert_equal([
|
104
|
+
'bin/main.rb',
|
105
|
+
'lib/foo.rb',
|
106
|
+
'lib/bar.rb',
|
107
|
+
'../hoge/../fuga/../piyo.rb',
|
108
|
+
'c:/foo/bar/baz.rb',
|
109
|
+
].collect {|fn| File.expand_path(fn) }.sort, task.prerequisites.sort)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_define_with_files_hash
|
113
|
+
spec = IRPack::Specification.new {|s|
|
114
|
+
s.output_file = 'output/main.exe'
|
115
|
+
s.entry_file = 'main.rb'
|
116
|
+
s.files = {
|
117
|
+
'main.rb' => 'bin/main.rb',
|
118
|
+
'foo.rb' => 'lib/foo.rb',
|
119
|
+
'bar.rb' => 'lib/bar.rb',
|
120
|
+
'../piyo.rb' => '../hoge/../fuga/../piyo.rb',
|
121
|
+
'foo/bar/baz.rb' => 'c:/foo/bar/baz.rb',
|
122
|
+
}
|
123
|
+
}
|
124
|
+
IRPack::Rake::GenerateExeTask.new(spec) do
|
125
|
+
end
|
126
|
+
task = Rake::Task[spec.output_file]
|
127
|
+
assert_equal([
|
128
|
+
'bin/main.rb',
|
129
|
+
'lib/foo.rb',
|
130
|
+
'lib/bar.rb',
|
131
|
+
'../hoge/../fuga/../piyo.rb',
|
132
|
+
'c:/foo/bar/baz.rb',
|
133
|
+
].collect {|fn| File.expand_path(fn) }.sort, task.prerequisites.sort)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_execute
|
137
|
+
FileUtils.mkpath('test/tmp')
|
138
|
+
spec = IRPack::Specification.new {|s|
|
139
|
+
s.output_file = 'test/tmp/foo.exe'
|
140
|
+
s.entry_file = 'test/fixtures/foo.rb'
|
141
|
+
}
|
142
|
+
IRPack::Rake::GenerateExeTask.new(spec) do
|
143
|
+
end
|
144
|
+
task = Rake::Task[spec.output_file]
|
145
|
+
task.execute
|
146
|
+
assert(File.exist?(spec.output_file))
|
147
|
+
assert('Hello World!', `#{spec.output_file}`)
|
148
|
+
ensure
|
149
|
+
FileUtils.rm_rf('test/tmp')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|