aruba-win-fix 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +37 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +188 -0
  6. data/.simplecov +34 -0
  7. data/.travis.yml +47 -0
  8. data/.yardopts +8 -0
  9. data/CONTRIBUTING.md +71 -0
  10. data/Gemfile +83 -0
  11. data/History.md +579 -0
  12. data/LICENSE +20 -0
  13. data/README.md +226 -0
  14. data/Rakefile +49 -0
  15. data/TODO.md +13 -0
  16. data/appveyor.yml +32 -0
  17. data/aruba.gemspec +48 -0
  18. data/bin/aruba +7 -0
  19. data/config/.gitignore +1 -0
  20. data/cucumber.yml +26 -0
  21. data/features/.nav +72 -0
  22. data/features/api/command/find_command.feature +83 -0
  23. data/features/api/command/last_command_started.feature +50 -0
  24. data/features/api/command/last_command_stopped.feature +89 -0
  25. data/features/api/command/run.feature +414 -0
  26. data/features/api/command/run_simple.feature +242 -0
  27. data/features/api/command/send_signal.feature +53 -0
  28. data/features/api/command/stderr.feature +46 -0
  29. data/features/api/command/stdout.feature +46 -0
  30. data/features/api/command/stop.feature +131 -0
  31. data/features/api/command/stop_all_commands.feature +53 -0
  32. data/features/api/command/terminate_all_commands.feature +53 -0
  33. data/features/api/command/which.feature +37 -0
  34. data/features/api/core/expand_path.feature +88 -0
  35. data/features/api/environment/append_environment_variable.feature +128 -0
  36. data/features/api/environment/delete_environment_variable.feature +63 -0
  37. data/features/api/environment/prepend_environment_variable.feature +128 -0
  38. data/features/api/environment/set_environment_variable.feature +376 -0
  39. data/features/api/filesystem/cd.feature +184 -0
  40. data/features/api/filesystem/create_directory.feature +57 -0
  41. data/features/api/filesystem/disk_usage.feature +152 -0
  42. data/features/api/filesystem/does_exist.feature +62 -0
  43. data/features/api/filesystem/fixtures.feature +104 -0
  44. data/features/api/filesystem/is_absolute.feature +48 -0
  45. data/features/api/filesystem/is_directory.feature +53 -0
  46. data/features/api/filesystem/is_file.feature +54 -0
  47. data/features/api/filesystem/is_relative.feature +48 -0
  48. data/features/api/filesystem/move.feature +119 -0
  49. data/features/api/text/extract_text.feature +87 -0
  50. data/features/api/text/replace_variables.feature +45 -0
  51. data/features/api/text/sanitize_text.feature +228 -0
  52. data/features/api/text/unescape_text.feature +127 -0
  53. data/features/cli/console.feature +52 -0
  54. data/features/cli/init.feature +79 -0
  55. data/features/configuration/activate_announcer_on_command_failure.feature +38 -0
  56. data/features/configuration/command_runtime_environment.feature +129 -0
  57. data/features/configuration/console_history_file.feature +38 -0
  58. data/features/configuration/exit_timeout.feature +52 -0
  59. data/features/configuration/fixtures_directories.feature +38 -0
  60. data/features/configuration/fixtures_path_prefix.feature +23 -0
  61. data/features/configuration/home_directory.feature +80 -0
  62. data/features/configuration/io_timeout.feature +30 -0
  63. data/features/configuration/keep_ansi.feature +30 -0
  64. data/features/configuration/log_level.feature +38 -0
  65. data/features/configuration/physical_block_size.feature +53 -0
  66. data/features/configuration/remove_ansi_escape_sequences.feature +38 -0
  67. data/features/configuration/root_directory.feature +30 -0
  68. data/features/configuration/startup_wait_time.feature +48 -0
  69. data/features/configuration/usage.feature +159 -0
  70. data/features/configuration/working_directory.feature +33 -0
  71. data/features/development/build.feature +15 -0
  72. data/features/development/test.feature +24 -0
  73. data/features/getting_started/cleanup.feature +67 -0
  74. data/features/getting_started/install.feature +8 -0
  75. data/features/getting_started/run_commands.feature +177 -0
  76. data/features/getting_started/supported_testing_frameworks.feature +104 -0
  77. data/features/getting_started/writing_good_feature_tests.feature +38 -0
  78. data/features/hooks/after/command.feature +44 -0
  79. data/features/hooks/before/command.feature +71 -0
  80. data/features/matchers/collection/include_an_object.feature +72 -0
  81. data/features/matchers/directory/have_sub_directory.feature +110 -0
  82. data/features/matchers/file/be_a_command_found_in_path.feature +115 -0
  83. data/features/matchers/file/be_existing_executable.feature +88 -0
  84. data/features/matchers/file/be_existing_file.feature +82 -0
  85. data/features/matchers/file/have_file_content.feature +123 -0
  86. data/features/matchers/file/have_file_size.feature +107 -0
  87. data/features/matchers/path/be_an_absolute_path.feature +74 -0
  88. data/features/matchers/path/be_an_existing_path.feature +97 -0
  89. data/features/matchers/path/have_permissions.feature +118 -0
  90. data/features/matchers/timeouts.feature +48 -0
  91. data/features/platforms/jruby.feature +14 -0
  92. data/features/rspec/integration.feature +179 -0
  93. data/features/step_definitions/aruba_dev_steps.rb +56 -0
  94. data/features/step_definitions/hooks.rb +96 -0
  95. data/features/steps/command/debug.feature +92 -0
  96. data/features/steps/command/exit_statuses.feature +136 -0
  97. data/features/steps/command/in_process.feature +485 -0
  98. data/features/steps/command/interactive.feature +90 -0
  99. data/features/steps/command/output.feature +588 -0
  100. data/features/steps/command/run.feature +66 -0
  101. data/features/steps/command/send_signal.feature +104 -0
  102. data/features/steps/command/shell.feature +155 -0
  103. data/features/steps/command/stderr.feature +68 -0
  104. data/features/steps/command/stdout.feature +109 -0
  105. data/features/steps/command/stop.feature +313 -0
  106. data/features/steps/core/announce.feature +283 -0
  107. data/features/steps/environment/append_environment_variable.feature +52 -0
  108. data/features/steps/environment/home_variable.feature +62 -0
  109. data/features/steps/environment/prepend_environment_variable.feature +52 -0
  110. data/features/steps/environment/set_environment_variable.feature +49 -0
  111. data/features/steps/filesystem/append_to_file.feature +45 -0
  112. data/features/steps/filesystem/cd_to_directory.feature +33 -0
  113. data/features/steps/filesystem/check_file_content.feature +61 -0
  114. data/features/steps/filesystem/check_permissions_of_file.feature +39 -0
  115. data/features/steps/filesystem/compare_files.feature +42 -0
  116. data/features/steps/filesystem/copy.feature +45 -0
  117. data/features/steps/filesystem/create_directory.feature +57 -0
  118. data/features/steps/filesystem/create_file.feature +76 -0
  119. data/features/steps/filesystem/existence_of_directory.feature +57 -0
  120. data/features/steps/filesystem/existence_of_file.feature +43 -0
  121. data/features/steps/filesystem/file_content.feature +86 -0
  122. data/features/steps/filesystem/fixtures.feature +64 -0
  123. data/features/steps/filesystem/move.feature +45 -0
  124. data/features/steps/filesystem/non_existence_of_directory.feature +69 -0
  125. data/features/steps/filesystem/non_existence_of_file.feature +80 -0
  126. data/features/steps/filesystem/overwrite_file.feature +72 -0
  127. data/features/steps/filesystem/remove_directory.feature +38 -0
  128. data/features/steps/filesystem/remove_file.feature +38 -0
  129. data/features/steps/filesystem/use_fixture.feature +77 -0
  130. data/features/steps/overview.feature +60 -0
  131. data/features/support/aruba.rb +7 -0
  132. data/features/support/env.rb +33 -0
  133. data/features/support/jruby.rb +5 -0
  134. data/features/support/simplecov_setup.rb +8 -0
  135. data/fixtures/cli-app/.gitignore +9 -0
  136. data/fixtures/cli-app/.rspec +2 -0
  137. data/fixtures/cli-app/README.md +39 -0
  138. data/fixtures/cli-app/Rakefile +1 -0
  139. data/fixtures/cli-app/bin/cli +6 -0
  140. data/fixtures/cli-app/cli-app.gemspec +26 -0
  141. data/fixtures/cli-app/features/support/env.rb +1 -0
  142. data/fixtures/cli-app/lib/cli/app.rb +13 -0
  143. data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +15 -0
  144. data/fixtures/cli-app/lib/cli/app/version.rb +5 -0
  145. data/fixtures/cli-app/script/console +14 -0
  146. data/fixtures/cli-app/spec/spec_helper.rb +9 -0
  147. data/fixtures/cli-app/spec/support/aruba.rb +1 -0
  148. data/fixtures/copy/file.txt +1 -0
  149. data/fixtures/empty-app/.gitignore +9 -0
  150. data/fixtures/empty-app/.rspec +2 -0
  151. data/fixtures/empty-app/README.md +24 -0
  152. data/fixtures/empty-app/Rakefile +1 -0
  153. data/fixtures/empty-app/cli-app.gemspec +26 -0
  154. data/fixtures/empty-app/lib/cli/app.rb +13 -0
  155. data/fixtures/empty-app/lib/cli/app/version.rb +5 -0
  156. data/fixtures/getting-started-app/.gitignore +4 -0
  157. data/fixtures/getting-started-app/Gemfile +4 -0
  158. data/fixtures/getting-started-app/README.md +3 -0
  159. data/fixtures/getting-started-app/features/support/env.rb +1 -0
  160. data/fixtures/spawn_process/stderr.sh +3 -0
  161. data/lib/aruba.rb +1 -0
  162. data/lib/aruba/api.rb +34 -0
  163. data/lib/aruba/api/command.rb +307 -0
  164. data/lib/aruba/api/core.rb +191 -0
  165. data/lib/aruba/api/deprecated.rb +897 -0
  166. data/lib/aruba/api/environment.rb +89 -0
  167. data/lib/aruba/api/filesystem.rb +392 -0
  168. data/lib/aruba/api/rvm.rb +44 -0
  169. data/lib/aruba/api/text.rb +56 -0
  170. data/lib/aruba/aruba_path.rb +133 -0
  171. data/lib/aruba/basic_configuration.rb +240 -0
  172. data/lib/aruba/basic_configuration/option.rb +32 -0
  173. data/lib/aruba/cli.rb +26 -0
  174. data/lib/aruba/colorizer.rb +108 -0
  175. data/lib/aruba/command.rb +74 -0
  176. data/lib/aruba/config.rb +108 -0
  177. data/lib/aruba/config/jruby.rb +17 -0
  178. data/lib/aruba/config_wrapper.rb +58 -0
  179. data/lib/aruba/console.rb +70 -0
  180. data/lib/aruba/console/help.rb +35 -0
  181. data/lib/aruba/contracts/absolute_path.rb +20 -0
  182. data/lib/aruba/contracts/enum.rb +26 -0
  183. data/lib/aruba/contracts/is_power_of_two.rb +22 -0
  184. data/lib/aruba/contracts/relative_path.rb +20 -0
  185. data/lib/aruba/cucumber.rb +13 -0
  186. data/lib/aruba/cucumber/command.rb +422 -0
  187. data/lib/aruba/cucumber/core.rb +5 -0
  188. data/lib/aruba/cucumber/environment.rb +42 -0
  189. data/lib/aruba/cucumber/file.rb +201 -0
  190. data/lib/aruba/cucumber/hooks.rb +160 -0
  191. data/lib/aruba/cucumber/rvm.rb +3 -0
  192. data/lib/aruba/cucumber/testing_frameworks.rb +95 -0
  193. data/lib/aruba/errors.rb +37 -0
  194. data/lib/aruba/event_bus.rb +59 -0
  195. data/lib/aruba/event_bus/name_resolver.rb +168 -0
  196. data/lib/aruba/events.rb +39 -0
  197. data/lib/aruba/extensions/string/strip.rb +25 -0
  198. data/lib/aruba/file_size.rb +63 -0
  199. data/lib/aruba/generators/script_file.rb +46 -0
  200. data/lib/aruba/hooks.rb +56 -0
  201. data/lib/aruba/in_config_wrapper.rb +24 -0
  202. data/lib/aruba/in_process.rb +14 -0
  203. data/lib/aruba/initializer.rb +222 -0
  204. data/lib/aruba/jruby.rb +4 -0
  205. data/lib/aruba/matchers/base/base_matcher.rb +96 -0
  206. data/lib/aruba/matchers/base/object_formatter.rb +114 -0
  207. data/lib/aruba/matchers/collection.rb +1 -0
  208. data/lib/aruba/matchers/collection/all.rb +11 -0
  209. data/lib/aruba/matchers/collection/include_an_object.rb +122 -0
  210. data/lib/aruba/matchers/command.rb +1 -0
  211. data/lib/aruba/matchers/command/be_successfully_executed.rb +34 -0
  212. data/lib/aruba/matchers/command/have_exit_status.rb +38 -0
  213. data/lib/aruba/matchers/command/have_finished_in_time.rb +37 -0
  214. data/lib/aruba/matchers/command/have_output.rb +36 -0
  215. data/lib/aruba/matchers/command/have_output_on_stderr.rb +32 -0
  216. data/lib/aruba/matchers/command/have_output_on_stdout.rb +32 -0
  217. data/lib/aruba/matchers/command/have_output_size.rb +28 -0
  218. data/lib/aruba/matchers/directory.rb +1 -0
  219. data/lib/aruba/matchers/directory/be_an_existing_directory.rb +38 -0
  220. data/lib/aruba/matchers/directory/have_sub_directory.rb +53 -0
  221. data/lib/aruba/matchers/environment.rb +1 -0
  222. data/lib/aruba/matchers/file.rb +1 -0
  223. data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +36 -0
  224. data/lib/aruba/matchers/file/be_an_existing_executable.rb +37 -0
  225. data/lib/aruba/matchers/file/be_an_existing_file.rb +38 -0
  226. data/lib/aruba/matchers/file/have_file_content.rb +62 -0
  227. data/lib/aruba/matchers/file/have_file_size.rb +47 -0
  228. data/lib/aruba/matchers/file/have_same_file_content.rb +48 -0
  229. data/lib/aruba/matchers/path.rb +1 -0
  230. data/lib/aruba/matchers/path/a_path_matching_pattern.rb +25 -0
  231. data/lib/aruba/matchers/path/be_an_absolute_path.rb +36 -0
  232. data/lib/aruba/matchers/path/be_an_existing_path.rb +37 -0
  233. data/lib/aruba/matchers/path/have_permissions.rb +64 -0
  234. data/lib/aruba/matchers/path/match_path_pattern.rb +41 -0
  235. data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +25 -0
  236. data/lib/aruba/matchers/string.rb +1 -0
  237. data/lib/aruba/matchers/string/include_output_string.rb +36 -0
  238. data/lib/aruba/matchers/string/match_output_string.rb +37 -0
  239. data/lib/aruba/matchers/string/output_string_eq.rb +35 -0
  240. data/lib/aruba/platform.rb +25 -0
  241. data/lib/aruba/platforms/announcer.rb +232 -0
  242. data/lib/aruba/platforms/aruba_file_creator.rb +35 -0
  243. data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +35 -0
  244. data/lib/aruba/platforms/aruba_logger.rb +81 -0
  245. data/lib/aruba/platforms/command_monitor.rb +229 -0
  246. data/lib/aruba/platforms/determine_disk_usage.rb +28 -0
  247. data/lib/aruba/platforms/determine_file_size.rb +22 -0
  248. data/lib/aruba/platforms/disk_usage_calculator.rb +20 -0
  249. data/lib/aruba/platforms/filesystem_status.rb +68 -0
  250. data/lib/aruba/platforms/local_environment.rb +29 -0
  251. data/lib/aruba/platforms/simple_table.rb +54 -0
  252. data/lib/aruba/platforms/unix_command_string.rb +27 -0
  253. data/lib/aruba/platforms/unix_environment_variables.rb +220 -0
  254. data/lib/aruba/platforms/unix_platform.rb +276 -0
  255. data/lib/aruba/platforms/unix_which.rb +85 -0
  256. data/lib/aruba/platforms/windows_command_string.rb +31 -0
  257. data/lib/aruba/platforms/windows_environment_variables.rb +89 -0
  258. data/lib/aruba/platforms/windows_platform.rb +42 -0
  259. data/lib/aruba/platforms/windows_which.rb +106 -0
  260. data/lib/aruba/processes/basic_process.rb +143 -0
  261. data/lib/aruba/processes/debug_process.rb +69 -0
  262. data/lib/aruba/processes/in_process.rb +125 -0
  263. data/lib/aruba/processes/spawn_process.rb +278 -0
  264. data/lib/aruba/reporting.rb +126 -0
  265. data/lib/aruba/rspec.rb +107 -0
  266. data/lib/aruba/runtime.rb +96 -0
  267. data/lib/aruba/setup.rb +90 -0
  268. data/lib/aruba/spawn_process.rb +11 -0
  269. data/lib/aruba/version.rb +3 -0
  270. data/script/bootstrap +28 -0
  271. data/script/console +16 -0
  272. data/script/test +3 -0
  273. data/spec/aruba/api/environment/restore_env_spec.rb +65 -0
  274. data/spec/aruba/api/environment/set_env_spec.rb +42 -0
  275. data/spec/aruba/api/filesystem/file_size_spec.rb +28 -0
  276. data/spec/aruba/api/runtime_spec.rb +28 -0
  277. data/spec/aruba/api_spec.rb +1209 -0
  278. data/spec/aruba/aruba_path_spec.rb +103 -0
  279. data/spec/aruba/basic_configuration_spec.rb +5 -0
  280. data/spec/aruba/configuration_spec.rb +5 -0
  281. data/spec/aruba/hooks_spec.rb +17 -0
  282. data/spec/aruba/in_config_wrapper_spec.rb +25 -0
  283. data/spec/aruba/jruby_spec.rb +55 -0
  284. data/spec/aruba/matchers/command/have_output_size_spec.rb +25 -0
  285. data/spec/aruba/matchers/command_spec.rb +174 -0
  286. data/spec/aruba/matchers/directory_spec.rb +57 -0
  287. data/spec/aruba/matchers/file_spec.rb +127 -0
  288. data/spec/aruba/matchers/path_spec.rb +88 -0
  289. data/spec/aruba/platform/simple_table_spec.rb +23 -0
  290. data/spec/aruba/platform/windows_environment_variables_spec.rb +500 -0
  291. data/spec/aruba/rspec_spec.rb +15 -0
  292. data/spec/aruba/runtime_spec.rb +29 -0
  293. data/spec/aruba/spawn_process_spec.rb +60 -0
  294. data/spec/event_bus/name_resolver_spec.rb +68 -0
  295. data/spec/event_bus_spec.rb +160 -0
  296. data/spec/spec_helper.rb +23 -0
  297. data/spec/support/configs/.keep +0 -0
  298. data/spec/support/configs/aruba.rb +5 -0
  299. data/spec/support/configs/pry.rb +3 -0
  300. data/spec/support/configs/rspec.rb +15 -0
  301. data/spec/support/helpers/.keep +0 -0
  302. data/spec/support/helpers/reporting.rb +44 -0
  303. data/spec/support/matchers/.keep +0 -0
  304. data/spec/support/matchers/option.rb +35 -0
  305. data/spec/support/shared_contexts/.keep +0 -0
  306. data/spec/support/shared_contexts/aruba.rb +48 -0
  307. data/spec/support/shared_examples/.keep +0 -0
  308. data/spec/support/shared_examples/configuration.rb +116 -0
  309. data/spec/support/shared_examples/directory.rb +7 -0
  310. data/spec/support/shared_examples/file.rb +7 -0
  311. data/templates/css/console.css +24 -0
  312. data/templates/css/filesystem.css +42 -0
  313. data/templates/css/pygments-autumn.css +59 -0
  314. data/templates/files.erb +14 -0
  315. data/templates/images/LICENSE +22 -0
  316. data/templates/images/folder.png +0 -0
  317. data/templates/images/page_white.png +0 -0
  318. data/templates/images/page_white_gherkin.png +0 -0
  319. data/templates/images/page_white_ruby.png +0 -0
  320. data/templates/index.erb +20 -0
  321. data/templates/js/filesystem.js +5 -0
  322. data/templates/js/jquery-1.11.3.min.js +5 -0
  323. data/templates/main.erb +34 -0
  324. metadata +629 -0
