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,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RemoteFileLoaderTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "The remote file loader" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@uri = 'http://github.com/downloads/lukebayes/project-sprouts/echochamber-test.zip'
|
10
|
+
@file = File.join fixtures, 'remote_file_loader', 'md5', 'echochamber-test.zip'
|
11
|
+
@md5 = 'd6939117f1df58e216f365a12fec64f9'
|
12
|
+
|
13
|
+
# Don't reach out to the network for these tests:
|
14
|
+
Sprout::RemoteFileLoader.stubs(:fetch).returns File.read @file
|
15
|
+
end
|
16
|
+
|
17
|
+
should "attempt to load a requested file" do
|
18
|
+
bytes = Sprout::RemoteFileLoader.load @uri, @md5
|
19
|
+
assert_equal 310, bytes.size
|
20
|
+
end
|
21
|
+
|
22
|
+
should "fail if md5 doesn't match" do
|
23
|
+
Sprout::RemoteFileLoader.expects(:prompt_for_md5_failure)
|
24
|
+
Sprout::RemoteFileLoader.load @uri, 'abcd'
|
25
|
+
end
|
26
|
+
|
27
|
+
should "pass if md5 isn't provided" do
|
28
|
+
Sprout::RemoteFileLoader.expects(:prompt_for_md5_failure).never
|
29
|
+
Sprout::RemoteFileLoader.load @uri
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RemoteFileTargetTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "an improperly configured remote file target" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
Sprout::RemoteFileTarget.any_instance.stubs(:load_archive).returns true
|
10
|
+
end
|
11
|
+
|
12
|
+
should "throw validation error on archive_type" do
|
13
|
+
assert_raises Sprout::Errors::ValidationError do
|
14
|
+
t = Sprout::RemoteFileTarget.new
|
15
|
+
#t.archive_type = :zip # This causes the validation error
|
16
|
+
t.md5 = 'abcd'
|
17
|
+
t.url = 'http://google.com'
|
18
|
+
t.pkg_name = 'google'
|
19
|
+
t.pkg_version = '1.0.0'
|
20
|
+
|
21
|
+
t.resolve
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
should "throw validation error on md5" do
|
26
|
+
assert_raises Sprout::Errors::ValidationError do
|
27
|
+
t = Sprout::RemoteFileTarget.new
|
28
|
+
t.archive_type = :zip
|
29
|
+
#t.md5 = 'abcd' # This causes the validation error
|
30
|
+
t.url = 'http://google.com'
|
31
|
+
t.pkg_name = 'google'
|
32
|
+
t.pkg_version = '1.0.0'
|
33
|
+
|
34
|
+
t.resolve
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
should "throw validation error on url" do
|
39
|
+
assert_raises Sprout::Errors::ValidationError do
|
40
|
+
t = Sprout::RemoteFileTarget.new
|
41
|
+
t.archive_type = :zip
|
42
|
+
t.md5 = 'abcd'
|
43
|
+
#t.url = 'http://google.com' # This causes the validation error
|
44
|
+
t.pkg_name = 'google'
|
45
|
+
t.pkg_version = '1.0.0'
|
46
|
+
|
47
|
+
t.resolve
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "a correctly configured remote file target" do
|
53
|
+
|
54
|
+
setup do
|
55
|
+
@target = Sprout::RemoteFileTarget.new do |t|
|
56
|
+
t.archive_type = :zip
|
57
|
+
t.md5 = 'd6939117f1df58e216f365a12fec64f9'
|
58
|
+
t.url = 'http://github.com/downloads/lukebayes/project-sprouts/echochamber-test.zip'
|
59
|
+
t.pkg_name = 'echochamber'
|
60
|
+
t.pkg_version = '1.0.pre'
|
61
|
+
t.add_executable :echochamber, 'bin/echochamber.sh'
|
62
|
+
end
|
63
|
+
|
64
|
+
@unpacked_file = File.join(temp_cache, 'unpacked')
|
65
|
+
@target.stubs(:unpacked_file).returns @unpacked_file
|
66
|
+
|
67
|
+
@downloaded_file = File.join(temp_cache, 'downloaded.zip')
|
68
|
+
@target.stubs(:downloaded_file).returns @downloaded_file
|
69
|
+
|
70
|
+
@archive_bytes = File.read(File.join(fixtures, 'remote_file_target', 'echochamber-test.zip'))
|
71
|
+
end
|
72
|
+
|
73
|
+
context "that has already been UNPACKED" do
|
74
|
+
should "not be DOWNLOADED or unpacked" do
|
75
|
+
create_file @unpacked_file
|
76
|
+
@target.expects(:download_archive).never
|
77
|
+
@target.expects(:unpack_archive).never
|
78
|
+
@target.resolve
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "that has been DOWNLOADED, but not UNPACKED" do
|
83
|
+
should "unpack but not download" do
|
84
|
+
create_file @downloaded_file
|
85
|
+
@target.expects(:download_archive).never
|
86
|
+
@target.expects(:unpack_archive)
|
87
|
+
@target.resolve
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "that has not yet been DOWNLOADED, or UNPACKED" do
|
92
|
+
should "download and unpack the remote archive" do
|
93
|
+
@target.expects(:download_archive).returns @archive_bytes
|
94
|
+
#@target.expects(:unpack_archive)
|
95
|
+
|
96
|
+
@target.resolve
|
97
|
+
assert_file @downloaded_file
|
98
|
+
assert_file @unpacked_file
|
99
|
+
#assert_not_empty @unpacked_file
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class RubyFeatureTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "a new ruby feature" do
|
7
|
+
|
8
|
+
teardown do
|
9
|
+
FakePlugin.clear_entities!
|
10
|
+
end
|
11
|
+
|
12
|
+
should "allow register" do
|
13
|
+
# Shouldn't require the package since it's already
|
14
|
+
# registered and available...
|
15
|
+
FakePlugin.expects(:require_ruby_package).never
|
16
|
+
plugin = create_item
|
17
|
+
FakePlugin.register plugin
|
18
|
+
assert_equal plugin, FakePlugin.load(:foo, 'sprout/base')
|
19
|
+
end
|
20
|
+
|
21
|
+
should "return nil if nothing is registered" do
|
22
|
+
FakePlugin.expects :require_ruby_package
|
23
|
+
assert_raises Sprout::Errors::LoadError do
|
24
|
+
FakePlugin.load(:foo, 'sprout/base')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should "find the correct registered plugin" do
|
29
|
+
foo = create_item
|
30
|
+
bar = create_item :name => :bar
|
31
|
+
FakePlugin.register foo
|
32
|
+
FakePlugin.register bar
|
33
|
+
assert_equal bar, FakePlugin.load(:bar)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not share registrations among includers" do
|
37
|
+
foo = create_item
|
38
|
+
FakePlugin.register foo
|
39
|
+
assert_raises Sprout::Errors::LoadError do
|
40
|
+
OtherFakePlugin.load :foo
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "allow registration and load without ruby package or version" do
|
45
|
+
FakePlugin.register OpenStruct.new({:name => :foo2})
|
46
|
+
assert_not_nil FakePlugin.load :foo2
|
47
|
+
end
|
48
|
+
|
49
|
+
should "allow registration and match with nil pkg_name" do
|
50
|
+
FakePlugin.register(create_item(:pkg_name => nil))
|
51
|
+
assert_not_nil FakePlugin.load :foo
|
52
|
+
end
|
53
|
+
|
54
|
+
should "allow registration and match with nil pkg_version" do
|
55
|
+
FakePlugin.register(create_item(:pkg_version => nil))
|
56
|
+
assert_not_nil FakePlugin.load :foo
|
57
|
+
end
|
58
|
+
|
59
|
+
should "allow registration and match with nil platform" do
|
60
|
+
FakePlugin.register(create_item(:platform => nil))
|
61
|
+
assert_not_nil FakePlugin.load :foo
|
62
|
+
end
|
63
|
+
|
64
|
+
should "not allow registration with nil name" do
|
65
|
+
assert_raises Sprout::Errors::UsageError do
|
66
|
+
FakePlugin.register(create_item(:name => nil))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
should "load when request is a string" do
|
71
|
+
FakePlugin.register(OpenStruct.new({:name => :foo3}))
|
72
|
+
assert_not_nil FakePlugin.load 'foo3'
|
73
|
+
end
|
74
|
+
|
75
|
+
should "load when registration is a string" do
|
76
|
+
FakePlugin.register(OpenStruct.new({:name => :swc, :pkg_name => 'asunit4'}))
|
77
|
+
assert_not_nil FakePlugin.load nil, :asunit4
|
78
|
+
end
|
79
|
+
|
80
|
+
should "raise on failure to find from collection" do
|
81
|
+
FakePlugin.register(create_item)
|
82
|
+
assert_raises Sprout::Errors::LoadError do
|
83
|
+
FakePlugin.load [:bar, :baz]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
should "allow load with collection of names" do
|
88
|
+
FakePlugin.register(create_item)
|
89
|
+
assert_not_nil FakePlugin.load [:bar, :baz, :foo]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def create_item options={}
|
96
|
+
OpenStruct.new({:name => :foo, :pkg_name => 'sprout/base', :pkg_version => '1.0.pre', :platform => :universal}.merge(options))
|
97
|
+
end
|
98
|
+
|
99
|
+
class FakePlugin
|
100
|
+
include Sprout::RubyFeature
|
101
|
+
end
|
102
|
+
|
103
|
+
class OtherFakePlugin
|
104
|
+
include Sprout::RubyFeature
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
require 'sprout/generators/ruby/ruby_generator'
|
4
|
+
|
5
|
+
class RubyGeneratorTest < Test::Unit::TestCase
|
6
|
+
include SproutTestCase
|
7
|
+
|
8
|
+
context "A generated ruby application" do
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@temp = File.join(fixtures, 'generators', 'ruby')
|
12
|
+
FileUtils.mkdir_p @temp
|
13
|
+
@generator = Sprout::RubyGenerator.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 ruby application" do
|
23
|
+
@generator.input = 'SomeProject'
|
24
|
+
@generator.version = '4.2.pre'
|
25
|
+
@generator.lib = 'libs'
|
26
|
+
@generator.execute
|
27
|
+
|
28
|
+
project_dir = File.join @temp, 'some_project'
|
29
|
+
assert_file project_dir
|
30
|
+
|
31
|
+
gem_file = File.join project_dir, 'Gemfile'
|
32
|
+
assert_file gem_file
|
33
|
+
|
34
|
+
lib_dir = File.join project_dir, 'libs'
|
35
|
+
assert_file lib_dir
|
36
|
+
|
37
|
+
module_file = File.join lib_dir, 'some_project.rb'
|
38
|
+
assert_file module_file do |content|
|
39
|
+
assert_matches /VERSION/, content
|
40
|
+
assert_matches /4.2.pre/, content
|
41
|
+
end
|
42
|
+
|
43
|
+
classes_dir = File.join lib_dir, 'some_project'
|
44
|
+
assert_file classes_dir
|
45
|
+
|
46
|
+
main_file = File.join classes_dir, 'base.rb'
|
47
|
+
assert_file main_file
|
48
|
+
|
49
|
+
test_dir = File.join project_dir, 'test'
|
50
|
+
assert_file test_dir
|
51
|
+
|
52
|
+
unit_dir = File.join test_dir, 'unit'
|
53
|
+
assert_file unit_dir
|
54
|
+
|
55
|
+
fixtures_dir = File.join test_dir, 'fixtures'
|
56
|
+
assert_file fixtures_dir
|
57
|
+
|
58
|
+
bin_dir = File.join project_dir, 'bin'
|
59
|
+
assert_file bin_dir
|
60
|
+
|
61
|
+
exe_file = File.join bin_dir, 'some-project'
|
62
|
+
assert_file exe_file do |content|
|
63
|
+
assert_matches /some_project/, content
|
64
|
+
assert_matches /SomeProject::Base.new/, content
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class SpecificationTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "a newly defined specification" do
|
7
|
+
setup do
|
8
|
+
@spec = Sprout::Specification.new do |s|
|
9
|
+
s.version = '1.0.pre'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
should "have a default name" do
|
14
|
+
assert_equal 'specification_test', @spec.name
|
15
|
+
end
|
16
|
+
|
17
|
+
should "accept the version" do
|
18
|
+
assert_equal '1.0.pre', @spec.version
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with a new name" do
|
22
|
+
setup do
|
23
|
+
@spec.name = 'foo_sdk'
|
24
|
+
@spec.version = '1.0.pre'
|
25
|
+
end
|
26
|
+
|
27
|
+
should "register executables" do
|
28
|
+
@spec.add_file_target do |t|
|
29
|
+
t.add_executable :foo, 'bin/foo'
|
30
|
+
end
|
31
|
+
|
32
|
+
Sprout::Executable.stubs :require_ruby_package
|
33
|
+
assert_not_nil Sprout::Executable.load :foo, 'foo_sdk', '1.0.pre'
|
34
|
+
end
|
35
|
+
|
36
|
+
should "load returns libraries in expected order" do
|
37
|
+
@spec.add_file_target do |t|
|
38
|
+
t.add_library :swc, 'bin/foo'
|
39
|
+
t.add_library :src, 'bin/bar'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Without specifying the :swc/:src decision:
|
43
|
+
library = Sprout::Library.load nil, 'foo_sdk'
|
44
|
+
assert_equal 'foo', File.basename(library.path)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "a newly included executable" do
|
52
|
+
setup do
|
53
|
+
@echo_chamber = File.join fixtures, 'executable', 'echochamber_gem', 'echo_chamber'
|
54
|
+
$:.unshift File.dirname(@echo_chamber)
|
55
|
+
end
|
56
|
+
|
57
|
+
teardown do
|
58
|
+
$:.shift
|
59
|
+
end
|
60
|
+
|
61
|
+
should "require the sproutspec" do
|
62
|
+
path = Sprout::Executable.load(:echos, 'echo_chamber').path
|
63
|
+
assert_matches /fixtures\/.*echochamber/, path
|
64
|
+
assert_file path
|
65
|
+
|
66
|
+
# TODO: We should be able to execute
|
67
|
+
# the provided executable!
|
68
|
+
#response = Sprout::System.create.execute path
|
69
|
+
#assert_equal 'ECHO ECHO ECHO', response
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class SproutTest < Test::Unit::TestCase
|
4
|
+
include SproutTestCase
|
5
|
+
|
6
|
+
context "Errors" do
|
7
|
+
include Sprout::Errors
|
8
|
+
|
9
|
+
[
|
10
|
+
ArchiveUnpackerError,
|
11
|
+
DestinationExistsError,
|
12
|
+
ExecutionError,
|
13
|
+
ExecutableRegistrationError,
|
14
|
+
MissingExecutableError,
|
15
|
+
ProcessRunnerError,
|
16
|
+
SproutError,
|
17
|
+
ExecutableError,
|
18
|
+
UnknownArchiveType,
|
19
|
+
UsageError,
|
20
|
+
VersionRequirementNotMetError
|
21
|
+
].each do |error|
|
22
|
+
|
23
|
+
should "be available to instiate a #{error.to_s}" do
|
24
|
+
error.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "cache" do
|
30
|
+
setup do
|
31
|
+
@library = File.join(fixtures, 'sprout')
|
32
|
+
end
|
33
|
+
|
34
|
+
should "find library from system" do
|
35
|
+
user = Sprout::System::OSXSystem.new
|
36
|
+
user.stubs(:library).returns @library
|
37
|
+
Sprout.stubs(:current_system).returns user
|
38
|
+
|
39
|
+
expected_cache = File.join(@library, 'Sprouts', Sprout::VERSION::MAJOR_MINOR, 'cache')
|
40
|
+
assert_equal expected_cache, Sprout.cache
|
41
|
+
end
|
42
|
+
|
43
|
+
should "find library for unix system" do
|
44
|
+
user = Sprout::System::UnixSystem.new
|
45
|
+
user.stubs(:library).returns @library
|
46
|
+
Sprout.stubs(:current_system).returns user
|
47
|
+
|
48
|
+
expected_cache = File.join(@library, '.sprouts', Sprout::VERSION::MAJOR_MINOR, 'cache')
|
49
|
+
assert_equal expected_cache, Sprout.cache
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "A new sprout test case" do
|
54
|
+
|
55
|
+
should "be able to work as a particular user but then revert when done" do
|
56
|
+
original_class = Sprout.current_system.class
|
57
|
+
|
58
|
+
block_called = false
|
59
|
+
|
60
|
+
systems = [
|
61
|
+
Sprout::System::VistaSystem,
|
62
|
+
Sprout::System::WinNixSystem,
|
63
|
+
Sprout::System::WinSystem,
|
64
|
+
Sprout::System::JavaSystem,
|
65
|
+
Sprout::System::OSXSystem,
|
66
|
+
Sprout::System::UnixSystem
|
67
|
+
]
|
68
|
+
incr = 0
|
69
|
+
|
70
|
+
as_each_system do |sys|
|
71
|
+
block_called = true
|
72
|
+
assert_equal systems[incr], Sprout.current_system.class, "Requests for the current system should yield a UNIX system"
|
73
|
+
incr += 1
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_equal original_class, Sprout.current_system.class
|
77
|
+
assert block_called, "Ensure the block was yielded to..."
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "Executables" do
|
82
|
+
|
83
|
+
context "with a sandboxed load path" do
|
84
|
+
|
85
|
+
setup do
|
86
|
+
path = File.join fixtures, "executable", "flex3sdk_gem"
|
87
|
+
$:.unshift path
|
88
|
+
end
|
89
|
+
|
90
|
+
teardown do
|
91
|
+
$:.shift
|
92
|
+
end
|
93
|
+
|
94
|
+
should "find requested executables" do
|
95
|
+
path = Sprout::Executable.load(:mxmlc, 'flex3sdk', '>= 3.0.0').path
|
96
|
+
assert_not_nil path
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with a stubbed load path" do
|
101
|
+
|
102
|
+
setup do
|
103
|
+
Sprout::Executable.stubs(:require_ruby_package).returns true
|
104
|
+
@path = 'test/fixtures/process_runner/chmod_script.sh'
|
105
|
+
end
|
106
|
+
|
107
|
+
should "work when registered with different gem names" do
|
108
|
+
register_executable :mxmlc, 'flex3sdk', '1.0.pre', @path
|
109
|
+
register_executable :mxmlc, 'flex4sdk', '1.0.pre', @path
|
110
|
+
end
|
111
|
+
|
112
|
+
should "work when registered with different exe names" do
|
113
|
+
register_executable :mxmlc, 'flex3sdk', '1.0.pre', @path
|
114
|
+
register_executable :compc, 'flex3sdk', '1.0.pre', @path
|
115
|
+
end
|
116
|
+
|
117
|
+
context "that are registered" do
|
118
|
+
should "work the first time" do
|
119
|
+
register_executable :mxmlc, 'flex3sdk', '1.0.pre', @path
|
120
|
+
end
|
121
|
+
|
122
|
+
context "and then requested" do
|
123
|
+
setup do
|
124
|
+
register_executable :mxmlc, 'flex3sdk', '1.0.pre', @path
|
125
|
+
end
|
126
|
+
|
127
|
+
should "succeed if the executable is available and no version specified" do
|
128
|
+
assert_equal @path, Sprout::Executable.load(:mxmlc, 'flex3sdk').path
|
129
|
+
end
|
130
|
+
|
131
|
+
should "succeed if version requirement is met" do
|
132
|
+
assert_equal @path, Sprout::Executable.load(:mxmlc, 'flex3sdk', '>= 1.0.pre').path
|
133
|
+
end
|
134
|
+
|
135
|
+
should "fail if version requirement is not met" do
|
136
|
+
assert_raises Sprout::Errors::LoadError do
|
137
|
+
Sprout::Executable.load :mxmlc, 'flex3sdk', '>= 1.1.0'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "that are not registered" do
|
145
|
+
should "fail when requested" do
|
146
|
+
assert_raises Sprout::Errors::LoadError do
|
147
|
+
Sprout::Executable.load :mxmlc, 'flex3sdk'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def register_executable name, pkg_name, pkg_version, path, platform=:universal
|
158
|
+
exe = OpenStruct.new({
|
159
|
+
:name => name,
|
160
|
+
:path => path,
|
161
|
+
:pkg_name => pkg_name,
|
162
|
+
:pkg_version => pkg_version,
|
163
|
+
:platform => platform
|
164
|
+
})
|
165
|
+
Sprout::Executable.register exe
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
|