sprout 0.7.246 → 1.0.0.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/CHANGELOG.md +10 -0
- data/Gemfile +28 -0
- data/MIT-LICENSE +3 -2
- data/POSTINSTALL.rdoc +28 -0
- data/README.textile +152 -0
- data/bin/sprout +1 -131
- data/bin/sprout-generator +10 -0
- data/bin/sprout-library +11 -0
- data/bin/sprout-tool +10 -0
- data/lib/sprout.rb +4 -500
- data/lib/sprout/archive_unpacker.rb +122 -206
- data/lib/sprout/base.rb +90 -0
- data/lib/sprout/concern.rb +30 -0
- data/lib/sprout/dir.rb +23 -0
- data/lib/sprout/errors.rb +94 -0
- data/lib/sprout/executable.rb +496 -0
- data/lib/sprout/executable/boolean.rb +35 -0
- data/lib/sprout/executable/collection_param.rb +53 -0
- data/lib/sprout/executable/file_param.rb +53 -0
- data/lib/sprout/executable/files.rb +26 -0
- data/lib/sprout/executable/number.rb +10 -0
- data/lib/sprout/executable/param.rb +222 -0
- data/lib/sprout/executable/parameter_factory.rb +28 -0
- data/lib/sprout/executable/path.rb +21 -0
- data/lib/sprout/executable/paths.rb +21 -0
- data/lib/sprout/executable/string_param.rb +15 -0
- data/lib/sprout/executable/strings.rb +11 -0
- data/lib/sprout/executable/url.rb +10 -0
- data/lib/sprout/executable/urls.rb +10 -0
- data/lib/sprout/file_target.rb +76 -0
- data/lib/sprout/generator/base.rb +233 -0
- data/lib/sprout/generator/command.rb +67 -0
- data/lib/sprout/generator/directory_manifest.rb +49 -0
- data/lib/sprout/generator/file_manifest.rb +55 -0
- data/lib/sprout/generator/manifest.rb +13 -0
- data/lib/sprout/generator/template_manifest.rb +13 -0
- data/lib/sprout/generators/generator/generator_generator.rb +48 -0
- data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
- data/lib/sprout/generators/generator/templates/generator_executable +9 -0
- data/lib/sprout/generators/generator/templates/generator_template +1 -0
- data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
- data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
- data/lib/sprout/generators/library/library_generator.rb +20 -0
- data/lib/sprout/generators/library/templates/library.gemspec +19 -0
- data/lib/sprout/generators/library/templates/library.rb +15 -0
- data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
- data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
- data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
- data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
- data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
- data/lib/sprout/generators/tool/templates/Gemfile +4 -0
- data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
- data/lib/sprout/generators/tool/templates/tool.rb +38 -0
- data/lib/sprout/generators/tool/tool_generator.rb +36 -0
- data/lib/sprout/library.rb +111 -0
- data/lib/sprout/log.rb +1 -0
- data/lib/sprout/platform.rb +71 -0
- data/lib/sprout/process_runner.rb +80 -40
- data/lib/sprout/progress_bar.rb +341 -0
- data/lib/sprout/rdoc_parser.rb +91 -0
- data/lib/sprout/remote_file_loader.rb +72 -50
- data/lib/sprout/remote_file_target.rb +44 -152
- data/lib/sprout/ruby_feature.rb +167 -0
- data/lib/sprout/specification.rb +197 -0
- data/lib/sprout/string.rb +19 -0
- data/lib/sprout/system.rb +35 -0
- data/lib/sprout/system/base_system.rb +225 -0
- data/lib/sprout/system/java_system.rb +9 -0
- data/lib/sprout/system/osx_system.rb +26 -0
- data/lib/sprout/system/unix_system.rb +72 -0
- data/lib/sprout/system/vista_system.rb +16 -0
- data/lib/sprout/system/win_nix_system.rb +41 -0
- data/lib/sprout/system/win_system.rb +76 -0
- data/lib/sprout/test/sprout_test_case.rb +211 -0
- data/lib/sprout/version.rb +9 -4
- data/rakefile.rb +85 -144
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/sprout.gemspec +26 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
- data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
- data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
- data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
- data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
- data/test/fixtures/examples/app_generator.rb +127 -0
- data/test/fixtures/examples/echo_inputs.rb +151 -0
- data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
- data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
- data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
- data/test/fixtures/executable/mxmlc.rb +805 -0
- data/test/fixtures/executable/params/input.as +0 -0
- data/test/fixtures/executable/params/input2.as +0 -0
- data/test/fixtures/executable/params/input3.as +0 -0
- data/test/fixtures/executable/params/mxmlc +5 -0
- data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
- data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
- data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
- data/test/fixtures/executable/paths/folder1/file1 +0 -0
- data/test/fixtures/executable/paths/folder1/file2 +0 -0
- data/test/fixtures/executable/paths/folder1/file3 +0 -0
- data/test/fixtures/executable/paths/folder2/file4 +0 -0
- data/test/fixtures/executable/paths/folder2/file5 +0 -0
- data/test/fixtures/executable/paths/folder3/file6 +0 -0
- data/test/fixtures/executable/src/Main.as +0 -0
- data/test/fixtures/executable/windows_line_endings +47 -0
- data/test/fixtures/generators/song_generator.rb +11 -0
- data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
- data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
- data/test/fixtures/generators/temp_generator.rb +24 -0
- data/test/fixtures/generators/templates/Main.as +9 -0
- data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
- data/test/fixtures/generators/templates/SomeFile +1 -0
- data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
- data/test/fixtures/generators/templates/Song.txt +3 -0
- data/test/fixtures/generators/templates/destroy +0 -0
- data/test/fixtures/generators/templates/generate +0 -0
- data/test/fixtures/library/archive/Archive.swc +0 -0
- data/test/fixtures/library/sources/lib/a/A.as +0 -0
- data/test/fixtures/library/sources/lib/b/B.as +0 -0
- data/test/fixtures/library/sources/src/Source.as +0 -0
- data/test/fixtures/process_runner/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/failure +5 -0
- data/test/fixtures/process_runner/success +4 -0
- data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
- data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
- data/test/fixtures/remote_file_target/bin/echochamber +3 -0
- data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
- data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
- data/test/fixtures/specification/asunit4.rb +25 -0
- data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
- data/test/fixtures/specification/flashplayer.rb +30 -0
- data/test/fixtures/specification/flex4sdk.rb +72 -0
- data/test/fixtures/specification/flexunit4.sproutspec +17 -0
- data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
- data/test/fixtures/specification/src/AsUnit.as +0 -0
- data/test/fixtures/user/mxmlc_crlf +3 -0
- data/test/unit/archive_unpacker_test.rb +108 -0
- data/test/unit/boolean_param_test.rb +38 -0
- data/test/unit/executable_option_parser_test.rb +142 -0
- data/test/unit/executable_param_test.rb +76 -0
- data/test/unit/executable_test.rb +237 -0
- data/test/unit/fake_executable_task.rb +22 -0
- data/test/unit/fake_other_executable.rb +20 -0
- data/test/unit/fake_process_runner.rb +29 -0
- data/test/unit/file_param_test.rb +61 -0
- data/test/unit/file_target_test.rb +42 -0
- data/test/unit/files_param_test.rb +72 -0
- data/test/unit/generator_generator_test.rb +85 -0
- data/test/unit/generator_test.rb +333 -0
- data/test/unit/library_generator_test.rb +41 -0
- data/test/unit/library_test.rb +88 -0
- data/test/unit/osx_system_test.rb +20 -0
- data/test/unit/path_param_test.rb +43 -0
- data/test/unit/paths_param_test.rb +53 -0
- data/test/unit/platform_test.rb +76 -0
- data/test/unit/process_runner_test.rb +104 -0
- data/test/unit/rdoc_parser_test.rb +15 -0
- data/test/unit/remote_file_loader_test.rb +34 -0
- data/test/unit/remote_file_target_test.rb +105 -0
- data/test/unit/ruby_feature_test.rb +108 -0
- data/test/unit/ruby_generator_test.rb +70 -0
- data/test/unit/specification_test.rb +73 -0
- data/test/unit/sprout_test.rb +170 -0
- data/test/unit/sprout_test_helper.rb +18 -0
- data/test/unit/string_param_test.rb +19 -0
- data/test/unit/string_test.rb +20 -0
- data/test/unit/strings_param_test.rb +27 -0
- data/test/unit/test_helper.rb +1 -0
- data/test/unit/tool_generator_test.rb +43 -0
- data/test/unit/unix_system_test.rb +52 -0
- data/test/unit/user_test.rb +147 -0
- data/test/unit/vista_system_test.rb +40 -0
- data/test/unit/win_nix_system_test.rb +26 -0
- data/test/unit/win_system_test.rb +61 -0
- metadata +318 -113
- data/doc/Bundle +0 -14
- data/doc/Generator +0 -35
- data/doc/Library +0 -63
- data/doc/Task +0 -21
- data/doc/Tool +0 -20
- data/lib/platform.rb +0 -113
- data/lib/progress_bar.rb +0 -354
- data/lib/sprout/builder.rb +0 -51
- data/lib/sprout/bundle_resolver.rb +0 -349
- data/lib/sprout/commands/generate.rb +0 -9
- data/lib/sprout/dynamic_accessors.rb +0 -40
- data/lib/sprout/general_tasks.rb +0 -6
- data/lib/sprout/generator.rb +0 -7
- data/lib/sprout/generator/base_mixins.rb +0 -186
- data/lib/sprout/generator/named_base.rb +0 -227
- data/lib/sprout/project_model.rb +0 -278
- data/lib/sprout/simple_resolver.rb +0 -88
- data/lib/sprout/tasks/erb_resolver.rb +0 -118
- data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
- data/lib/sprout/tasks/git_task.rb +0 -134
- data/lib/sprout/tasks/library_task.rb +0 -118
- data/lib/sprout/tasks/sftp_task.rb +0 -248
- data/lib/sprout/tasks/ssh_task.rb +0 -153
- data/lib/sprout/tasks/tool_task.rb +0 -836
- data/lib/sprout/tasks/zip_task.rb +0 -158
- data/lib/sprout/tool_task_model.rb +0 -19
- data/lib/sprout/user.rb +0 -415
- data/lib/sprout/version_file.rb +0 -89
- data/lib/sprout/zip_util.rb +0 -61
- data/samples/gem_wrap/rakefile.rb +0 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
class FakeExecutableTask
|
3
|
+
attr_accessor :output
|
4
|
+
attr_accessor :default_prefix
|
5
|
+
attr_accessor :default_short_prefix
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@output = 'fake_tool'
|
10
|
+
@default_prefix = '-'
|
11
|
+
@default_short_prefix = '--'
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_file_expression
|
15
|
+
@default_file_expression ||= '/**/**/*'
|
16
|
+
end
|
17
|
+
|
18
|
+
def prerequisites
|
19
|
+
@prerequisites ||= []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
class CustomFakeParameter < Sprout::Executable::StringParam; end
|
3
|
+
|
4
|
+
class FakeOtherExecutableTask
|
5
|
+
include Sprout::Executable
|
6
|
+
|
7
|
+
add_param :boolean_param, Boolean
|
8
|
+
add_param :custom_param, CustomFakeParameter
|
9
|
+
add_param :file_param, File
|
10
|
+
add_param :files_param, Files
|
11
|
+
add_param :number_param, Number
|
12
|
+
add_param :path_param, Path
|
13
|
+
add_param :paths_param, Paths
|
14
|
+
add_param :string_param, String
|
15
|
+
add_param :strings_param, Strings
|
16
|
+
add_param :urls_param, Urls
|
17
|
+
|
18
|
+
add_param_alias :sp, :strings_param
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
class FakeProcessRunner
|
3
|
+
|
4
|
+
attr_accessor :command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@r = FakeIO.new
|
8
|
+
@w = FakeIO.new
|
9
|
+
@e = FakeIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute_open4 *command
|
13
|
+
@command = command
|
14
|
+
end
|
15
|
+
|
16
|
+
def read
|
17
|
+
@r
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_err
|
21
|
+
@e
|
22
|
+
end
|
23
|
+
|
24
|
+
def write value
|
25
|
+
@w.write value
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class FileParamTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "a new FileParam" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@input_with_spaces = File.join(fixtures, "executable", "path with spaces", "input.as")
|
10
|
+
@input_with_spaces.gsub!(Dir.pwd + File::SEPARATOR, '')
|
11
|
+
@input_with_escaped_spaces = @input_with_spaces.gsub(' ', '\ ')
|
12
|
+
@input_with_quoted_spaces = "#{@input_with_spaces.gsub('/', '\\')}"
|
13
|
+
|
14
|
+
@input = File.join(fixtures, "executable", "params", "input.as")
|
15
|
+
|
16
|
+
@tool = FakeExecutableTask.new
|
17
|
+
|
18
|
+
@param = Sprout::Executable::FileParam.new
|
19
|
+
@param.belongs_to = @tool
|
20
|
+
@param.name = 'input'
|
21
|
+
@param.value = @input
|
22
|
+
end
|
23
|
+
|
24
|
+
should "clean the path for each system" do
|
25
|
+
as_each_system do |sys|
|
26
|
+
@param.expects(:validate)
|
27
|
+
# Ensure that system.clean_path is called
|
28
|
+
@param.value = @input_with_spaces
|
29
|
+
@param.prepare
|
30
|
+
assert_equal "-input=#{sys.clean_path(@input_with_spaces)}", @param.to_shell
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
should "include file path in shell output" do
|
35
|
+
as_each_system do |sys|
|
36
|
+
assert_equal "-input=#{sys.clean_path(@input)}", @param.to_shell
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "add file as prerequisite to parent" do
|
41
|
+
assert_equal 0, @tool.prerequisites.size
|
42
|
+
@param.prepare
|
43
|
+
assert_equal 1, @tool.prerequisites.size
|
44
|
+
end
|
45
|
+
|
46
|
+
should "not add prerequisite that matches output of parent" do
|
47
|
+
@tool.output = :abcd
|
48
|
+
@param.value = "abcd"
|
49
|
+
@param.prepare
|
50
|
+
assert_equal 0, @tool.prerequisites.size
|
51
|
+
end
|
52
|
+
|
53
|
+
should "raise if the file doesn't exist when asked for output" do
|
54
|
+
@param.value = 'unknown file'
|
55
|
+
assert_raises Sprout::Errors::InvalidArgumentError do
|
56
|
+
@param.to_shell
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class FileTargetTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "a file target" do
|
7
|
+
setup do
|
8
|
+
@asunit_swc = 'bin/AsUnit4-4.1.pre.swc'
|
9
|
+
end
|
10
|
+
|
11
|
+
context "that is created with a constructor block" do
|
12
|
+
should "have the provided values" do
|
13
|
+
target = Sprout::FileTarget.new do |t|
|
14
|
+
t.add_library :swc, @asunit_swc
|
15
|
+
end
|
16
|
+
assert_provided_values target
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "that is created with no constructor block" do
|
21
|
+
should "have the provided values" do
|
22
|
+
target = Sprout::FileTarget.new
|
23
|
+
target.add_library :swc, @asunit_swc
|
24
|
+
assert_provided_values target
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def assert_provided_values t
|
33
|
+
assert_equal :universal, t.platform
|
34
|
+
assert_equal 0, t.executables.size
|
35
|
+
assert_equal 1, t.libraries.size
|
36
|
+
library = t.libraries.first
|
37
|
+
assert_equal :swc, library.name
|
38
|
+
assert_equal File.join('.', @asunit_swc), library.path
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class FilesParamTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "a new FilesParam" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@input1 = File.join(fixtures, "executable", "params", "input.as")
|
10
|
+
@input2 = File.join(fixtures, "executable", "params", "input2.as")
|
11
|
+
@input3 = File.join(fixtures, "executable", "params", "input3.as")
|
12
|
+
|
13
|
+
@input4 = File.join(fixtures, "executable", "path with spaces", "input.as")
|
14
|
+
@input5 = File.join(fixtures, "executable", "path with spaces", "input2.as")
|
15
|
+
@input6 = File.join(fixtures, "executable", "path with spaces", "input3.as")
|
16
|
+
|
17
|
+
@param = Sprout::Executable::Files.new
|
18
|
+
@param.name = 'inputs'
|
19
|
+
@param.belongs_to = FakeExecutableTask.new
|
20
|
+
end
|
21
|
+
|
22
|
+
['abcd', 1234, true].each do |value|
|
23
|
+
should "throw with non-enumerable assignment of #{value}" do
|
24
|
+
assert_raises Sprout::Errors::ExecutableError do
|
25
|
+
@param.value = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
should "allow assignment of enumerables" do
|
31
|
+
@param.value = ['abcd', 'efgh']
|
32
|
+
end
|
33
|
+
|
34
|
+
should "allow concatenation on first access" do
|
35
|
+
@param.value << 'abcd'
|
36
|
+
end
|
37
|
+
|
38
|
+
should "clean each path provided" do
|
39
|
+
# Ensure order is retained:
|
40
|
+
@param.value << @input3
|
41
|
+
@param.value << @input2
|
42
|
+
@param.value << @input1
|
43
|
+
|
44
|
+
as_each_system do |sys|
|
45
|
+
assert_equal "-inputs+=#{sys.clean_path(@input3)} -inputs+=#{sys.clean_path(@input2)} -inputs+=#{sys.clean_path(@input1)}", @param.to_shell, "As a #{sys}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should "clean paths with spaces" do
|
50
|
+
@param.value << @input6
|
51
|
+
@param.value << @input5
|
52
|
+
@param.value << @input4
|
53
|
+
|
54
|
+
as_each_system do |sys|
|
55
|
+
assert_equal "-inputs+=#{sys.clean_path(@input6)} -inputs+=#{sys.clean_path(@input5)} -inputs+=#{sys.clean_path(@input4)}", @param.to_shell, "As a #{sys}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
should "defer to to_shell_proc if provided" do
|
60
|
+
@param.to_shell_proc = Proc.new { |param|
|
61
|
+
"proc:#{param.name}:#{param.value.shift}"
|
62
|
+
}
|
63
|
+
|
64
|
+
@param.value << 'abcd'
|
65
|
+
|
66
|
+
assert "Should be visible", @param.visible?
|
67
|
+
assert_equal 'proc:inputs:abcd', @param.to_shell
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
require 'sprout/generators/generator/generator_generator'
|
4
|
+
|
5
|
+
class GeneratorGeneratorTest < Test::Unit::TestCase
|
6
|
+
include SproutTestCase
|
7
|
+
|
8
|
+
context "A new generator generator" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@temp = File.join(fixtures, 'generators', 'tmp')
|
12
|
+
FileUtils.mkdir_p @temp
|
13
|
+
@generator = Sprout::GeneratorGenerator.new
|
14
|
+
@generator.path = @temp
|
15
|
+
@generator.logger = StringIO.new
|
16
|
+
end
|
17
|
+
|
18
|
+
teardown do
|
19
|
+
remove_file @temp
|
20
|
+
end
|
21
|
+
|
22
|
+
should "generate a new generator" do
|
23
|
+
@generator.input = 'fwee'
|
24
|
+
@generator.execute
|
25
|
+
|
26
|
+
lib_dir = File.join(@temp, 'lib')
|
27
|
+
assert_directory lib_dir
|
28
|
+
|
29
|
+
test_dir = File.join(@temp, 'test')
|
30
|
+
assert_directory test_dir
|
31
|
+
|
32
|
+
#TODO: This should be generated by the library creator
|
33
|
+
# vendor_dir = File.join(@temp, 'vendor')
|
34
|
+
# assert_directory vendor_dir
|
35
|
+
|
36
|
+
fixtures_dir = File.join(test_dir, 'fixtures', 'generators')
|
37
|
+
assert_directory fixtures_dir
|
38
|
+
|
39
|
+
test_file = File.join(test_dir, 'unit', 'fwee_generator_test.rb')
|
40
|
+
assert_file test_file do |content|
|
41
|
+
assert_matches /FweeGeneratorTest/, content
|
42
|
+
end
|
43
|
+
|
44
|
+
test_helper_file = File.join(test_dir, 'unit', 'test_helper.rb')
|
45
|
+
assert_file test_helper_file
|
46
|
+
|
47
|
+
generators_dir = File.join(lib_dir, 'generators')
|
48
|
+
assert_directory generators_dir
|
49
|
+
|
50
|
+
generator_file = File.join(generators_dir, 'fwee_generator.rb')
|
51
|
+
assert_file generator_file
|
52
|
+
|
53
|
+
templates_dir = File.join(generators_dir, 'templates')
|
54
|
+
assert_directory templates_dir
|
55
|
+
|
56
|
+
template_file = File.join(templates_dir, 'fwee.as')
|
57
|
+
assert_file template_file
|
58
|
+
|
59
|
+
bin_dir = File.join(@temp, 'bin')
|
60
|
+
assert_directory bin_dir
|
61
|
+
|
62
|
+
executable_file = File.join(bin_dir, 'fwee')
|
63
|
+
assert_file executable_file
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'generate a new generator in a namespaced directory' do
|
68
|
+
@generator.input = 'fwi'
|
69
|
+
@generator.namespace = 'sigmund'
|
70
|
+
@generator.execute
|
71
|
+
|
72
|
+
lib_dir = File.join(@temp, 'lib')
|
73
|
+
assert_directory lib_dir
|
74
|
+
|
75
|
+
namespace_dir = File.join(lib_dir, 'sigmund')
|
76
|
+
assert_directory namespace_dir
|
77
|
+
|
78
|
+
generator_dir = File.join(namespace_dir, 'generators')
|
79
|
+
assert_directory generator_dir
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,333 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class GeneratorTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "The Sprout::Generator" do
|
7
|
+
|
8
|
+
should "identify a default set of search paths" do
|
9
|
+
File.stubs(:directory?).returns true
|
10
|
+
|
11
|
+
ENV['SPROUT_GENERATORS'] = Dir.pwd
|
12
|
+
paths = Sprout::Generator.search_paths
|
13
|
+
assert_equal File.join('config', 'generators'), paths.shift
|
14
|
+
assert_equal File.join('vendor', 'generators'), paths.shift
|
15
|
+
assert_equal Sprout.generator_cache, paths.shift
|
16
|
+
assert_equal Dir.pwd, paths.shift
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return empty search paths if no defaults are found" do
|
20
|
+
File.stubs(:directory?).returns false
|
21
|
+
paths = Sprout::Generator.search_paths
|
22
|
+
assert_equal [], paths
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "A new application generator" do
|
27
|
+
|
28
|
+
setup do
|
29
|
+
@fixture = File.join fixtures, 'generators', 'fake'
|
30
|
+
@templates = File.join fixtures, 'generators', 'templates'
|
31
|
+
@string_io = StringIO.new
|
32
|
+
@generator = configure_generator FakeGenerator.new
|
33
|
+
|
34
|
+
FileUtils.mkdir_p @fixture
|
35
|
+
end
|
36
|
+
|
37
|
+
teardown do
|
38
|
+
remove_file @fixture
|
39
|
+
end
|
40
|
+
|
41
|
+
context "that is asked to execute/create" do
|
42
|
+
should "default path to pwd" do
|
43
|
+
generator = FakeGenerator.new
|
44
|
+
assert_equal Dir.pwd, generator.path
|
45
|
+
end
|
46
|
+
|
47
|
+
should "create outer directory and file" do
|
48
|
+
@generator.input = 'some_project'
|
49
|
+
@generator.execute
|
50
|
+
project = File.join(@fixture, 'some_project')
|
51
|
+
assert_directory project
|
52
|
+
assert_file File.join(project, 'SomeFile')
|
53
|
+
assert_directory File.join(project, 'src')
|
54
|
+
assert_file File.join(project, 'src', 'SomeProject.as') do |content|
|
55
|
+
assert_matches /public class SomeProject/, content
|
56
|
+
assert_matches /public function SomeProject/, content
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
should "copy templates from the first found template path" do
|
61
|
+
@generator.input = 'some_project'
|
62
|
+
@generator.band_name = 'R.E.M.'
|
63
|
+
@generator.execute
|
64
|
+
assert_file File.join(@fixture, 'some_project', 'SomeFile') do |content|
|
65
|
+
assert_matches /got my Orange Crush - R.E.M./, content
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should "respect updates from subclasses" do
|
70
|
+
@generator = configure_generator SubclassedGenerator.new
|
71
|
+
@generator.input = 'some_project'
|
72
|
+
@generator.execute
|
73
|
+
assert_file File.join(@fixture, 'some_project', 'SomeFile') do |content|
|
74
|
+
assert_matches /Living Jest enough for the City and SomeProject/, content
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
should "use concrete template when provided" do
|
79
|
+
@generator.input = 'some_project'
|
80
|
+
@generator.execute
|
81
|
+
assert_file File.join(@fixture, 'some_project', 'SomeOtherFile') do |content|
|
82
|
+
assert_matches /I've had my fun/, content
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
should "raise missing template error if expected template is not found" do
|
87
|
+
@generator = configure_generator MissingTemplateGenerator.new
|
88
|
+
assert_raises Sprout::Errors::MissingTemplateError do
|
89
|
+
@generator.execute
|
90
|
+
end
|
91
|
+
|
92
|
+
assert !File.exists?(File.join(@fixture, 'some_project')), "Shouldn't leave half-generated files around"
|
93
|
+
end
|
94
|
+
|
95
|
+
should "notify user of all files created" do
|
96
|
+
@generator.input = 'some_project'
|
97
|
+
@string_io.expects(:puts).with('Created directory: ./some_project')
|
98
|
+
@string_io.expects(:puts).with('Created file: ./some_project/SomeFile')
|
99
|
+
@string_io.expects(:puts).with('Created file: ./some_project/SomeOtherFile')
|
100
|
+
@string_io.expects(:puts).with('Created directory: ./some_project/src')
|
101
|
+
@string_io.expects(:puts).with('Created file: ./some_project/src/SomeProject.as')
|
102
|
+
@generator.execute
|
103
|
+
end
|
104
|
+
|
105
|
+
should "not notify if quiet is true" do
|
106
|
+
@generator.input = 'some_project'
|
107
|
+
@generator.quiet = true
|
108
|
+
@string_io.expects(:puts).never
|
109
|
+
@generator.execute
|
110
|
+
end
|
111
|
+
|
112
|
+
should "only have one param in class definition" do
|
113
|
+
assert_equal 2, FakeGenerator.static_parameter_collection.size
|
114
|
+
assert_equal 2, FakeGenerator.static_default_value_collection.size
|
115
|
+
end
|
116
|
+
|
117
|
+
should "not update superclass parameter collection" do
|
118
|
+
assert_equal 6, Sprout::Generator::Base.static_parameter_collection.size
|
119
|
+
assert_equal 1, Sprout::Generator::Base.static_default_value_collection.size
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# TODO: Add ability to prompt the user if requested files already exist,
|
124
|
+
# and force != true
|
125
|
+
end
|
126
|
+
|
127
|
+
context "that is asked to unexecute/delete" do
|
128
|
+
|
129
|
+
setup do
|
130
|
+
@generator.input = 'some_project'
|
131
|
+
@generator.execute
|
132
|
+
|
133
|
+
@project = File.join @fixture, 'some_project'
|
134
|
+
@file = File.join @project, 'SomeFile'
|
135
|
+
|
136
|
+
assert_file File.join(@fixture, 'some_project')
|
137
|
+
end
|
138
|
+
|
139
|
+
should "remove the expected files" do
|
140
|
+
@generator.unexecute
|
141
|
+
assert !File.exists?(@project), "Project should be deleted"
|
142
|
+
end
|
143
|
+
|
144
|
+
should "remove the expected files if destroy == true" do
|
145
|
+
@generator.destroy = true
|
146
|
+
@generator.execute
|
147
|
+
assert !File.exists?(@project), "Project should be deleted"
|
148
|
+
end
|
149
|
+
|
150
|
+
should "not remove files (or their parents) that have been edited" do
|
151
|
+
# Edit the file:
|
152
|
+
File.open @file, 'w+' do |f|
|
153
|
+
f.write "New Content"
|
154
|
+
end
|
155
|
+
|
156
|
+
@generator.unexecute
|
157
|
+
assert !File.exists?(File.join(@project, 'src')), "src dir should be removed"
|
158
|
+
assert_file @file, "Edited files should not be removed"
|
159
|
+
end
|
160
|
+
|
161
|
+
should "remove edited files if force is true" do
|
162
|
+
# Edit the file:
|
163
|
+
File.open @file, 'w+' do |f|
|
164
|
+
f.write "New Content"
|
165
|
+
end
|
166
|
+
|
167
|
+
@generator.force = true
|
168
|
+
@generator.unexecute
|
169
|
+
assert !File.exists?(@project), "Project dir should be removed"
|
170
|
+
end
|
171
|
+
|
172
|
+
should "not remove directories that have files in them" do
|
173
|
+
@file = File.join(@project, 'SomeNewFile.as')
|
174
|
+
File.open(@file, 'w+') do |f|
|
175
|
+
f.write 'New Content'
|
176
|
+
end
|
177
|
+
|
178
|
+
@generator.unexecute
|
179
|
+
assert_file @file, 'New file should not be removed'
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def configure_generator generator
|
188
|
+
generator.input = 'some_project'
|
189
|
+
generator.logger = @string_io
|
190
|
+
generator.path = @fixture
|
191
|
+
generator.templates << @templates
|
192
|
+
generator
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# This is a fake Generator that should
|
197
|
+
# exercise the inputs.
|
198
|
+
class FakeGenerator < Sprout::Generator::Base
|
199
|
+
|
200
|
+
##
|
201
|
+
# Register this generator by input, type and version
|
202
|
+
#register :application, :fake, '1.0.pre'
|
203
|
+
|
204
|
+
##
|
205
|
+
# Some argument for the Fake Generator
|
206
|
+
add_param :band_name, String, { :default => 'Styx' }
|
207
|
+
|
208
|
+
##
|
209
|
+
# Source path
|
210
|
+
add_param :src, String, { :default => 'src' }
|
211
|
+
|
212
|
+
##
|
213
|
+
# The package (usually Gem) name
|
214
|
+
set :pkg_name, 'generator_test'
|
215
|
+
|
216
|
+
##
|
217
|
+
# The package version
|
218
|
+
set :pkg_version, '1.0.pre'
|
219
|
+
|
220
|
+
def class_name
|
221
|
+
@class_name ||= input.camel_case
|
222
|
+
end
|
223
|
+
|
224
|
+
def manifest
|
225
|
+
directory input do
|
226
|
+
template 'SomeFile'
|
227
|
+
template 'SomeOtherFile', 'OtherFileTemplate'
|
228
|
+
directory src do
|
229
|
+
template "#{class_name}.as", 'Main.as'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "an unregistered generator" do
|
236
|
+
|
237
|
+
setup do
|
238
|
+
@generators = File.join fixtures, 'generators'
|
239
|
+
@path = File.join @generators, 'fake'
|
240
|
+
@project = File.join @path, 'SomeProject'
|
241
|
+
$:.unshift @generators
|
242
|
+
end
|
243
|
+
|
244
|
+
teardown do
|
245
|
+
$:.shift
|
246
|
+
remove_file @path
|
247
|
+
end
|
248
|
+
|
249
|
+
should "fail to find unknown generator" do
|
250
|
+
assert_raises Sprout::Errors::LoadError do
|
251
|
+
generator = Sprout::Generator.load :demo, 'unknown_file', '>= 1.0.pre'
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
should "be loadable if it's in the load path" do
|
256
|
+
generator = Sprout::Generator.load :demo, 'temp_generator', '>= 1.0.pre'
|
257
|
+
assert_not_nil generator
|
258
|
+
|
259
|
+
generator.logger = StringIO.new
|
260
|
+
generator.path = @path
|
261
|
+
generator.input = 'SomeProject'
|
262
|
+
generator.execute
|
263
|
+
assert_file @project, "Should have created project folder"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "a generator that is a subclass of another" do
|
268
|
+
# Require the source files for this context
|
269
|
+
require 'test/fixtures/generators/song_generator'
|
270
|
+
require 'test/fixtures/generators/song_subclass/least_favorite'
|
271
|
+
|
272
|
+
setup do
|
273
|
+
@path = File.join(fixtures, 'generators', 'tmp')
|
274
|
+
FileUtils.mkdir_p @path
|
275
|
+
|
276
|
+
@song_generator = SongGenerator.new
|
277
|
+
@song_generator.logger = StringIO.new
|
278
|
+
@song_generator.path = @path
|
279
|
+
|
280
|
+
@least_favorite = LeastFavorite.new
|
281
|
+
@least_favorite.logger = StringIO.new
|
282
|
+
@least_favorite.path = @path
|
283
|
+
end
|
284
|
+
|
285
|
+
teardown do
|
286
|
+
remove_file @path
|
287
|
+
end
|
288
|
+
|
289
|
+
should "select templates from where it's defined - not it's superclass" do
|
290
|
+
@song_generator.favorite = 'I Feel Better'
|
291
|
+
@song_generator.execute
|
292
|
+
assert_file File.join(@path, 'i_feel_better.txt') do |content|
|
293
|
+
assert_matches /Your favorite song is 'I Feel Better'/, content
|
294
|
+
end
|
295
|
+
|
296
|
+
@least_favorite.favorite = 'I Feel Better'
|
297
|
+
@least_favorite.execute
|
298
|
+
assert_file File.join(@path, 'sucky', 'i_feel_better.txt') do |content|
|
299
|
+
assert_matches /Your LEAST favorite song is 'I Feel Better'/, content
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
class SubclassedGenerator < FakeGenerator
|
306
|
+
|
307
|
+
add_param :new_param, String, { :default => 'Other' }
|
308
|
+
|
309
|
+
def manifest
|
310
|
+
super
|
311
|
+
directory input do
|
312
|
+
template 'SomeFile', 'SomeSubclassFile'
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
##
|
318
|
+
# This is a broken generator that should fail
|
319
|
+
# with a MissingTemplateError
|
320
|
+
class MissingTemplateGenerator < Sprout::Generator::Base
|
321
|
+
|
322
|
+
def manifest
|
323
|
+
directory input do
|
324
|
+
template 'FileWithNoTemplate'
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|