sprout 1.0.35.pre → 1.1.2.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/Gemfile +1 -1
- data/Gemfile.lock +0 -2
- data/README.textile +1 -1
- data/VERSION +1 -1
- data/lib/sprout/concern.rb +5 -7
- data/lib/sprout/daemon.rb +183 -143
- data/lib/sprout/executable/base.rb +564 -0
- data/lib/sprout/executable.rb +1 -550
- data/lib/sprout/generator/base.rb +2 -3
- data/lib/sprout/generator.rb +2 -1
- data/lib/sprout/generators/ruby/templates/ruby_base.rb +1 -2
- data/lib/sprout/library.rb +3 -3
- data/lib/sprout/output_buffer.rb +35 -0
- data/lib/sprout/process_runner.rb +68 -17
- data/lib/sprout/progress_bar.rb +5 -5
- data/lib/sprout/remote_file_target.rb +1 -1
- data/lib/sprout/system/base_system.rb +3 -3
- data/lib/sprout/system/unix_system.rb +1 -1
- data/lib/sprout/{test/sprout_test_case.rb → test_helper.rb} +214 -14
- data/lib/sprout/version.rb +1 -1
- data/lib/sprout.rb +133 -2
- data/rakefile.rb +2 -0
- data/test/fixtures/examples/echo_inputs.rb +1 -2
- data/test/fixtures/executable/fdb.rb +7 -9
- data/test/fixtures/executable/flex3sdk_gem/fdb +49 -18
- data/test/fixtures/executable/mxmlc.rb +1 -2
- data/test/fixtures/executable/subclass/executable_subclass.rb +0 -1
- data/test/fixtures/executable/subclass/executable_superclass.rb +1 -2
- data/test/fixtures/specification/flex4sdk.rb +35 -24
- data/test/unit/archive_unpacker_test.rb +1 -1
- data/test/unit/boolean_param_test.rb +1 -1
- data/test/unit/daemon_test.rb +35 -3
- data/test/unit/executable_option_parser_test.rb +2 -3
- data/test/unit/executable_param_test.rb +1 -1
- data/test/unit/executable_test.rb +8 -15
- data/test/unit/fake_other_executable.rb +1 -2
- data/test/unit/file_param_test.rb +1 -1
- data/test/unit/file_target_test.rb +1 -1
- data/test/unit/files_param_test.rb +1 -1
- data/test/unit/generator_generator_test.rb +1 -1
- data/test/unit/generator_test.rb +1 -1
- data/test/unit/library_generator_test.rb +1 -1
- data/test/unit/library_test.rb +1 -1
- data/test/unit/osx_system_test.rb +1 -1
- data/test/unit/path_param_test.rb +1 -1
- data/test/unit/paths_param_test.rb +1 -1
- data/test/unit/platform_test.rb +1 -1
- data/test/unit/process_runner_test.rb +1 -1
- data/test/unit/rdoc_parser_test.rb +1 -1
- data/test/unit/remote_file_loader_test.rb +1 -1
- data/test/unit/remote_file_target_test.rb +1 -1
- data/test/unit/ruby_feature_test.rb +1 -1
- data/test/unit/ruby_generator_test.rb +1 -1
- data/test/unit/specification_test.rb +8 -1
- data/test/unit/sprout_test.rb +2 -2
- data/test/unit/string_param_test.rb +1 -1
- data/test/unit/string_test.rb +1 -1
- data/test/unit/strings_param_test.rb +1 -1
- data/test/unit/test_helper.rb +33 -1
- data/test/unit/tool_generator_test.rb +1 -1
- data/test/unit/unix_system_test.rb +1 -1
- data/test/unit/user_test.rb +1 -1
- data/test/unit/vista_system_test.rb +1 -1
- data/test/unit/win_nix_system_test.rb +1 -1
- data/test/unit/win_system_test.rb +1 -1
- data/test-stderr.log +1 -0
- data/test-stdout.log +237 -0
- metadata +15 -190
- data/doc/Dir.html +0 -288
- data/doc/Rake/Task.html +0 -184
- data/doc/Sprout/ArchiveUnpacker.html +0 -1246
- data/doc/Sprout/Base/ClassMethods.html +0 -434
- data/doc/Sprout/Base.html +0 -126
- data/doc/Sprout/Concern.html +0 -353
- data/doc/Sprout/Daemon/ClassMethods.html +0 -244
- data/doc/Sprout/Daemon/InstanceMethods.html +0 -601
- data/doc/Sprout/Daemon.html +0 -166
- data/doc/Sprout/Errors/ArchiveUnpackerError.html +0 -125
- data/doc/Sprout/Errors/DestinationExistsError.html +0 -133
- data/doc/Sprout/Errors/DuplicateMemberError.html +0 -132
- data/doc/Sprout/Errors/ExecutableError.html +0 -125
- data/doc/Sprout/Errors/ExecutableRegistrationError.html +0 -132
- data/doc/Sprout/Errors/ExecutionError.html +0 -121
- data/doc/Sprout/Errors/GeneratorError.html +0 -125
- data/doc/Sprout/Errors/InvalidArgumentError.html +0 -132
- data/doc/Sprout/Errors/LoadError.html +0 -121
- data/doc/Sprout/Errors/MissingArgumentError.html +0 -132
- data/doc/Sprout/Errors/MissingExecutableError.html +0 -132
- data/doc/Sprout/Errors/MissingGeneratorError.html +0 -132
- data/doc/Sprout/Errors/MissingTemplateError.html +0 -132
- data/doc/Sprout/Errors/ProcessRunnerError.html +0 -121
- data/doc/Sprout/Errors/RemoteFileLoaderError.html +0 -110
- data/doc/Sprout/Errors/SproutError.html +0 -114
- data/doc/Sprout/Errors/UnknownArchiveType.html +0 -122
- data/doc/Sprout/Errors/UsageError.html +0 -121
- data/doc/Sprout/Errors/ValidationError.html +0 -121
- data/doc/Sprout/Errors/VersionRequirementNotMetError.html +0 -121
- data/doc/Sprout/Errors.html +0 -101
- data/doc/Sprout/Executable/Boolean.html +0 -483
- data/doc/Sprout/Executable/ClassMethods.html +0 -417
- data/doc/Sprout/Executable/CollectionParam.html +0 -483
- data/doc/Sprout/Executable/FileParam.html +0 -484
- data/doc/Sprout/Executable/Files.html +0 -292
- data/doc/Sprout/Executable/InstanceMethods.html +0 -2006
- data/doc/Sprout/Executable/Number.html +0 -141
- data/doc/Sprout/Executable/Param.html +0 -2818
- data/doc/Sprout/Executable/ParameterFactory.html +0 -232
- data/doc/Sprout/Executable/Path.html +0 -223
- data/doc/Sprout/Executable/Paths.html +0 -253
- data/doc/Sprout/Executable/StringParam.html +0 -213
- data/doc/Sprout/Executable/Strings.html +0 -167
- data/doc/Sprout/Executable/Url.html +0 -160
- data/doc/Sprout/Executable/Urls.html +0 -170
- data/doc/Sprout/Executable.html +0 -173
- data/doc/Sprout/FileTarget.html +0 -1109
- data/doc/Sprout/Generator/Base.html +0 -1626
- data/doc/Sprout/Generator/Command.html +0 -690
- data/doc/Sprout/Generator/DirectoryManifest.html +0 -476
- data/doc/Sprout/Generator/FileManifest.html +0 -572
- data/doc/Sprout/Generator/Manifest.html +0 -377
- data/doc/Sprout/Generator/TemplateManifest.html +0 -196
- data/doc/Sprout/Generator.html +0 -689
- data/doc/Sprout/GeneratorGenerator.html +0 -1018
- data/doc/Sprout/Library.html +0 -1141
- data/doc/Sprout/LibraryGenerator.html +0 -309
- data/doc/Sprout/Log.html +0 -496
- data/doc/Sprout/MXMLC.html +0 -6373
- data/doc/Sprout/Platform.html +0 -714
- data/doc/Sprout/ProcessRunner.html +0 -1352
- data/doc/Sprout/ProgressBar.html +0 -376
- data/doc/Sprout/ProgressBarImpl.html +0 -2119
- data/doc/Sprout/ProgressBarManager.html +0 -434
- data/doc/Sprout/ProgressBarOutputStream.html +0 -416
- data/doc/Sprout/RDocParser.html +0 -211
- data/doc/Sprout/RemoteFileLoader.html +0 -172
- data/doc/Sprout/RemoteFileTarget.html +0 -679
- data/doc/Sprout/ReversedProgressBar.html +0 -194
- data/doc/Sprout/RubyFeature/ClassMethods.html +0 -1065
- data/doc/Sprout/RubyFeature.html +0 -155
- data/doc/Sprout/RubyGenerator.html +0 -764
- data/doc/Sprout/Specification.html +0 -767
- data/doc/Sprout/System/BaseSystem.html +0 -1455
- data/doc/Sprout/System/JavaSystem.html +0 -122
- data/doc/Sprout/System/OSXSystem.html +0 -335
- data/doc/Sprout/System/ThreadMock.html +0 -193
- data/doc/Sprout/System/UnixSystem.html +0 -584
- data/doc/Sprout/System/VistaSystem.html +0 -251
- data/doc/Sprout/System/WinNixSystem.html +0 -325
- data/doc/Sprout/System/WinSystem.html +0 -571
- data/doc/Sprout/System.html +0 -191
- data/doc/Sprout/ToolGenerator.html +0 -931
- data/doc/Sprout/VERSION.html +0 -128
- data/doc/Sprout.html +0 -144
- data/doc/SproutTestCase.html +0 -1412
- data/doc/String.html +0 -286
- data/doc/_index.html +0 -1035
- data/doc/class_list.html +0 -36
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -53
- data/doc/css/style.css +0 -310
- data/doc/file.README.html +0 -96
- data/doc/file.archive_unpacker.html +0 -288
- data/doc/file.base.html +0 -208
- data/doc/file.base_system.html +0 -278
- data/doc/file.boolean.html +0 -135
- data/doc/file.collection_param.html +0 -139
- data/doc/file.command.html +0 -126
- data/doc/file.concern.html +0 -136
- data/doc/file.daemon.html +0 -309
- data/doc/file.dir.html +0 -76
- data/doc/file.directory_manifest.html +0 -122
- data/doc/file.errors.html +0 -147
- data/doc/file.executable.html +0 -638
- data/doc/file.file_manifest.html +0 -109
- data/doc/file.file_param.html +0 -120
- data/doc/file.file_target.html +0 -140
- data/doc/file.files.html +0 -85
- data/doc/file.generator.html +0 -296
- data/doc/file.generator_class.html +0 -72
- data/doc/file.generator_generator.html +0 -137
- data/doc/file.generator_test.html +0 -92
- data/doc/file.generator_test_helper.html +0 -67
- data/doc/file.java_system.html +0 -62
- data/doc/file.library.html +0 -291
- data/doc/file.library_generator.html +0 -74
- data/doc/file.log.html +0 -100
- data/doc/file.manifest.html +0 -67
- data/doc/file.mxmlc.html +0 -740
- data/doc/file.number.html +0 -67
- data/doc/file.osx_system.html +0 -79
- data/doc/file.param.html +0 -491
- data/doc/file.parameter_factory.html +0 -119
- data/doc/file.path.html +0 -81
- data/doc/file.paths.html +0 -80
- data/doc/file.platform.html +0 -124
- data/doc/file.process_runner.html +0 -224
- data/doc/file.progress_bar.html +0 -390
- data/doc/file.rdoc_parser.html +0 -145
- data/doc/file.remote_file_loader.html +0 -117
- data/doc/file.remote_file_target.html +0 -176
- data/doc/file.ruby_base.html +0 -64
- data/doc/file.ruby_feature.html +0 -244
- data/doc/file.ruby_generator.html +0 -118
- data/doc/file.ruby_input.html +0 -62
- data/doc/file.ruby_test_case.html +0 -78
- data/doc/file.ruby_test_helper.html +0 -61
- data/doc/file.specification.html +0 -248
- data/doc/file.sprout.html +0 -64
- data/doc/file.sprout_test_case.html +0 -280
- data/doc/file.string.html +0 -72
- data/doc/file.string_param.html +0 -76
- data/doc/file.strings.html +0 -71
- data/doc/file.system.html +0 -86
- data/doc/file.template_manifest.html +0 -67
- data/doc/file.tool.html +0 -92
- data/doc/file.tool_generator.html +0 -90
- data/doc/file.unix_system.html +0 -128
- data/doc/file.url.html +0 -71
- data/doc/file.urls.html +0 -70
- data/doc/file.version.html +0 -71
- data/doc/file.vista_system.html +0 -69
- data/doc/file.win_nix_system.html +0 -88
- data/doc/file.win_system.html +0 -129
- data/doc/file_list.html +0 -230
- data/doc/frames.html +0 -13
- data/doc/index.html +0 -96
- data/doc/js/app.js +0 -202
- data/doc/js/full_list.js +0 -149
- data/doc/js/jquery.js +0 -154
- data/doc/method_list.html +0 -3355
- data/doc/top-level-namespace.html +0 -192
- data/lib/sprout/base.rb +0 -121
- data/lib/sprout/log.rb +0 -46
- data/test/unit/sprout_test_helper.rb +0 -33
@@ -1,30 +1,43 @@
|
|
1
1
|
|
2
|
-
module Sprout
|
2
|
+
module Sprout
|
3
3
|
|
4
4
|
# The ProcessRunner is a cross-platform wrapper for executing
|
5
5
|
# external executable processes.
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
7
|
+
# This class is typically accesses via the concrete Sprout::System
|
8
|
+
# classes in order to avoid ugly branching logic in the application
|
9
|
+
# layer.
|
10
|
+
#
|
11
|
+
# An example of this kind of usage might be:
|
12
|
+
#
|
13
|
+
# Sprout.current_system.execute './some.exe', '--foo=bar --baz=buz'
|
14
|
+
#
|
15
|
+
# To use this class directly, you need to know if you're on
|
16
|
+
# a unix-like system or a dos platform as these two deal with
|
17
|
+
# processes very differently.
|
18
|
+
#
|
19
|
+
# Assuming you know you're on a unix-like system, you could
|
20
|
+
# execute the previous example with:
|
21
|
+
#
|
22
|
+
# runner = Sprout::ProcessRunner.new
|
23
|
+
# runner.execute_open4 './some.exe --foo-bar --baz=buz'
|
24
|
+
# puts runner.read
|
25
|
+
#
|
13
26
|
class ProcessRunner
|
14
27
|
|
15
28
|
attr_reader :pid
|
16
29
|
attr_reader :ruby_version
|
17
30
|
|
18
31
|
##
|
19
|
-
#
|
32
|
+
# @return [IO] Read only
|
20
33
|
attr_reader :r
|
21
34
|
|
22
35
|
##
|
23
|
-
#
|
36
|
+
# @return [IO] Write only
|
24
37
|
attr_reader :w
|
25
38
|
|
26
39
|
##
|
27
|
-
#
|
40
|
+
# @return [IO] Error output
|
28
41
|
attr_reader :e
|
29
42
|
|
30
43
|
def initialize
|
@@ -32,6 +45,7 @@ module Sprout #:nodoc:
|
|
32
45
|
@ruby_version = RUBY_VERSION
|
33
46
|
end
|
34
47
|
|
48
|
+
##
|
35
49
|
# Execute the provided command using the open4.popen4
|
36
50
|
# library. This is generally only used by Cygwin and
|
37
51
|
# *nix variants (including OS X).
|
@@ -44,27 +58,36 @@ module Sprout #:nodoc:
|
|
44
58
|
end
|
45
59
|
end
|
46
60
|
|
61
|
+
##
|
47
62
|
# Execute the provided command using the win32-open3
|
48
|
-
# library. This is generally used
|
49
|
-
#
|
63
|
+
# library. This is generally used only only Windows
|
64
|
+
# systems (even 64 bit).
|
50
65
|
def execute_win32(*command)
|
51
66
|
execute_with_block *command do
|
52
67
|
@pid, @w, @r, @e = io_popen_block *command.join(' ')
|
53
68
|
end
|
54
69
|
end
|
55
70
|
|
71
|
+
##
|
72
|
+
# @return [Boolean] whether the process is still running.
|
56
73
|
def alive?
|
57
74
|
@alive = update_status
|
58
75
|
end
|
59
76
|
|
77
|
+
##
|
78
|
+
# Kill the process.
|
60
79
|
def kill
|
61
80
|
Process.kill(9, pid)
|
62
81
|
end
|
63
82
|
|
83
|
+
##
|
84
|
+
# Close the process
|
64
85
|
def close
|
65
86
|
update_status
|
66
87
|
end
|
67
88
|
|
89
|
+
##
|
90
|
+
# Send an update signal to the process.
|
68
91
|
def update_status
|
69
92
|
pid_int = Integer("#{ @pid }")
|
70
93
|
begin
|
@@ -75,42 +98,70 @@ module Sprout #:nodoc:
|
|
75
98
|
end
|
76
99
|
end
|
77
100
|
|
78
|
-
|
79
|
-
|
101
|
+
##
|
102
|
+
# Read +count+ characters from the process standard out.
|
103
|
+
#
|
104
|
+
# @param count [Integer] Number of characters to read.
|
105
|
+
# @return [String]
|
106
|
+
def readpartial count
|
107
|
+
@r.readpartial count
|
80
108
|
end
|
81
109
|
|
82
|
-
|
83
|
-
|
110
|
+
##
|
111
|
+
# Read +count+ lines from the process standard out.
|
112
|
+
#
|
113
|
+
# @param count [Integer] Number of lines to read.
|
114
|
+
# @return [String]
|
115
|
+
def readlines count
|
116
|
+
@r.readlines count
|
84
117
|
end
|
85
118
|
|
119
|
+
##
|
120
|
+
# Flush the write IO to the process.
|
86
121
|
def flush
|
87
122
|
@w.flush
|
88
123
|
end
|
89
124
|
|
125
|
+
##
|
126
|
+
# Get user input on the read stream from the process.
|
90
127
|
def getc
|
91
128
|
@r.getc
|
92
129
|
end
|
93
130
|
|
94
|
-
|
131
|
+
##
|
132
|
+
# Print some characters to process without an end of line character.
|
133
|
+
def print msg
|
95
134
|
@w.print msg
|
96
135
|
end
|
97
136
|
|
137
|
+
##
|
138
|
+
# Print characters to the process followed by an end of line.
|
98
139
|
def puts(msg)
|
99
140
|
@w.puts(msg)
|
100
141
|
end
|
101
142
|
|
143
|
+
##
|
144
|
+
# Close the write stream - usually terminates the process.
|
102
145
|
def close_write
|
103
146
|
@w.close_write
|
104
147
|
end
|
105
148
|
|
149
|
+
##
|
150
|
+
# Wait for the process to end and return the entire standard output.
|
106
151
|
def read
|
107
152
|
return @r.read
|
108
153
|
end
|
109
154
|
|
155
|
+
##
|
156
|
+
# Wait for the process to end and return the entire standard error.
|
110
157
|
def read_err
|
111
158
|
return @e.read
|
112
159
|
end
|
113
160
|
|
161
|
+
def readpartial_err count
|
162
|
+
return @e.readpartial count
|
163
|
+
end
|
164
|
+
|
114
165
|
private
|
115
166
|
|
116
167
|
def open4_popen4_block *command
|
data/lib/sprout/progress_bar.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
require 'singleton'
|
14
14
|
|
15
15
|
module Sprout
|
16
|
-
class ProgressBar
|
16
|
+
class ProgressBar
|
17
17
|
VERSION = "0.9"
|
18
18
|
@@debug = false
|
19
19
|
@@outio = $stderr
|
@@ -41,7 +41,7 @@ module Sprout
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
-
class ProgressBarImpl
|
44
|
+
class ProgressBarImpl
|
45
45
|
|
46
46
|
def initialize (title, total, out = STDERR)
|
47
47
|
@title = title
|
@@ -265,13 +265,13 @@ module Sprout
|
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
|
-
class ReversedProgressBar < ProgressBar
|
268
|
+
class ReversedProgressBar < ProgressBar
|
269
269
|
def do_percentage
|
270
270
|
100 - super
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
274
|
-
class ProgressBarOutputStream
|
274
|
+
class ProgressBarOutputStream
|
275
275
|
attr_reader :title
|
276
276
|
|
277
277
|
def initialize(mgr)
|
@@ -293,7 +293,7 @@ module Sprout
|
|
293
293
|
|
294
294
|
end
|
295
295
|
|
296
|
-
class ProgressBarManager
|
296
|
+
class ProgressBarManager
|
297
297
|
include Singleton
|
298
298
|
|
299
299
|
def initialize
|
@@ -68,13 +68,13 @@ module Sprout::System
|
|
68
68
|
# Raises a +Sprout::Errors::ExecutionError+ if the process writes to stderr
|
69
69
|
#
|
70
70
|
def execute(tool, options='')
|
71
|
-
Sprout
|
71
|
+
Sprout.stdout.puts("#{tool} #{options}")
|
72
72
|
runner = get_and_execute_process_runner(tool, options)
|
73
73
|
error = runner.read_err
|
74
74
|
result = runner.read
|
75
75
|
|
76
76
|
if(result.size > 0)
|
77
|
-
Sprout
|
77
|
+
Sprout.stdout.puts result
|
78
78
|
end
|
79
79
|
|
80
80
|
if(error.size > 0)
|
@@ -216,7 +216,7 @@ module Sprout::System
|
|
216
216
|
|
217
217
|
end
|
218
218
|
|
219
|
-
class ThreadMock
|
219
|
+
class ThreadMock
|
220
220
|
def alive?
|
221
221
|
return false
|
222
222
|
end
|
@@ -50,7 +50,7 @@ module Sprout::System
|
|
50
50
|
def repair_executable path
|
51
51
|
content = File.read(path)
|
52
52
|
if(content.match(/\r\n/))
|
53
|
-
Sprout
|
53
|
+
Sprout.stdout.puts "[WARNING] Sprouts is about to replace invalid Windows line endings on an executable at: (#{path})"
|
54
54
|
content.gsub!(/\r\n/, "\n")
|
55
55
|
File.open(path, 'w+') do |f|
|
56
56
|
f.write content
|
@@ -1,24 +1,74 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
2
|
+
##
|
3
|
+
# A collection of custom assertions and helper methods
|
4
|
+
# to take some of the suck out of testing functionality
|
5
|
+
# that is based on Sprout features.
|
6
|
+
#
|
7
|
+
# Include this module into your test cases to make
|
8
|
+
# testing Sprout tools easier.
|
9
|
+
#
|
10
|
+
# require 'sprout/test/sprout_test_helper'
|
11
|
+
#
|
12
|
+
# class SomeTestCase < Test::Unit::TestCase
|
13
|
+
# include Sprout::TestHelper
|
14
|
+
#
|
15
|
+
# def setup
|
16
|
+
# super
|
17
|
+
# # do something
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def teardown
|
21
|
+
# super
|
22
|
+
# # do something
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# def test_something
|
26
|
+
# assert_file File.join(fixtures, 'some_file') do |f|
|
27
|
+
# assert_matches /Fred/, f
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
module Sprout::TestHelper
|
33
|
+
|
34
|
+
##
|
35
|
+
# The name of the folder that should contain
|
36
|
+
# fixture data.
|
7
37
|
FIXTURES_NAME = 'fixtures'
|
8
38
|
|
9
39
|
# Gives us the ability to hide RubyGem output from
|
10
40
|
# our test results...
|
11
41
|
include Gem::DefaultUserInteraction
|
12
42
|
|
43
|
+
##
|
44
|
+
# Add the skip method that was introduced in Ruby 1.9.1 Test::Unit
|
45
|
+
# This doesn't really work all that well...
|
46
|
+
if(RUBY_VERSION == '1.8.7')
|
47
|
+
def skip message=""
|
48
|
+
puts
|
49
|
+
puts ">> SproutTestCase.skip called from: #{caller[0]} ( #{message} )"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# @return [Dir] Path to a fixtures folder that is next to
|
55
|
+
# the text case that calls this method.
|
13
56
|
def fixtures from=nil
|
14
57
|
@fixtures ||= find_fixtures(from || Sprout.file_from_caller(caller.first))
|
15
58
|
end
|
16
59
|
|
60
|
+
##
|
61
|
+
# Override the setup method in order to record the
|
62
|
+
# working directory before the test method runs.
|
17
63
|
def setup
|
18
64
|
super
|
19
65
|
@start_path = Dir.pwd
|
20
66
|
end
|
21
67
|
|
68
|
+
##
|
69
|
+
# Override the teardown method in order to perform
|
70
|
+
# systemic cleanup work like, clearing lingering rake tasks,
|
71
|
+
# and removing temporary folders.
|
22
72
|
def teardown
|
23
73
|
super
|
24
74
|
clear_tasks
|
@@ -35,56 +85,123 @@ module SproutTestCase # :nodoc:[all]
|
|
35
85
|
end
|
36
86
|
end
|
37
87
|
|
88
|
+
protected
|
89
|
+
|
90
|
+
##
|
91
|
+
# Create a temporary folder relative to the
|
92
|
+
# test case that calls this method.
|
93
|
+
#
|
94
|
+
# @return [Dir] Path to the requested temp folder.
|
38
95
|
def temp_path
|
39
96
|
caller_file = Sprout.file_from_caller caller.first
|
40
97
|
@temp_path ||= make_temp_folder File.dirname(caller_file)
|
41
98
|
end
|
42
99
|
|
100
|
+
##
|
101
|
+
# Create a temporary folder relative to the
|
102
|
+
# provided path.
|
103
|
+
#
|
104
|
+
# @param from [Dir] Folder within which a 'tmp' folder should be added.
|
105
|
+
#
|
106
|
+
# @return [Dir] Path to the requested temp folder.
|
43
107
|
def make_temp_folder from
|
44
108
|
dir = File.join(fixtures(from), 'tmp')
|
45
109
|
FileUtils.mkdir_p dir
|
46
110
|
dir
|
47
111
|
end
|
48
112
|
|
113
|
+
##
|
114
|
+
# Invoke a Rake task by name.
|
115
|
+
#
|
116
|
+
# @return [Rake::Task] The task that was invoked.
|
49
117
|
def run_task(name)
|
50
118
|
t = Rake.application[name]
|
51
119
|
t.invoke
|
52
120
|
return t
|
53
121
|
end
|
54
122
|
|
123
|
+
##
|
124
|
+
# Retrieve a registered Rake task by name.
|
125
|
+
#
|
126
|
+
# @return [Rake::Task] The task that was found.
|
55
127
|
def get_task(name)
|
56
128
|
return Rake.application[name]
|
57
129
|
end
|
58
130
|
|
131
|
+
##
|
132
|
+
# Clear all registered Rake tasks.
|
59
133
|
def clear_tasks
|
60
134
|
CLEAN.delete_if {|a| true }
|
61
135
|
Rake::Task.clear
|
62
136
|
Rake.application.clear
|
63
137
|
end
|
64
138
|
|
139
|
+
##
|
140
|
+
# Create an empty file at +path+
|
141
|
+
#
|
142
|
+
# @param [File] The path to the file that should be created.
|
143
|
+
# @return [File] The path to the file.
|
65
144
|
def create_file path
|
66
145
|
dir = File.dirname path
|
67
146
|
FileUtils.mkdir_p dir
|
68
147
|
FileUtils.touch path
|
69
148
|
end
|
70
149
|
|
150
|
+
##
|
151
|
+
# Remove a file if it exists. If no file exists,
|
152
|
+
# do nothing.
|
153
|
+
#
|
154
|
+
# @param path [File] Path to the file that should be removed.
|
71
155
|
def remove_file(path=nil)
|
72
156
|
if(path && File.exists?(path))
|
73
157
|
FileUtils.rm_rf(path)
|
74
158
|
end
|
75
159
|
end
|
76
160
|
|
161
|
+
##
|
162
|
+
# Assert that a file exists at +path+ and display +message+
|
163
|
+
# if it does not.
|
164
|
+
#
|
165
|
+
# @param path [File] Path to the file that should exist.
|
166
|
+
# @param message [String] The message that should be displayed if the expected file does not exist.
|
167
|
+
# @yield [String] The contents of the file.
|
168
|
+
#
|
169
|
+
# This method yields the file contents so that you can write
|
170
|
+
# readable tests like:
|
171
|
+
#
|
172
|
+
# assert_file File.join(fixtures, 'my_file') do |f|
|
173
|
+
# assert_matches /Johnny/, f
|
174
|
+
# end
|
175
|
+
#
|
77
176
|
def assert_file(path, message=nil)
|
78
177
|
message ||= "Expected file not found at #{path}"
|
79
178
|
assert(File.exists?(path), message)
|
80
179
|
yield File.read(path) if block_given?
|
81
180
|
end
|
82
181
|
|
182
|
+
##
|
183
|
+
# Assert that a directory exists at +path+ and display +message+
|
184
|
+
# if it does not.
|
185
|
+
#
|
186
|
+
# @param path [Dir] Path to the directory that should exist.
|
187
|
+
# @param message [String] The message that should be displayed if the expected directory does not exist.
|
188
|
+
#
|
189
|
+
# assert_directory File.join(fixtures, 'SomeDir')
|
190
|
+
#
|
83
191
|
def assert_directory(path, message=nil)
|
84
192
|
message ||= "Expected directory not found at #{path}"
|
85
193
|
assert(File.directory?(path), message)
|
86
194
|
end
|
87
195
|
|
196
|
+
##
|
197
|
+
# Assert that a file exists at +path+ and is not empty. Display
|
198
|
+
# +message+ if the file does not exist or if it is empty.
|
199
|
+
# @param path [File] Path to the file that should exist.
|
200
|
+
# @param message [String] The message that should be displayed if
|
201
|
+
# the expected file does not exist or is empty.
|
202
|
+
#
|
203
|
+
# assert_not_empty File.join(fixtures, 'SomeFile')
|
204
|
+
#
|
88
205
|
def assert_not_empty(path, message=nil)
|
89
206
|
assert_file path, message
|
90
207
|
files = FileList["#{path}/*"]
|
@@ -92,6 +209,14 @@ module SproutTestCase # :nodoc:[all]
|
|
92
209
|
assert files.size > 0, message
|
93
210
|
end
|
94
211
|
|
212
|
+
##
|
213
|
+
# Assert that an expression matches the provided string.
|
214
|
+
#
|
215
|
+
# This helper mainly makes tests more readable and provides
|
216
|
+
# simpler failure messages without extra work.
|
217
|
+
#
|
218
|
+
# assert_matches /Fred/, 'Bill, Fred, Bob'
|
219
|
+
#
|
95
220
|
def assert_matches(expression, string, message='')
|
96
221
|
if(expression.is_a?(String))
|
97
222
|
expresion = /#{expression}/
|
@@ -102,20 +227,52 @@ module SproutTestCase # :nodoc:[all]
|
|
102
227
|
end
|
103
228
|
|
104
229
|
##
|
105
|
-
#
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
230
|
+
# Update the Sprout::Executable registry so that subsequent
|
231
|
+
# requests for an executable return a fake one instead of
|
232
|
+
# the real one.
|
233
|
+
#
|
234
|
+
# @param exe [Symbol] The executable that will be sent to the load request (e.g. :fdb, :mxmlc, etc.).
|
235
|
+
# @param fake_name [String] The path to the fake executable that should be used.
|
236
|
+
#
|
237
|
+
# Note: Calling this method will set a mocha expectation
|
238
|
+
# that the Sprout::Executable.load method will be called during
|
239
|
+
# the test method run.
|
240
|
+
#
|
241
|
+
def insert_fake_executable fake
|
242
|
+
# Comment the following and install the flashsdk gem
|
243
|
+
# to run test against actual executables instead of fakes:
|
244
|
+
path_response = OpenStruct.new(:path => fake)
|
245
|
+
Sprout::Executable.expects(:load).returns path_response
|
112
246
|
end
|
113
247
|
|
248
|
+
##
|
249
|
+
# Create and/or return sprout/cache directory relative to the
|
250
|
+
# fixtures folder nearest the file that calls this method.
|
251
|
+
# @return [Dir] The path to the cache directory.
|
114
252
|
def temp_cache
|
115
253
|
dir = File.dirname(Sprout.file_from_caller(caller.first))
|
116
254
|
@temp_cache ||= File.join(fixtures(dir), 'sprout', 'cache')
|
117
255
|
end
|
118
256
|
|
257
|
+
##
|
258
|
+
# Execute a block as each available Sprout::System, any code
|
259
|
+
# within this block that calls Sprout.current_user will
|
260
|
+
# receive the currently active Sprout::System.
|
261
|
+
#
|
262
|
+
# as_each_system do
|
263
|
+
# puts ">> Sprout.home: #{Sprout.home}"
|
264
|
+
# end
|
265
|
+
#
|
266
|
+
# This method is primarily used to ensure that we create
|
267
|
+
# system-appropriate paths and processes.
|
268
|
+
#
|
269
|
+
# NOTE: This process automatically calls Mocha::Mockery.instance.teardown
|
270
|
+
# after the yield. This means that any mocks that have been created will
|
271
|
+
# no longer be available after the provided block is complete.
|
272
|
+
#
|
273
|
+
# @return [Sprout::System::BaseSystem] The concrete class that was created.
|
274
|
+
# @yield [Sprout::System::BaseSystem] The concrete subclass of BaseSystem
|
275
|
+
#
|
119
276
|
def as_each_system
|
120
277
|
[
|
121
278
|
Sprout::System::VistaSystem.new,
|
@@ -131,9 +288,19 @@ module SproutTestCase # :nodoc:[all]
|
|
131
288
|
# Doing it anyway b/c we need to get Windows support in place...
|
132
289
|
# TODO: Implement this feature without clobbering all stubs/mocks
|
133
290
|
Mocha::Mockery.instance.teardown
|
291
|
+
sys
|
134
292
|
end
|
135
293
|
end
|
136
294
|
|
295
|
+
##
|
296
|
+
# Execute a block as a UnixSystem.
|
297
|
+
#
|
298
|
+
# as_a_unix_system do
|
299
|
+
# puts ">> Sprout.home: #{Sprout.home}"
|
300
|
+
# end
|
301
|
+
#
|
302
|
+
# @return [Sprout::System::UnixSystem] The Sprout::System that was created.
|
303
|
+
# @yield [Sprout::System::UnixSystem] The current Sprout::System.
|
137
304
|
def as_a_unix_system
|
138
305
|
sys = Sprout::System::UnixSystem.new
|
139
306
|
expectation = Sprout::System.stubs(:create).returns sys
|
@@ -142,8 +309,18 @@ module SproutTestCase # :nodoc:[all]
|
|
142
309
|
# Doing it anyway b/c we need to get Windows support in place...
|
143
310
|
# TODO: Implement this feature without clobbering all stubs/mocks
|
144
311
|
#Mocha::Mockery.instance.teardown
|
312
|
+
sys
|
145
313
|
end
|
146
314
|
|
315
|
+
##
|
316
|
+
# Execute a block as a OSXSystem.
|
317
|
+
#
|
318
|
+
# as_a_mac_system do
|
319
|
+
# puts ">> Sprout.home: #{Sprout.home}"
|
320
|
+
# end
|
321
|
+
#
|
322
|
+
# @return [Sprout::System::OSXSystem] The Sprout::System that was created.
|
323
|
+
# @yield [Sprout::System::OSXSystem] The current Sprout::System.
|
147
324
|
def as_a_mac_system
|
148
325
|
sys = Sprout::System::OSXSystem.new
|
149
326
|
Sprout::System.stubs(:create).returns sys
|
@@ -152,8 +329,18 @@ module SproutTestCase # :nodoc:[all]
|
|
152
329
|
# Doing it anyway b/c we need to get Windows support in place...
|
153
330
|
# TODO: Implement this feature without clobbering all stubs/mocks
|
154
331
|
#Mocha::Mockery.instance.teardown
|
332
|
+
sys
|
155
333
|
end
|
156
334
|
|
335
|
+
##
|
336
|
+
# Execute a block as a WinSystem.
|
337
|
+
#
|
338
|
+
# as_a_windows_system do
|
339
|
+
# puts ">> Sprout.home: #{Sprout.home}"
|
340
|
+
# end
|
341
|
+
#
|
342
|
+
# @return [Sprout::System::WinSystem] The Sprout::System that was created.
|
343
|
+
# @yield [Sprout::System::WinSystem] The current Sprout::System.
|
157
344
|
def as_a_windows_system
|
158
345
|
sys = Sprout::System::WinSystem.new
|
159
346
|
Sprout::System.stubs(:create).returns sys
|
@@ -162,8 +349,18 @@ module SproutTestCase # :nodoc:[all]
|
|
162
349
|
# Doing it anyway b/c we need to get Windows support in place...
|
163
350
|
# TODO: Implement this feature without clobbering all stubs/mocks
|
164
351
|
#Mocha::Mockery.instance.teardown
|
352
|
+
sys
|
165
353
|
end
|
166
354
|
|
355
|
+
##
|
356
|
+
# Execute a block as a WinNixSystem.
|
357
|
+
#
|
358
|
+
# as_a_win_nix_system do
|
359
|
+
# puts ">> Sprout.home: #{Sprout.home}"
|
360
|
+
# end
|
361
|
+
#
|
362
|
+
# @return [Sprout::System::WinNixSystem] The Sprout::System that was created.
|
363
|
+
# @yield [Sprout::System::WinNixSystem] The current Sprout::System.
|
167
364
|
def as_a_win_nix_system
|
168
365
|
sys = Sprout::System::WinNixSystem.new
|
169
366
|
Sprout::System.stubs(:create).returns sys
|
@@ -172,11 +369,13 @@ module SproutTestCase # :nodoc:[all]
|
|
172
369
|
# Doing it anyway b/c we need to get Windows support in place...
|
173
370
|
# TODO: Implement this feature without clobbering all stubs/mocks
|
174
371
|
#Mocha::Mockery.instance.teardown
|
372
|
+
sys
|
175
373
|
end
|
176
374
|
|
177
375
|
|
178
376
|
private
|
179
377
|
|
378
|
+
##
|
180
379
|
# Find the nearest fixtures folder to the provided
|
181
380
|
# path by checking each parent directory.
|
182
381
|
def find_fixtures path
|
@@ -225,8 +424,9 @@ end
|
|
225
424
|
# bare_setup - place this in setup method to create the app_root folder for each test
|
226
425
|
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or app_root folder after each test
|
227
426
|
|
228
|
-
|
229
427
|
# Prevent log messages from interrupting the test output:
|
230
|
-
Sprout
|
428
|
+
Sprout.stdout = Sprout.stdout_test
|
429
|
+
Sprout.stderr = Sprout.stderr_test
|
430
|
+
|
231
431
|
#Sprout::ProgressBar.debug = true
|
232
432
|
|