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.

Files changed (211) hide show
  1. data/CHANGELOG.md +10 -0
  2. data/Gemfile +28 -0
  3. data/MIT-LICENSE +3 -2
  4. data/POSTINSTALL.rdoc +28 -0
  5. data/README.textile +152 -0
  6. data/bin/sprout +1 -131
  7. data/bin/sprout-generator +10 -0
  8. data/bin/sprout-library +11 -0
  9. data/bin/sprout-tool +10 -0
  10. data/lib/sprout.rb +4 -500
  11. data/lib/sprout/archive_unpacker.rb +122 -206
  12. data/lib/sprout/base.rb +90 -0
  13. data/lib/sprout/concern.rb +30 -0
  14. data/lib/sprout/dir.rb +23 -0
  15. data/lib/sprout/errors.rb +94 -0
  16. data/lib/sprout/executable.rb +496 -0
  17. data/lib/sprout/executable/boolean.rb +35 -0
  18. data/lib/sprout/executable/collection_param.rb +53 -0
  19. data/lib/sprout/executable/file_param.rb +53 -0
  20. data/lib/sprout/executable/files.rb +26 -0
  21. data/lib/sprout/executable/number.rb +10 -0
  22. data/lib/sprout/executable/param.rb +222 -0
  23. data/lib/sprout/executable/parameter_factory.rb +28 -0
  24. data/lib/sprout/executable/path.rb +21 -0
  25. data/lib/sprout/executable/paths.rb +21 -0
  26. data/lib/sprout/executable/string_param.rb +15 -0
  27. data/lib/sprout/executable/strings.rb +11 -0
  28. data/lib/sprout/executable/url.rb +10 -0
  29. data/lib/sprout/executable/urls.rb +10 -0
  30. data/lib/sprout/file_target.rb +76 -0
  31. data/lib/sprout/generator/base.rb +233 -0
  32. data/lib/sprout/generator/command.rb +67 -0
  33. data/lib/sprout/generator/directory_manifest.rb +49 -0
  34. data/lib/sprout/generator/file_manifest.rb +55 -0
  35. data/lib/sprout/generator/manifest.rb +13 -0
  36. data/lib/sprout/generator/template_manifest.rb +13 -0
  37. data/lib/sprout/generators/generator/generator_generator.rb +48 -0
  38. data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
  39. data/lib/sprout/generators/generator/templates/generator_executable +9 -0
  40. data/lib/sprout/generators/generator/templates/generator_template +1 -0
  41. data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
  42. data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
  43. data/lib/sprout/generators/library/library_generator.rb +20 -0
  44. data/lib/sprout/generators/library/templates/library.gemspec +19 -0
  45. data/lib/sprout/generators/library/templates/library.rb +15 -0
  46. data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
  47. data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
  48. data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
  49. data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
  50. data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
  51. data/lib/sprout/generators/tool/templates/Gemfile +4 -0
  52. data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
  53. data/lib/sprout/generators/tool/templates/tool.rb +38 -0
  54. data/lib/sprout/generators/tool/tool_generator.rb +36 -0
  55. data/lib/sprout/library.rb +111 -0
  56. data/lib/sprout/log.rb +1 -0
  57. data/lib/sprout/platform.rb +71 -0
  58. data/lib/sprout/process_runner.rb +80 -40
  59. data/lib/sprout/progress_bar.rb +341 -0
  60. data/lib/sprout/rdoc_parser.rb +91 -0
  61. data/lib/sprout/remote_file_loader.rb +72 -50
  62. data/lib/sprout/remote_file_target.rb +44 -152
  63. data/lib/sprout/ruby_feature.rb +167 -0
  64. data/lib/sprout/specification.rb +197 -0
  65. data/lib/sprout/string.rb +19 -0
  66. data/lib/sprout/system.rb +35 -0
  67. data/lib/sprout/system/base_system.rb +225 -0
  68. data/lib/sprout/system/java_system.rb +9 -0
  69. data/lib/sprout/system/osx_system.rb +26 -0
  70. data/lib/sprout/system/unix_system.rb +72 -0
  71. data/lib/sprout/system/vista_system.rb +16 -0
  72. data/lib/sprout/system/win_nix_system.rb +41 -0
  73. data/lib/sprout/system/win_system.rb +76 -0
  74. data/lib/sprout/test/sprout_test_case.rb +211 -0
  75. data/lib/sprout/version.rb +9 -4
  76. data/rakefile.rb +85 -144
  77. data/script/console +10 -0
  78. data/script/destroy +14 -0
  79. data/script/generate +14 -0
  80. data/sprout.gemspec +26 -0
  81. data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
  82. data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
  83. data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
  84. data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
  85. data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
  86. data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
  87. data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
  88. data/test/fixtures/examples/app_generator.rb +127 -0
  89. data/test/fixtures/examples/echo_inputs.rb +151 -0
  90. data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
  91. data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
  92. data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
  93. data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
  94. data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
  95. data/test/fixtures/executable/mxmlc.rb +805 -0
  96. data/test/fixtures/executable/params/input.as +0 -0
  97. data/test/fixtures/executable/params/input2.as +0 -0
  98. data/test/fixtures/executable/params/input3.as +0 -0
  99. data/test/fixtures/executable/params/mxmlc +5 -0
  100. data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
  101. data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
  102. data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
  103. data/test/fixtures/executable/paths/folder1/file1 +0 -0
  104. data/test/fixtures/executable/paths/folder1/file2 +0 -0
  105. data/test/fixtures/executable/paths/folder1/file3 +0 -0
  106. data/test/fixtures/executable/paths/folder2/file4 +0 -0
  107. data/test/fixtures/executable/paths/folder2/file5 +0 -0
  108. data/test/fixtures/executable/paths/folder3/file6 +0 -0
  109. data/test/fixtures/executable/src/Main.as +0 -0
  110. data/test/fixtures/executable/windows_line_endings +47 -0
  111. data/test/fixtures/generators/song_generator.rb +11 -0
  112. data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
  113. data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
  114. data/test/fixtures/generators/temp_generator.rb +24 -0
  115. data/test/fixtures/generators/templates/Main.as +9 -0
  116. data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
  117. data/test/fixtures/generators/templates/SomeFile +1 -0
  118. data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
  119. data/test/fixtures/generators/templates/Song.txt +3 -0
  120. data/test/fixtures/generators/templates/destroy +0 -0
  121. data/test/fixtures/generators/templates/generate +0 -0
  122. data/test/fixtures/library/archive/Archive.swc +0 -0
  123. data/test/fixtures/library/sources/lib/a/A.as +0 -0
  124. data/test/fixtures/library/sources/lib/b/B.as +0 -0
  125. data/test/fixtures/library/sources/src/Source.as +0 -0
  126. data/test/fixtures/process_runner/chmod_script.sh +3 -0
  127. data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
  128. data/test/fixtures/process_runner/failure +5 -0
  129. data/test/fixtures/process_runner/success +4 -0
  130. data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
  131. data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
  132. data/test/fixtures/remote_file_target/bin/echochamber +3 -0
  133. data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
  134. data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
  135. data/test/fixtures/specification/asunit4.rb +25 -0
  136. data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
  137. data/test/fixtures/specification/flashplayer.rb +30 -0
  138. data/test/fixtures/specification/flex4sdk.rb +72 -0
  139. data/test/fixtures/specification/flexunit4.sproutspec +17 -0
  140. data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
  141. data/test/fixtures/specification/src/AsUnit.as +0 -0
  142. data/test/fixtures/user/mxmlc_crlf +3 -0
  143. data/test/unit/archive_unpacker_test.rb +108 -0
  144. data/test/unit/boolean_param_test.rb +38 -0
  145. data/test/unit/executable_option_parser_test.rb +142 -0
  146. data/test/unit/executable_param_test.rb +76 -0
  147. data/test/unit/executable_test.rb +237 -0
  148. data/test/unit/fake_executable_task.rb +22 -0
  149. data/test/unit/fake_other_executable.rb +20 -0
  150. data/test/unit/fake_process_runner.rb +29 -0
  151. data/test/unit/file_param_test.rb +61 -0
  152. data/test/unit/file_target_test.rb +42 -0
  153. data/test/unit/files_param_test.rb +72 -0
  154. data/test/unit/generator_generator_test.rb +85 -0
  155. data/test/unit/generator_test.rb +333 -0
  156. data/test/unit/library_generator_test.rb +41 -0
  157. data/test/unit/library_test.rb +88 -0
  158. data/test/unit/osx_system_test.rb +20 -0
  159. data/test/unit/path_param_test.rb +43 -0
  160. data/test/unit/paths_param_test.rb +53 -0
  161. data/test/unit/platform_test.rb +76 -0
  162. data/test/unit/process_runner_test.rb +104 -0
  163. data/test/unit/rdoc_parser_test.rb +15 -0
  164. data/test/unit/remote_file_loader_test.rb +34 -0
  165. data/test/unit/remote_file_target_test.rb +105 -0
  166. data/test/unit/ruby_feature_test.rb +108 -0
  167. data/test/unit/ruby_generator_test.rb +70 -0
  168. data/test/unit/specification_test.rb +73 -0
  169. data/test/unit/sprout_test.rb +170 -0
  170. data/test/unit/sprout_test_helper.rb +18 -0
  171. data/test/unit/string_param_test.rb +19 -0
  172. data/test/unit/string_test.rb +20 -0
  173. data/test/unit/strings_param_test.rb +27 -0
  174. data/test/unit/test_helper.rb +1 -0
  175. data/test/unit/tool_generator_test.rb +43 -0
  176. data/test/unit/unix_system_test.rb +52 -0
  177. data/test/unit/user_test.rb +147 -0
  178. data/test/unit/vista_system_test.rb +40 -0
  179. data/test/unit/win_nix_system_test.rb +26 -0
  180. data/test/unit/win_system_test.rb +61 -0
  181. metadata +318 -113
  182. data/doc/Bundle +0 -14
  183. data/doc/Generator +0 -35
  184. data/doc/Library +0 -63
  185. data/doc/Task +0 -21
  186. data/doc/Tool +0 -20
  187. data/lib/platform.rb +0 -113
  188. data/lib/progress_bar.rb +0 -354
  189. data/lib/sprout/builder.rb +0 -51
  190. data/lib/sprout/bundle_resolver.rb +0 -349
  191. data/lib/sprout/commands/generate.rb +0 -9
  192. data/lib/sprout/dynamic_accessors.rb +0 -40
  193. data/lib/sprout/general_tasks.rb +0 -6
  194. data/lib/sprout/generator.rb +0 -7
  195. data/lib/sprout/generator/base_mixins.rb +0 -186
  196. data/lib/sprout/generator/named_base.rb +0 -227
  197. data/lib/sprout/project_model.rb +0 -278
  198. data/lib/sprout/simple_resolver.rb +0 -88
  199. data/lib/sprout/tasks/erb_resolver.rb +0 -118
  200. data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
  201. data/lib/sprout/tasks/git_task.rb +0 -134
  202. data/lib/sprout/tasks/library_task.rb +0 -118
  203. data/lib/sprout/tasks/sftp_task.rb +0 -248
  204. data/lib/sprout/tasks/ssh_task.rb +0 -153
  205. data/lib/sprout/tasks/tool_task.rb +0 -836
  206. data/lib/sprout/tasks/zip_task.rb +0 -158
  207. data/lib/sprout/tool_task_model.rb +0 -19
  208. data/lib/sprout/user.rb +0 -415
  209. data/lib/sprout/version_file.rb +0 -89
  210. data/lib/sprout/zip_util.rb +0 -61
  211. data/samples/gem_wrap/rakefile.rb +0 -17
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class BooleanParamTest < Test::Unit::TestCase
4
+ include SproutTestCase
5
+
6
+ context "a new, simple BooleanParam" do
7
+
8
+ setup do
9
+ @param = Sprout::Executable::Boolean.new
10
+ @param.name = 'foo'
11
+ end
12
+
13
+ should "be hidden when false" do
14
+ @param.value = false
15
+ assert_equal '', @param.to_shell
16
+ end
17
+
18
+ should "default to false" do
19
+ assert_equal false, @param.value
20
+ end
21
+
22
+ should "show on true" do
23
+ @param.value = true
24
+ assert_equal '--foo', @param.to_shell
25
+ end
26
+
27
+ context "when configuring option parser" do
28
+
29
+ should "update correctly" do
30
+ @param.show_on_false = true
31
+ @param.default = true
32
+ @param.hidden_value = false
33
+ assert_equal "--foo [BOOL]", @param.option_parser_declaration
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'test/fixtures/examples/echo_inputs'
3
+
4
+ class ExecutableOptionParserTest < Test::Unit::TestCase
5
+ include SproutTestCase
6
+
7
+ context "a new ruby executable" do
8
+
9
+ setup do
10
+ @exe = EchoInputs.new
11
+ @exe.abort_on_failure = false
12
+ @default_input = '--input=lib/sprout.rb'
13
+ end
14
+
15
+ should "fail without required args" do
16
+ assert_raises Sprout::Errors::MissingArgumentError do
17
+ @exe.parse! []
18
+ end
19
+ end
20
+
21
+ should "accept required args" do
22
+ @exe.parse! [ @default_input ]
23
+ assert_equal 'lib/sprout.rb', @exe.input
24
+ end
25
+
26
+ should "accept boolean with hidden_value" do
27
+ assert !@exe.truthy
28
+ @exe.parse! [ '--truthy', @default_input ]
29
+ assert @exe.truthy
30
+ end
31
+
32
+ should "always accept help option" do
33
+ @exe.expects :puts
34
+ assert_raises SystemExit do
35
+ @exe.parse! [ '--help' ]
36
+ end
37
+ end
38
+
39
+ should "accept false boolean" do
40
+ assert @exe.falsey, "Should be true by default"
41
+ @exe.parse! [@default_input, '--falsey=false']
42
+ assert !@exe.falsey, "Should be false"
43
+ end
44
+
45
+ should "accept string" do
46
+ @exe.parse! [@default_input, '--string=abcd']
47
+ assert_equal 'abcd', @exe.string
48
+ end
49
+
50
+ should "accept file" do
51
+ @exe.parse! [@default_input, '--file=lib/sprout.rb']
52
+ assert_equal 'lib/sprout.rb', @exe.file
53
+ end
54
+
55
+ should "accept files" do
56
+ @exe.parse! [@default_input, '--files+=lib/sprout.rb', '--files+=lib/sprout/log.rb']
57
+ assert_equal ['lib/sprout.rb', 'lib/sprout/log.rb'], @exe.files
58
+ end
59
+
60
+ # TODO: This might not be correct behavior...
61
+ should "accept files with equal sign delimiter" do
62
+ @exe.parse! [@default_input, '--files=lib/sprout.rb', '--files=lib/sprout/log.rb']
63
+ assert_equal ['lib/sprout.rb', 'lib/sprout/log.rb'], @exe.files
64
+ end
65
+
66
+ # TODO: Not sure what's going on here...
67
+ should "configure required arguments" do
68
+ @exe.parse! [@default_input, @default_input]
69
+ assert_equal 'lib/sprout.rb', @exe.input
70
+ end
71
+
72
+ # TODO: This test ensures that the commandline description
73
+ # is pulled from the provided RDocs - but this turns out
74
+ # to be more work than I'm prepared to take on at the moment.
75
+ #
76
+ #should "use rdoc to assign parameter documentation" do
77
+ #skip "Not yet ready to integrate rdoc comments"
78
+ #doc = "A boolean parameter that defaults to true, and must be explicitly set to false in order to turn it off."
79
+ #assert_matches /#{doc}/, @exe.to_help
80
+ #end
81
+
82
+ should "fail without required param" do
83
+ assert_raises Sprout::Errors::MissingArgumentError do
84
+ @exe.parse! []
85
+ end
86
+ end
87
+
88
+ should "fail with incorrect param" do
89
+ assert_raises Sprout::Errors::InvalidArgumentError do
90
+ @exe.parse! ['--input=lib/unknown_file.rb']
91
+ end
92
+ end
93
+
94
+ context "with an unknown option" do
95
+ should "throw an exception" do
96
+ assert_raises OptionParser::InvalidOption do
97
+ @exe.parse! [ '--unknown-param', @default_input ]
98
+ end
99
+ end
100
+
101
+ should "abort and display help" do
102
+ @exe.abort_on_failure = true
103
+ @exe.expects :abort
104
+ @exe.parse! [ '--unknown-param', @default_input ]
105
+ end
106
+ end
107
+
108
+ context "with a hidden name" do
109
+
110
+ # Define the class in a place
111
+ # where only these tests can use it.
112
+ class SomeExecutable
113
+ include Sprout::Executable
114
+ add_param :debug, Boolean
115
+ add_param :input, String, { :hidden_name => true }
116
+ end
117
+
118
+ setup do
119
+ @exe = SomeExecutable.new
120
+ end
121
+
122
+ should "accept a value at the end" do
123
+ @exe.parse! ['--debug', 'SomeString']
124
+ assert @exe.debug
125
+ assert_equal 'SomeString', @exe.input
126
+ end
127
+
128
+ =begin
129
+ TODO: Get these passing...
130
+
131
+ should "fail if multiple values provided for a singular param" do
132
+ skip "not yet implemented"
133
+ end
134
+
135
+ should "accept multiple values for collection param" do
136
+ skip "not yet implemented"
137
+ end
138
+ =end
139
+ end
140
+ end
141
+ end
142
+
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ExecutableParamTest < Test::Unit::TestCase
4
+ include SproutTestCase
5
+
6
+ context "a new, simple Executable::Param" do
7
+
8
+ setup do
9
+ @param = Sprout::Executable::Param.new
10
+ end
11
+
12
+ should "be invisible until value set" do
13
+ assert !@param.visible?
14
+ end
15
+
16
+ should "return empty string with no value" do
17
+ assert_equal '', @param.to_shell
18
+ end
19
+
20
+ should "raise if required and nil" do
21
+ @param.required = true
22
+ assert_raises Sprout::Errors::MissingArgumentError do
23
+ @param.to_shell
24
+ end
25
+ end
26
+
27
+ context "with simple values" do
28
+
29
+ setup do
30
+ @param.name = :foo
31
+ @param.value = 'bar'
32
+ end
33
+
34
+ should "not raise if required and has value" do
35
+ @param.required = true
36
+ assert @param.to_shell
37
+ end
38
+
39
+ should "accept a name and value" do
40
+ assert_equal '--foo=bar', @param.to_shell
41
+ end
42
+
43
+ should "accept space delimiter" do
44
+ @param.delimiter = ' '
45
+ assert_equal '--foo bar', @param.to_shell
46
+ end
47
+
48
+ should "accept arbitrary delimiter" do
49
+ @param.delimiter = ' ||= '
50
+ assert_equal '--foo ||= bar', @param.to_shell
51
+ end
52
+
53
+ should "accept empty prefix" do
54
+ @param.prefix = ''
55
+ assert_equal 'foo=bar', @param.to_shell
56
+ end
57
+
58
+ should "accept arbitrary prefix" do
59
+ @param.prefix = '++++'
60
+ assert_equal '++++foo=bar', @param.to_shell
61
+ end
62
+
63
+ should "accept hidden_name attribute" do
64
+ @param.hidden_name = true
65
+ assert_equal 'bar', @param.to_shell
66
+ end
67
+
68
+ should "accept hidden_value attribute" do
69
+ @param.hidden_value = true
70
+ assert_equal '--foo', @param.to_shell
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1,237 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'test/fixtures/executable/mxmlc'
3
+ require 'test/unit/fake_other_executable'
4
+
5
+ class ExecutableTest < Test::Unit::TestCase
6
+ include SproutTestCase
7
+
8
+ context "a new executable delegate" do
9
+
10
+ setup do
11
+ @tool = FakeOtherExecutableTask.new
12
+ end
13
+
14
+ should "accept boolean param" do
15
+ @tool.boolean_param = true
16
+ assert @tool.boolean_param
17
+ assert_equal "--boolean-param", @tool.to_shell
18
+ end
19
+
20
+ should "accept a string param" do
21
+ @tool.string_param = "string1"
22
+ assert_equal "string1", @tool.string_param
23
+ assert_equal "--string-param=string1", @tool.to_shell
24
+ end
25
+
26
+ should "not share parameter values across instances" do
27
+ first = FakeOtherExecutableTask.new
28
+ second = FakeOtherExecutableTask.new
29
+ first.string_param = 'value1'
30
+ second.string_param = 'value2'
31
+ assert first.string_param != second.string_param
32
+ end
33
+
34
+ should "accept strings param" do
35
+ @tool.strings_param << 'string1'
36
+ @tool.strings_param << 'string2'
37
+
38
+ assert_equal ['string1', 'string2'], @tool.strings_param
39
+ assert_equal "--strings-param+=string1 --strings-param+=string2", @tool.to_shell
40
+ end
41
+
42
+ should "accept number param" do
43
+ @tool.number_param = 1234
44
+ assert_equal 1234, @tool.number_param
45
+ end
46
+
47
+ should "accept parameter alias" do
48
+ @tool.strings_param << "a"
49
+ @tool.sp << "b"
50
+
51
+ assert_equal ["a", "b"], @tool.sp
52
+ end
53
+
54
+ should "raise UsageError with unknown type" do
55
+ assert_raises Sprout::Errors::UsageError do
56
+ class BrokenExecutable
57
+ include Sprout::Executable
58
+ add_param :broken_param, nil
59
+ end
60
+
61
+ tool = BrokenExecutable.new
62
+ end
63
+ end
64
+
65
+ should "raise Error if type is not a Class" do
66
+ assert_raises Sprout::Errors::UsageError do
67
+ class BrokenExecutable2
68
+ include Sprout::Executable
69
+ add_param :some_name, :string
70
+ end
71
+ end
72
+ end
73
+
74
+ should "raise Error when requested param name already exists" do
75
+ assert_raises Sprout::Errors::DuplicateMemberError do
76
+ class BrokenExecutable3
77
+ include Sprout::Executable
78
+ attr_accessor :existing_method
79
+
80
+ add_param :existing_method, String
81
+ end
82
+ end
83
+ end
84
+
85
+ should "raise Error if a block is provided to add_param" do
86
+ assert_raises Sprout::Errors::UsageError do
87
+ class BrokenExecutable4
88
+ include Sprout::Executable
89
+ add_param :name, String do
90
+ # this is no longer how it's done...
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ should "define a new method" do
97
+ class WorkingTool
98
+ include Sprout::Executable
99
+ add_param :custom_name, String
100
+ end
101
+
102
+ tool1 = WorkingTool.new
103
+ tool1.custom_name = "Foo Bar"
104
+ assert_equal "Foo Bar", tool1.custom_name
105
+
106
+ tool2 = WorkingTool.new
107
+ tool2.custom_name = "Bar Baz"
108
+ assert_equal "Bar Baz", tool2.custom_name
109
+ end
110
+
111
+ should "accept custom reader" do
112
+ class WorkingTool
113
+ include Sprout::Executable
114
+ add_param :custom1, String, { :reader => :read_custom }
115
+ def read_custom
116
+ "#{@custom1} world"
117
+ end
118
+ end
119
+
120
+ tool = WorkingTool.new
121
+ tool.custom1 = 'hello'
122
+ assert_equal 'hello world', tool.custom1
123
+ end
124
+
125
+ should "accept custom writer" do
126
+ class WorkingTool
127
+ include Sprout::Executable
128
+ add_param :custom2, String, { :writer => :write_custom }
129
+ def write_custom(value)
130
+ @custom2 = "#{value} world"
131
+ end
132
+ end
133
+
134
+ tool = WorkingTool.new
135
+ tool.custom2 = 'hello'
136
+ assert_equal 'hello world', tool.custom2
137
+ end
138
+
139
+ # TODO: Ensure that file, files, path and paths
140
+ # validate the existence of the references.
141
+
142
+ # TODO: Ensure that a helpful error message is thrown
143
+ # when assignment operator is used on collection params
144
+ end
145
+
146
+ context "a new mxmlc task" do
147
+
148
+ setup do
149
+ @tool = Sprout::MXMLC.new
150
+ @mxmlc_executable = File.join(fixtures, 'executable', 'flex3sdk_gem', 'mxmlc')
151
+ end
152
+
153
+ should "accept input" do
154
+ @tool.input = "test/fixtures/executable/src/Main.as"
155
+ assert_equal "test/fixtures/executable/src/Main.as", @tool.input
156
+ assert_equal "test/fixtures/executable/src/Main.as", @tool.to_shell
157
+ end
158
+
159
+ should "accept default gem name" do
160
+ assert_equal 'flex4sdk', @tool.pkg_name
161
+ end
162
+
163
+ should "override default gem name" do
164
+ @tool.pkg_name = 'flex5sdk'
165
+ assert_equal 'flex5sdk', @tool.pkg_name
166
+ end
167
+
168
+ should "accept default gem version" do
169
+ assert_equal '>= 1.0.pre', @tool.pkg_version
170
+ end
171
+
172
+ should "override default gem version" do
173
+ @tool.pkg_version = '1.1.pre'
174
+ assert_equal '1.1.pre', @tool.pkg_version
175
+ end
176
+
177
+ should "accept default gem executable" do
178
+ assert_equal :mxmlc, @tool.executable
179
+ end
180
+
181
+ should "override default gem executable" do
182
+ @tool.executable = :compc
183
+ assert_equal :compc, @tool.executable
184
+ end
185
+
186
+ should "accept configuration as a file task" do
187
+ @tool = mxmlc 'bin/SomeFile.swf' do |t|
188
+ t.source_path << 'test/fixtures/executable/src'
189
+ t.input = 'test/fixtures/executable/src/Main.as'
190
+ end
191
+ assert_equal 'bin/SomeFile.swf', @tool.output
192
+ assert_equal "--output=bin/SomeFile.swf --source-path+=test/fixtures/executable/src test/fixtures/executable/src/Main.as", @tool.to_shell
193
+ end
194
+
195
+ should "accept configuration with prereqs as a file task" do
196
+ task :other_task
197
+ @tool = mxmlc 'bin/SomeFile.swf' => [:clean, :other_task] do |t|
198
+ t.source_path << 'test/fixtures/executable/src'
199
+ t.input = 'test/fixtures/executable/src/Main.as'
200
+ end
201
+ assert_equal 'bin/SomeFile.swf', @tool.output
202
+ assert_equal "--output=bin/SomeFile.swf --source-path+=test/fixtures/executable/src test/fixtures/executable/src/Main.as", @tool.to_shell
203
+ end
204
+
205
+ should "to_shell input" do
206
+ @tool.debug = true
207
+ @tool.source_path << "test/fixtures/executable/src"
208
+ assert_equal "--debug --source-path+=test/fixtures/executable/src", @tool.to_shell
209
+ end
210
+
211
+ should "execute the registered executable" do
212
+ # Configure stub executable:
213
+ @tool.input = 'test/fixtures/executable/src/Main.as'
214
+ @tool.source_path << 'test/fixtures/executable/src'
215
+ @tool.debug = true
216
+ response = OpenStruct.new(:path => @mxmlc_executable)
217
+ Sprout::Executable.expects(:load).with(:mxmlc, 'flex4sdk', '>= 1.0.pre').returns response
218
+
219
+ # Ensure the exe file mode is NOT valid:
220
+ File.chmod 0644, @mxmlc_executable
221
+ first = File.stat(@mxmlc_executable).mode
222
+
223
+ # Execute the stub executable:
224
+ @tool.execute
225
+
226
+ # Ensure the file mode was updated:
227
+ assert "non-executable file mode should be updated by execute", first != File.stat(@mxmlc_executable).mode
228
+ end
229
+
230
+ should "include prerequisites" do
231
+ @tool.input = 'test/fixtures/executable/src/Main.as'
232
+ file_task = @tool.to_rake('bin/SomeProject.swf')
233
+ assert_equal 2, file_task.prerequisites.size
234
+ end
235
+ end
236
+ end
237
+