aruba 1.0.0.pre.alpha.2 → 1.0.0.pre.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/PULL_REQUEST_TEMPLATE.md +2 -1
- data/.rubocop.yml +6 -181
- data/.rubocop_todo.yml +364 -0
- data/.travis.yml +63 -34
- data/.yardopts +3 -0
- data/CHANGELOG.md +1121 -0
- data/CONTRIBUTING.md +179 -78
- data/Gemfile +29 -44
- data/README.md +41 -11
- data/Rakefile +35 -35
- data/appveyor.yml +6 -5
- data/aruba.gemspec +14 -16
- data/bin/console +2 -11
- data/cucumber.yml +0 -7
- data/fixtures/cli-app/README.md +1 -1
- data/fixtures/cli-app/Rakefile +1 -1
- data/fixtures/cli-app/cli-app.gemspec +1 -0
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +3 -3
- data/fixtures/cli-app/lib/cli/app/version.rb +1 -1
- data/fixtures/empty-app/Rakefile +1 -1
- data/fixtures/empty-app/cli-app.gemspec +1 -0
- data/fixtures/empty-app/lib/cli/app/version.rb +1 -1
- data/fixtures/getting-started-app/Gemfile +1 -1
- data/lib/aruba/api.rb +3 -10
- data/lib/aruba/api/bundler.rb +16 -0
- data/lib/aruba/api/commands.rb +249 -0
- data/lib/aruba/api/core.rb +24 -10
- data/lib/aruba/api/environment.rb +12 -7
- data/lib/aruba/api/filesystem.rb +22 -20
- data/lib/aruba/api/text.rb +3 -9
- data/lib/aruba/aruba_path.rb +3 -18
- data/lib/aruba/basic_configuration.rb +3 -19
- data/lib/aruba/cli.rb +1 -1
- data/lib/aruba/colorizer.rb +33 -33
- data/lib/aruba/command.rb +4 -0
- data/lib/aruba/config_wrapper.rb +1 -1
- data/lib/aruba/configuration.rb +78 -0
- data/lib/aruba/console.rb +5 -5
- data/lib/aruba/console/help.rb +1 -1
- data/lib/aruba/cucumber.rb +0 -1
- data/lib/aruba/cucumber/command.rb +55 -115
- data/lib/aruba/cucumber/environment.rb +1 -1
- data/lib/aruba/cucumber/file.rb +9 -21
- data/lib/aruba/cucumber/hooks.rb +6 -62
- data/lib/aruba/event_bus/name_resolver.rb +1 -2
- data/lib/aruba/hooks.rb +1 -1
- data/lib/aruba/initializer.rb +3 -3
- data/lib/aruba/matchers/base/base_matcher.rb +2 -2
- data/lib/aruba/matchers/base/message_indenter.rb +19 -0
- data/lib/aruba/matchers/base/object_formatter.rb +2 -2
- data/lib/aruba/matchers/collection/include_an_object.rb +7 -9
- data/lib/aruba/matchers/command/be_successfully_executed.rb +2 -4
- data/lib/aruba/matchers/command/have_exit_status.rb +1 -1
- data/lib/aruba/matchers/command/have_finished_in_time.rb +2 -4
- data/lib/aruba/matchers/command/have_output.rb +9 -4
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +1 -1
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +1 -1
- data/lib/aruba/matchers/command/have_output_size.rb +1 -1
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +4 -6
- data/lib/aruba/matchers/directory/have_sub_directory.rb +4 -6
- data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +2 -4
- data/lib/aruba/matchers/file/be_an_existing_executable.rb +4 -6
- data/lib/aruba/matchers/file/be_an_existing_file.rb +4 -6
- data/lib/aruba/matchers/file/have_file_content.rb +4 -4
- data/lib/aruba/matchers/file/have_file_size.rb +6 -8
- data/lib/aruba/matchers/file/have_same_file_content.rb +9 -12
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +2 -4
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +3 -5
- data/lib/aruba/matchers/path/be_an_existing_path.rb +4 -6
- data/lib/aruba/matchers/path/have_permissions.rb +6 -8
- data/lib/aruba/matchers/string/include_output_string.rb +8 -10
- data/lib/aruba/matchers/string/match_output_string.rb +9 -11
- data/lib/aruba/matchers/string/output_string_eq.rb +7 -9
- data/lib/aruba/platform.rb +0 -1
- data/lib/aruba/platforms/announcer.rb +26 -70
- data/lib/aruba/platforms/aruba_file_creator.rb +1 -1
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +2 -2
- data/lib/aruba/platforms/aruba_logger.rb +22 -2
- data/lib/aruba/platforms/command_monitor.rb +2 -125
- data/lib/aruba/platforms/filesystem_status.rb +9 -9
- data/lib/aruba/platforms/local_environment.rb +2 -2
- data/lib/aruba/platforms/simple_table.rb +3 -3
- data/lib/aruba/platforms/unix_command_string.rb +7 -4
- data/lib/aruba/platforms/unix_environment_variables.rb +9 -13
- data/lib/aruba/platforms/unix_platform.rb +2 -27
- data/lib/aruba/platforms/unix_which.rb +2 -1
- data/lib/aruba/platforms/windows_command_string.rb +20 -7
- data/lib/aruba/platforms/windows_environment_variables.rb +35 -30
- data/lib/aruba/platforms/windows_which.rb +4 -3
- data/lib/aruba/processes/basic_process.rb +11 -15
- data/lib/aruba/processes/debug_process.rb +5 -0
- data/lib/aruba/processes/in_process.rb +17 -8
- data/lib/aruba/processes/spawn_process.rb +35 -23
- data/lib/aruba/rspec.rb +9 -22
- data/lib/aruba/runtime.rb +7 -5
- data/lib/aruba/setup.rb +6 -4
- data/lib/aruba/tasks/docker_helpers.rb +1 -1
- data/lib/aruba/version.rb +1 -1
- metadata +37 -57
- data/History.md +0 -612
- data/bin/bootstrap +0 -34
- data/fixtures/spawn_process/stderr.sh +0 -3
- data/lib/aruba/api/command.rb +0 -309
- data/lib/aruba/api/deprecated.rb +0 -895
- data/lib/aruba/api/rvm.rb +0 -44
- data/lib/aruba/config.rb +0 -101
- data/lib/aruba/cucumber/rvm.rb +0 -3
- data/lib/aruba/in_process.rb +0 -14
- data/lib/aruba/jruby.rb +0 -4
- data/lib/aruba/matchers/path/match_path_pattern.rb +0 -41
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +0 -25
- data/lib/aruba/spawn_process.rb +0 -11
data/Rakefile
CHANGED
@@ -6,46 +6,31 @@ require 'aruba/platform'
|
|
6
6
|
require 'bundler'
|
7
7
|
Bundler.setup
|
8
8
|
|
9
|
-
task :
|
9
|
+
task default: [:lint, :test]
|
10
10
|
|
11
|
-
desc 'Run
|
12
|
-
task :
|
11
|
+
desc 'Run all linters.'
|
12
|
+
task lint: %w(lint:travis lint:coding_guidelines lint:licenses)
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
Rake::Task['test:cucumber'].invoke
|
17
|
-
end
|
18
|
-
|
19
|
-
task :cucumber_wip do
|
20
|
-
Aruba.platform.deprecated 'The use of task "cucumber_wip" is deprecated. Please use "test:cucumber_wip"'
|
21
|
-
Rake::Task['test:cucumber_wip'].invoke
|
22
|
-
end
|
14
|
+
desc 'Run the whole test suite.'
|
15
|
+
task test: %w(test:rspec test:cucumber test:cucumber_wip)
|
23
16
|
|
24
|
-
task
|
25
|
-
|
26
|
-
Rake::Task['test:rspec'].invoke
|
27
|
-
end
|
28
|
-
|
29
|
-
task :rubocop do
|
30
|
-
Aruba.platform.deprecated 'The use of task "rubocop" is deprecated. Please use "lint:coding_guidelines"'
|
31
|
-
Rake::Task['test:coding_guidelines'].invoke
|
32
|
-
end
|
17
|
+
require 'cucumber/rake/task'
|
18
|
+
require 'rspec/core/rake_task'
|
33
19
|
|
34
20
|
namespace :test do
|
35
|
-
|
36
|
-
|
37
|
-
sh 'bundle exec cucumber'
|
21
|
+
Cucumber::Rake::Task.new do |t|
|
22
|
+
t.cucumber_opts = %w{--format progress}
|
38
23
|
end
|
39
24
|
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
Cucumber::Rake::Task.new(:cucumber_wip, 'Run Cucumber features '\
|
26
|
+
'which are "WORK IN PROGRESS" and '\
|
27
|
+
'are allowed to fail') do |t|
|
28
|
+
t.cucumber_opts = %w{--format progress}
|
29
|
+
t.profile = 'wip'
|
43
30
|
end
|
44
31
|
|
45
|
-
desc 'Run
|
46
|
-
|
47
|
-
sh 'bundle exec rspec'
|
48
|
-
end
|
32
|
+
desc 'Run RSpec tests'
|
33
|
+
RSpec::Core::RakeTask.new(:rspec)
|
49
34
|
end
|
50
35
|
|
51
36
|
namespace :lint do
|
@@ -63,12 +48,27 @@ namespace :lint do
|
|
63
48
|
|
64
49
|
desc 'Lint our code with "rubocop"'
|
65
50
|
task :coding_guidelines do
|
66
|
-
|
51
|
+
if RUBY_VERSION >= '2'
|
52
|
+
sh 'bundle exec rubocop --fail-level E'
|
53
|
+
else
|
54
|
+
warn 'Your ruby version is not supported for code linting'
|
55
|
+
end
|
67
56
|
end
|
68
57
|
|
69
58
|
desc 'Check for relevant licenses in project'
|
70
59
|
task :licenses do
|
71
|
-
|
60
|
+
if RUBY_VERSION >= '2.3'
|
61
|
+
sh 'bundle exec license_finder'
|
62
|
+
else
|
63
|
+
warn 'Your ruby version is not supported for license checking'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
require 'yard-junk/rake'
|
69
|
+
YardJunk::Rake.define_task
|
70
|
+
rescue LoadError
|
71
|
+
warn 'yard-junk requires Ruby 2.3.0. Rake task lint:yard:junk not loaded.'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -79,8 +79,8 @@ end
|
|
79
79
|
namespace :docker do
|
80
80
|
desc 'Build docker image'
|
81
81
|
task :build, :cache, :version do |_, args|
|
82
|
-
args.with_defaults(:
|
83
|
-
args.with_defaults(:
|
82
|
+
args.with_defaults(version: 'latest')
|
83
|
+
args.with_defaults(cache: true)
|
84
84
|
|
85
85
|
docker_compose_file = Aruba::DockerComposeFile.new(File.expand_path('../docker-compose.yml', __FILE__))
|
86
86
|
docker_run_instance = Aruba::DockerRunInstance.new(docker_compose_file, :base)
|
data/appveyor.yml
CHANGED
@@ -6,6 +6,7 @@ version: "{build}"
|
|
6
6
|
branches:
|
7
7
|
only:
|
8
8
|
- master
|
9
|
+
- still
|
9
10
|
|
10
11
|
# Disable normal Windows builds in favor of our test script.
|
11
12
|
build: off
|
@@ -14,18 +15,18 @@ install:
|
|
14
15
|
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
15
16
|
- ruby --version
|
16
17
|
- gem --version
|
17
|
-
- gem install bundler
|
18
18
|
- bundler --version
|
19
19
|
- bundle install
|
20
20
|
- cinst ansicon
|
21
21
|
|
22
22
|
test_script:
|
23
|
-
- bundle exec rake test --trace
|
23
|
+
- bundle exec rake test:rspec --trace
|
24
24
|
|
25
25
|
environment:
|
26
26
|
matrix:
|
27
|
-
- ruby_version: '19'
|
28
|
-
- ruby_version: '20'
|
29
|
-
- ruby_version: '21'
|
30
27
|
- ruby_version: '22'
|
28
|
+
- ruby_version: '23'
|
29
|
+
- ruby_version: '24'
|
30
|
+
- ruby_version: '25'
|
31
|
+
- ruby_version: '26'
|
31
32
|
|
data/aruba.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
lib = ::File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'aruba/version'
|
@@ -6,33 +7,30 @@ require 'aruba/version'
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = 'aruba'
|
8
9
|
spec.version = Aruba::VERSION
|
9
|
-
spec.author =
|
10
|
+
spec.author = 'Aslak Hellesøy, Matt Wynne and other Aruba Contributors'
|
10
11
|
spec.description = 'Extension for popular TDD and BDD frameworks like "Cucumber", "RSpec" and "Minitest" to make testing commandline applications meaningful, easy and fun.'
|
11
12
|
spec.summary = "aruba-#{spec.version}"
|
12
13
|
spec.license = 'MIT'
|
13
14
|
spec.email = 'cukes@googlegroups.com'
|
14
|
-
spec.homepage = '
|
15
|
+
spec.homepage = 'https://github.com/cucumber/aruba'
|
15
16
|
|
16
|
-
spec.add_runtime_dependency '
|
17
|
-
spec.add_runtime_dependency '
|
18
|
-
spec.add_runtime_dependency '
|
19
|
-
spec.add_runtime_dependency '
|
20
|
-
spec.add_runtime_dependency '
|
17
|
+
spec.add_runtime_dependency 'childprocess', '~> 1.0'
|
18
|
+
spec.add_runtime_dependency 'contracts', '~> 0.13'
|
19
|
+
spec.add_runtime_dependency 'cucumber', '~> 2.4'
|
20
|
+
spec.add_runtime_dependency 'ffi', '~> 1.9'
|
21
|
+
spec.add_runtime_dependency 'rspec-expectations', '~> 3.4'
|
21
22
|
spec.add_runtime_dependency 'thor', '~> 0.19'
|
22
23
|
|
23
|
-
spec.add_development_dependency 'bundler', '
|
24
|
-
spec.rubygems_version =
|
25
|
-
spec.required_ruby_version = '>=
|
26
|
-
|
27
|
-
# spec.post_install_message = <<-EOS
|
28
|
-
# EOS
|
24
|
+
spec.add_development_dependency 'bundler', ['>= 1.7.0', '< 3.0']
|
25
|
+
spec.rubygems_version = '>= 1.6.1'
|
26
|
+
spec.required_ruby_version = '>= 2.2'
|
29
27
|
|
30
28
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
31
29
|
f.match(%r{^(test|spec|features)/})
|
32
30
|
end
|
33
31
|
|
34
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
-
spec.rdoc_options = [
|
36
|
-
spec.bindir =
|
37
|
-
spec.require_paths = [
|
33
|
+
spec.rdoc_options = ['--charset=UTF-8']
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.require_paths = ['lib']
|
38
36
|
end
|
data/bin/console
CHANGED
@@ -2,15 +2,6 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'aruba/console'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
module Aruba
|
10
|
-
class MyConsole
|
11
|
-
include Aruba::Api
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
include Aruba
|
16
|
-
Pry.start MyConsole.new
|
7
|
+
Aruba::Console.new.start
|
data/cucumber.yml
CHANGED
@@ -11,13 +11,6 @@ java_wip_opts = "--tags @wip-jruby-java-1.6:3" if defined?(JRUBY_VERSION) &&
|
|
11
11
|
|
12
12
|
ignore_opts = []
|
13
13
|
ignore_opts << '--tags ~@ignore'
|
14
|
-
ignore_opts << '--tags ~@unsupported-on-platform-java' if RUBY_PLATFORM.include? 'java'
|
15
|
-
ignore_opts << '--tags ~@unsupported-on-platform-mri' if !RUBY_PLATFORM.include? 'java'
|
16
|
-
ignore_opts << '--tags ~@unsupported-on-platform-windows' if FFI::Platform.windows?
|
17
|
-
ignore_opts << '--tags ~@unsupported-on-platform-unix' if FFI::Platform.unix?
|
18
|
-
ignore_opts << '--tags ~@unsupported-on-platform-mac' if FFI::Platform.mac?
|
19
|
-
ignore_opts << '--tags ~@unsupported-on-ruby-older-2' if RUBY_VERSION < '2'
|
20
|
-
ignore_opts << '--tags ~@requires-aruba-version-1' if Aruba::VERSION < '1'
|
21
14
|
ignore_opts = ignore_opts.join(' ')
|
22
15
|
%>
|
23
16
|
default: <%= std_opts %> --tags ~@wip <%= java_default_opts %> <%= ignore_opts %>
|
data/fixtures/cli-app/README.md
CHANGED
data/fixtures/cli-app/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -2,12 +2,12 @@ module SimpleCov
|
|
2
2
|
module Formatter
|
3
3
|
class HTMLFormatter
|
4
4
|
def format(result)
|
5
|
-
Dir[File.join(File.dirname(__FILE__),
|
5
|
+
Dir[File.join(File.dirname(__FILE__), '../public/*')].each do |path|
|
6
6
|
FileUtils.cp_r(path, asset_output_path)
|
7
7
|
end
|
8
8
|
|
9
|
-
File.open(File.join(output_path,
|
10
|
-
file.puts template(
|
9
|
+
File.open(File.join(output_path, 'index.html'), 'wb') do |file|
|
10
|
+
file.puts template('layout').result(binding)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/fixtures/empty-app/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/aruba/api.rb
CHANGED
@@ -6,16 +6,12 @@ require 'aruba/extensions/string/strip'
|
|
6
6
|
|
7
7
|
require 'aruba/platform'
|
8
8
|
require 'aruba/api/core'
|
9
|
-
require 'aruba/api/
|
10
|
-
|
11
|
-
if Aruba::VERSION <= '1.1.0'
|
12
|
-
require 'aruba/api/deprecated'
|
13
|
-
end
|
9
|
+
require 'aruba/api/commands'
|
14
10
|
|
15
11
|
require 'aruba/api/environment'
|
16
12
|
require 'aruba/api/filesystem'
|
17
13
|
require 'aruba/api/text'
|
18
|
-
require 'aruba/api/
|
14
|
+
require 'aruba/api/bundler'
|
19
15
|
|
20
16
|
Aruba.platform.require_matching_files('../matchers/**/*.rb', __FILE__)
|
21
17
|
|
@@ -27,10 +23,7 @@ module Aruba
|
|
27
23
|
include Aruba::Api::Commands
|
28
24
|
include Aruba::Api::Environment
|
29
25
|
include Aruba::Api::Filesystem
|
30
|
-
include Aruba::Api::Rvm
|
31
|
-
if Aruba::VERSION <= '1.1.0'
|
32
|
-
include Aruba::Api::Deprecated
|
33
|
-
end
|
34
26
|
include Aruba::Api::Text
|
27
|
+
include Aruba::Api::Bundler
|
35
28
|
end
|
36
29
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'aruba/api/environment'
|
2
|
+
|
3
|
+
module Aruba
|
4
|
+
module Api
|
5
|
+
module Bundler
|
6
|
+
include Environment
|
7
|
+
|
8
|
+
# Unset variables used by bundler
|
9
|
+
def unset_bundler_env_vars
|
10
|
+
%w[RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |key|
|
11
|
+
delete_environment_variable(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require 'aruba/platform'
|
4
|
+
require 'aruba/command'
|
5
|
+
|
6
|
+
# require 'win32/file' if File::ALT_SEPARATOR
|
7
|
+
|
8
|
+
# Aruba
|
9
|
+
module Aruba
|
10
|
+
# Api
|
11
|
+
module Api
|
12
|
+
# Command module
|
13
|
+
module Commands
|
14
|
+
# Resolve path for command using the PATH-environment variable
|
15
|
+
#
|
16
|
+
# @param [#to_s] program
|
17
|
+
# The name of the program which should be resolved
|
18
|
+
#
|
19
|
+
# @param [String] path
|
20
|
+
# The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
|
21
|
+
# UNIX-system
|
22
|
+
def which(program, path = nil)
|
23
|
+
with_environment do
|
24
|
+
# ENV is set within this block
|
25
|
+
path = ENV['PATH'] if path.nil?
|
26
|
+
|
27
|
+
Aruba.platform.which(program, path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Pipe data in file
|
32
|
+
#
|
33
|
+
# @param [String] file_name
|
34
|
+
# The file which should be used to pipe in data
|
35
|
+
def pipe_in_file(file_name)
|
36
|
+
file_name = expand_path(file_name)
|
37
|
+
|
38
|
+
File.open(file_name, 'r').each_line do |line|
|
39
|
+
last_command_started.write(line)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return all commands
|
44
|
+
#
|
45
|
+
# @return [Array]
|
46
|
+
# List of commands
|
47
|
+
def all_commands
|
48
|
+
aruba.command_monitor.registered_commands
|
49
|
+
end
|
50
|
+
|
51
|
+
# Last command started
|
52
|
+
def last_command_started
|
53
|
+
aruba.command_monitor.last_command_started
|
54
|
+
end
|
55
|
+
|
56
|
+
# Last command stopped
|
57
|
+
def last_command_stopped
|
58
|
+
aruba.command_monitor.last_command_stopped
|
59
|
+
end
|
60
|
+
|
61
|
+
# Stop all commands
|
62
|
+
#
|
63
|
+
# @yield [Command]
|
64
|
+
# If block is given use it to filter the commands which should be
|
65
|
+
# stoppend.
|
66
|
+
def stop_all_commands(&block)
|
67
|
+
cmds = if block_given?
|
68
|
+
all_commands.select(&block)
|
69
|
+
else
|
70
|
+
all_commands
|
71
|
+
end
|
72
|
+
|
73
|
+
cmds.each(&:stop)
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# Terminate all commands
|
79
|
+
#
|
80
|
+
# @yield [Command]
|
81
|
+
# If block is given use it to filter the commands which should be
|
82
|
+
# terminated.
|
83
|
+
def terminate_all_commands(&block)
|
84
|
+
cmds = if block_given?
|
85
|
+
all_commands.select(&block)
|
86
|
+
else
|
87
|
+
all_commands
|
88
|
+
end
|
89
|
+
|
90
|
+
cmds.each(&:terminate)
|
91
|
+
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
# Find a started command
|
96
|
+
#
|
97
|
+
# @param [String, Command] commandline
|
98
|
+
# The commandline
|
99
|
+
def find_command(commandline)
|
100
|
+
aruba.command_monitor.find(commandline)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Run given command and stop it if timeout is reached
|
104
|
+
#
|
105
|
+
# @param [String] cmd
|
106
|
+
# The command which should be executed
|
107
|
+
#
|
108
|
+
# @param [Hash] opts
|
109
|
+
# Options
|
110
|
+
#
|
111
|
+
# @option opts [Numeric] exit_timeout
|
112
|
+
# If the timeout is reached the command will be killed
|
113
|
+
#
|
114
|
+
# @option opts [Numeric] io_wait_timeout
|
115
|
+
# Wait for IO to finish
|
116
|
+
#
|
117
|
+
# @option opts [Numeric] startup_wait_time
|
118
|
+
# Wait for a command to start
|
119
|
+
#
|
120
|
+
# @option opts [String] stop_signal
|
121
|
+
# Use signal to stop command
|
122
|
+
#
|
123
|
+
# @yield [SpawnProcess]
|
124
|
+
# Run block with process
|
125
|
+
#
|
126
|
+
def run_command(cmd, opts = {})
|
127
|
+
command = prepare_command(cmd, opts)
|
128
|
+
|
129
|
+
unless command.interactive?
|
130
|
+
raise NotImplementedError,
|
131
|
+
'Running interactively is not supported with this process launcher.'
|
132
|
+
end
|
133
|
+
|
134
|
+
start_command(command)
|
135
|
+
|
136
|
+
block_given? ? yield(command) : command
|
137
|
+
end
|
138
|
+
|
139
|
+
# Run a command with aruba
|
140
|
+
#
|
141
|
+
# Checks for error during command execution and checks the output to detect
|
142
|
+
# an timeout error.
|
143
|
+
#
|
144
|
+
# @param [String] cmd
|
145
|
+
# The command to be executed
|
146
|
+
#
|
147
|
+
# @param [Hash] options
|
148
|
+
# Options for aruba
|
149
|
+
#
|
150
|
+
# @option options [Boolean] fail_on_error
|
151
|
+
# Should aruba fail on error?
|
152
|
+
#
|
153
|
+
# @option options [Numeric] exit_timeout
|
154
|
+
# Timeout for execution
|
155
|
+
#
|
156
|
+
# @option options [Numeric] io_wait_timeout
|
157
|
+
# Timeout for IO - STDERR, STDOUT
|
158
|
+
#
|
159
|
+
def run_command_and_stop(cmd, opts = {})
|
160
|
+
fail_on_error = if opts.key?(:fail_on_error)
|
161
|
+
opts.delete(:fail_on_error) == true
|
162
|
+
else
|
163
|
+
true
|
164
|
+
end
|
165
|
+
|
166
|
+
command = prepare_command(cmd, opts)
|
167
|
+
start_command(command)
|
168
|
+
command.stop
|
169
|
+
|
170
|
+
return unless fail_on_error
|
171
|
+
|
172
|
+
begin
|
173
|
+
expect(command).to have_finished_in_time
|
174
|
+
expect(command).to be_successfully_executed
|
175
|
+
rescue ::RSpec::Expectations::ExpectationNotMetError => e
|
176
|
+
aruba.announcer.activate(aruba.config.activate_announcer_on_command_failure)
|
177
|
+
aruba.event_bus.notify Events::CommandStopped.new(command)
|
178
|
+
raise e
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Provide data to command via stdin
|
183
|
+
#
|
184
|
+
# @param [String] input
|
185
|
+
# The input for the command
|
186
|
+
def type(input)
|
187
|
+
return close_input if input == "\u0004"
|
188
|
+
|
189
|
+
last_command_started.write(input << "\n")
|
190
|
+
end
|
191
|
+
|
192
|
+
# Close stdin
|
193
|
+
def close_input
|
194
|
+
last_command_started.close_io(:stdin)
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
|
199
|
+
# rubocop:disable Metrics/MethodLength
|
200
|
+
def prepare_command(cmd, opts)
|
201
|
+
exit_timeout = opts[:exit_timeout].nil? ? aruba.config.exit_timeout : opts[:exit_timeout]
|
202
|
+
io_wait_timeout = opts[:io_wait_timeout].nil? ? aruba.config.io_wait_timeout : opts[:io_wait_timeout]
|
203
|
+
stop_signal = opts[:stop_signal].nil? ? aruba.config.stop_signal : opts[:stop_signal]
|
204
|
+
startup_wait_time = opts[:startup_wait_time].nil? ? aruba.config.startup_wait_time : opts[:startup_wait_time]
|
205
|
+
|
206
|
+
cmd = replace_variables(cmd)
|
207
|
+
|
208
|
+
@commands ||= []
|
209
|
+
@commands << cmd
|
210
|
+
|
211
|
+
environment = aruba.environment
|
212
|
+
working_directory = expand_path('.')
|
213
|
+
event_bus = aruba.event_bus
|
214
|
+
|
215
|
+
cmd = Aruba.platform.detect_ruby(cmd)
|
216
|
+
|
217
|
+
mode = aruba.config.command_launcher
|
218
|
+
|
219
|
+
main_class = aruba.config.main_class
|
220
|
+
|
221
|
+
Command.new(
|
222
|
+
cmd,
|
223
|
+
mode: mode,
|
224
|
+
exit_timeout: exit_timeout,
|
225
|
+
io_wait_timeout: io_wait_timeout,
|
226
|
+
working_directory: working_directory,
|
227
|
+
environment: environment.to_hash,
|
228
|
+
main_class: main_class,
|
229
|
+
stop_signal: stop_signal,
|
230
|
+
startup_wait_time: startup_wait_time,
|
231
|
+
event_bus: event_bus
|
232
|
+
)
|
233
|
+
end
|
234
|
+
|
235
|
+
# rubocop:enable Metrics/MethodLength
|
236
|
+
|
237
|
+
def start_command(command)
|
238
|
+
aruba.config.before(:command, self, command)
|
239
|
+
|
240
|
+
command.start
|
241
|
+
|
242
|
+
stop_signal = command.stop_signal
|
243
|
+
aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
|
244
|
+
|
245
|
+
aruba.config.after(:command, self, command)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|