@@ -0,0 +1,69 @@
1
+ require 'aruba/processes/spawn_process'
2
+
3
+ # Aruba
4
+ module Aruba
5
+ # Processes
6
+ module Processes
7
+ # Run your command in `systemd()` to make debugging it easier
8
+ #
9
+ # `DebugProcess` is not meant for direct use - `InProcess.new` - by
10
+ # users. Only it's public methods are part of the public API of aruba, e.g.
11
+ # `#stdin`, `#stdout`.
12
+ #
13
+ # @private
14
+ class DebugProcess < BasicProcess
15
+ # Use only if mode is :debug
16
+ def self.match?(mode)
17
+ mode == :debug || (mode.is_a?(Class) && mode <= DebugProcess)
18
+ end
19
+
20
+ def start
21
+ Dir.chdir @working_directory do
22
+ Aruba.platform.with_environment(environment) do
23
+ @exit_status = system(command, *arguments) ? 0 : 1
24
+ end
25
+ end
26
+ end
27
+
28
+ # Return stdin
29
+ #
30
+ # @return [NilClass]
31
+ # Nothing
32
+ def stdin(*); end
33
+
34
+ # Return stdout
35
+ #
36
+ # @return [String]
37
+ # A predefined string to make users aware they are using the DebugProcess
38
+ def stdout(*)
39
+ 'This is the debug launcher on STDOUT. If this output is unexpected, please check your setup.'
40
+ end
41
+
42
+ # Return stderr
43
+ #
44
+ # @return [String]
45
+ # A predefined string to make users aware they are using the DebugProcess
46
+ def stderr(*)
47
+ 'This is the debug launcher on STDERR. If this output is unexpected, please check your setup.'
48
+ end
49
+
50
+ # Write to nothing
51
+ def write(*); end
52
+
53
+ # Close nothing
54
+ def close_io(*); end
55
+
56
+ # Stop process
57
+ def stop(*)
58
+ @started = false
59
+
60
+ @exit_status
61
+ end
62
+
63
+ # Terminate process
64
+ def terminate(*)
65
+ stop
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,125 @@
1
+ require 'shellwords'
2
+ require 'stringio'
3
+ require 'aruba/processes/basic_process'
4
+ require 'aruba/platform'
5
+
6
+ # Aruba
7
+ module Aruba
8
+ # Platforms
9
+ module Processes
10
+ # Run command in your ruby process
11
+ #
12
+ # `InProcess` is not meant for direct use - `InProcess.new` - by
13
+ # users. Only it's public methods are part of the public API of aruba, e.g.
14
+ # `#stdin`, `#stdout`.
15
+ #
16
+ # @private
17
+ class InProcess < BasicProcess
18
+ # Use only if mode is in_process
19
+ def self.match?(mode)
20
+ mode == :in_process || (mode.is_a?(Class) && mode <= InProcess)
21
+ end
22
+
23
+ attr_reader :exit_status
24
+
25
+ # Fake Kernel module of ruby
26
+ #
27
+ # @private
28
+ class FakeKernel
29
+ attr_reader :exitstatus
30
+
31
+ def initialize
32
+ @exitstatus = 0
33
+ end
34
+
35
+ def exit(exitstatus)
36
+ @exitstatus = exitstatus
37
+ end
38
+ end
39
+
40
+ class << self
41
+ # @deprecated
42
+ attr_accessor :main_class
43
+ end
44
+
45
+ # @private
46
+ attr_reader :main_class
47
+
48
+ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
49
+ @cmd = cmd
50
+ @argv = arguments
51
+ @stdin = StringIO.new
52
+ @stdout = StringIO.new
53
+ @stderr = StringIO.new
54
+ @kernel = FakeKernel.new
55
+
56
+ super
57
+ end
58
+
59
+ # Start command
60
+ def start
61
+ fail "You need to call aruba.config.main_class = YourMainClass" unless main_class
62
+
63
+ Dir.chdir @working_directory do
64
+ before_run
65
+
66
+ Aruba.platform.with_environment environment.merge('PWD' => @working_directory) do
67
+ main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute!
68
+ end
69
+
70
+ after_run
71
+
72
+ yield self if block_given?
73
+ end
74
+ end
75
+
76
+ # Stop command
77
+ def stop(*)
78
+ @started = false
79
+ @exit_status = @kernel.exitstatus
80
+ end
81
+
82
+ # Access stdin
83
+ def stdin
84
+ @stdin.string
85
+ end
86
+
87
+ # Access stdout
88
+ def stdout(*)
89
+ @stdout.string
90
+ end
91
+
92
+ # Access stderr
93
+ def stderr(*)
94
+ @stderr.string
95
+ end
96
+
97
+ # Write strint to stdin
98
+ #
99
+ # @param [String] input
100
+ # Write string to stdin in
101
+ def write(input)
102
+ @stdin.write input
103
+ end
104
+
105
+ # Close io
106
+ def close_io(name)
107
+ fail ArgumentError, 'Only stdin stdout and stderr are allowed to close' unless [:stdin, :stdout, :stderr].include? name
108
+
109
+ get_instance_variable(name.to_sym).close
110
+ end
111
+
112
+ # Terminate program
113
+ def terminate
114
+ stop
115
+ end
116
+
117
+ # Output pid of process
118
+ #
119
+ # This is the PID of the ruby process! So be careful
120
+ def pid
121
+ $PROCESS_ID
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,278 @@
1
+ require 'childprocess'
2
+ require 'tempfile'
3
+ require 'shellwords'
4
+
5
+ require 'aruba/errors'
6
+ require 'aruba/processes/basic_process'
7
+ require 'aruba/platform'
8
+
9
+ # Aruba
10
+ module Aruba
11
+ # Platforms
12
+ module Processes
13
+ # Spawn a process for command
14
+ #
15
+ # `SpawnProcess` is not meant for direct use - `SpawnProcess.new` - by
16
+ # users. Only it's public methods are part of the public API of aruba, e.g.
17
+ # `#stdin`, `#stdout`.
18
+ #
19
+ # @private
20
+ class SpawnProcess < BasicProcess
21
+ # Use as default launcher
22
+ def self.match?(mode)
23
+ true
24
+ end
25
+
26
+ # Create process
27
+ #
28
+ # @params [String] cmd
29
+ # Command string
30
+ #
31
+ # @params [Integer] exit_timeout
32
+ # The timeout until we expect the command to be finished
33
+ #
34
+ # @params [Integer] io_wait_timeout
35
+ # The timeout until we expect the io to be finished
36
+ #
37
+ # @params [String] working_directory
38
+ # The directory where the command will be executed
39
+ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory, environment = ENV.to_hash.dup, main_class = nil, stop_signal = nil, startup_wait_time = 0)
40
+ super
41
+
42
+ @process = nil
43
+ @stdout_cache = nil
44
+ @stderr_cache = nil
45
+ end
46
+
47
+ # Run the command
48
+ #
49
+ # @yield [SpawnProcess]
50
+ # Run code for process which was started
51
+ #
52
+ # rubocop:disable Metrics/MethodLength
53
+ def start
54
+ # rubocop:disable Metrics/LineLength
55
+ fail CommandAlreadyStartedError, %(Command "#{commandline}" has already been started. Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.\n#{caller.join("\n")}) if started?
56
+ # rubocop:enable Metrics/LineLength
57
+
58
+ @started = true
59
+
60
+ @process = ChildProcess.build(*[command_string.to_a, arguments].flatten)
61
+ @stdout_file = Tempfile.new('aruba-stdout-')
62
+ @stderr_file = Tempfile.new('aruba-stderr-')
63
+
64
+ @stdout_file.sync = true
65
+ @stderr_file.sync = true
66
+
67
+ @exit_status = nil
68
+ @duplex = true
69
+
70
+ before_run
71
+
72
+ @process.leader = true
73
+ @process.io.stdout = @stdout_file
74
+ @process.io.stderr = @stderr_file
75
+ @process.duplex = @duplex
76
+ @process.cwd = @working_directory
77
+
78
+ @process.environment.update(environment)
79
+
80
+ begin
81
+ Aruba.platform.with_environment(environment) do
82
+ @process.start
83
+ sleep startup_wait_time
84
+ end
85
+ rescue ChildProcess::LaunchError => e
86
+ raise LaunchError, "It tried to start #{cmd}. " + e.message
87
+ end
88
+
89
+ after_run
90
+
91
+ yield self if block_given?
92
+ end
93
+ # rubocop:disable Metrics/MethodLength
94
+
95
+ # Access to stdout of process
96
+ def stdin
97
+ return if @process.exited?
98
+
99
+ @process.io.stdin
100
+ end
101
+
102
+ # Access to stdout of process
103
+ #
104
+ # @param [Hash] opts
105
+ # Options
106
+ #
107
+ # @option [Integer] wait_for_io
108
+ # Wait for IO to be finished
109
+ #
110
+ # @return [String]
111
+ # The content of stdout
112
+ def stdout(opts = {})
113
+ return @stdout_cache if stopped?
114
+
115
+ wait_for_io opts.fetch(:wait_for_io, io_wait_timeout) do
116
+ @process.io.stdout.flush
117
+ open(@stdout_file.path).read
118
+ end
119
+ end
120
+
121
+ # Access to stderr of process
122
+ #
123
+ # @param [Hash] opts
124
+ # Options
125
+ #
126
+ # @option [Integer] wait_for_io
127
+ # Wait for IO to be finished
128
+ #
129
+ # @return [String]
130
+ # The content of stderr
131
+ def stderr(opts = {})
132
+ return @stderr_cache if stopped?
133
+
134
+ wait_for_io opts.fetch(:wait_for_io, io_wait_timeout) do
135
+ @process.io.stderr.flush
136
+ open(@stderr_file.path).read
137
+ end
138
+ end
139
+
140
+ def read_stdout
141
+ # rubocop:disable Metrics/LineLength
142
+ Aruba.platform.deprecated('The use of "#read_stdout" is deprecated. Use "#stdout" instead. To reduce the time to wait for io, pass `:wait_for_io => 0` or some suitable for your use case')
143
+ # rubocop:enable Metrics/LineLength
144
+
145
+ stdout(:wait_for_io => 0)
146
+ end
147
+
148
+ def write(input)
149
+ return if stopped?
150
+
151
+ @process.io.stdin.write(input)
152
+ @process.io.stdin.flush
153
+
154
+ self
155
+ end
156
+
157
+ # Close io
158
+ def close_io(name)
159
+ return if stopped?
160
+
161
+ if RUBY_VERSION < '1.9'
162
+ @process.io.send(name.to_sym).close
163
+ else
164
+ @process.io.public_send(name.to_sym).close
165
+ end
166
+ end
167
+
168
+ # Stop command
169
+ def stop(*)
170
+ return @exit_status if stopped?
171
+
172
+ begin
173
+ @process.poll_for_exit(@exit_timeout)
174
+ rescue ChildProcess::TimeoutError
175
+ @timed_out = true
176
+ end
177
+
178
+ terminate
179
+ end
180
+
181
+ # Wait for command to finish
182
+ def wait
183
+ @process.wait
184
+ end
185
+
186
+ # Terminate command
187
+ def terminate
188
+ return @exit_status if stopped?
189
+
190
+ unless @process.exited?
191
+ if @stop_signal
192
+ # send stop signal ...
193
+ send_signal @stop_signal
194
+ # ... and set the exit status
195
+ wait
196
+ else
197
+ @process.stop
198
+ end
199
+ end
200
+
201
+ @exit_status = @process.exit_code
202
+
203
+ @stdout_cache = read_temporary_output_file @stdout_file
204
+ @stderr_cache = read_temporary_output_file @stderr_file
205
+
206
+ # @stdout_file = nil
207
+ # @stderr_file = nil
208
+
209
+ @started = false
210
+
211
+ @exit_status
212
+ end
213
+
214
+ # Output pid of process
215
+ #
216
+ # This is the PID of the spawned process.
217
+ def pid
218
+ @process.pid
219
+ end
220
+
221
+ # Send command a signal
222
+ #
223
+ # @param [String] signal
224
+ # The signal, i.e. 'TERM'
225
+ def send_signal(signal)
226
+ fail CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.) if @process.exited?
227
+
228
+ Process.kill signal, pid
229
+ rescue Errno::ESRCH
230
+ raise CommandAlreadyStoppedError, %(Command "#{commandline}" with PID "#{pid}" has already stopped.)
231
+ end
232
+
233
+ # Return file system stats for the given command
234
+ #
235
+ # @return [Aruba::Platforms::FilesystemStatus]
236
+ # This returns a File::Stat-object
237
+ def filesystem_status
238
+ Aruba.platform.filesystem_status.new(command_string.to_s)
239
+ end
240
+
241
+ # Content of command
242
+ #
243
+ # @return [String]
244
+ # The content of the script/command. This might be binary output as
245
+ # string if your command is a binary executable.
246
+ def content
247
+ File.read command_string.to_s
248
+ end
249
+
250
+ private
251
+
252
+ def command_string
253
+ # gather fully qualified path
254
+ cmd = Aruba.platform.which(command, environment['PATH'])
255
+
256
+ # rubocop:disable Metrics/LineLength
257
+ fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) if cmd.nil?
258
+ # rubocop:enable Metrics/LineLength
259
+
260
+ Aruba.platform.command_string.new(cmd)
261
+ end
262
+
263
+ def wait_for_io(time_to_wait, &block)
264
+ sleep time_to_wait.to_i
265
+ yield
266
+ end
267
+
268
+ def read_temporary_output_file(file)
269
+ file.flush
270
+ file.rewind
271
+ data = file.read
272
+ file.close
273
+
274
+ data
275
+ end
276
+ end
277
+ end
278
+ end