aruba 0.8.1 → 0.9.0.pre
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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +3 -1
- data/Gemfile +13 -10
- data/History.md +25 -7
- data/README.md +6 -1
- data/Rakefile +16 -3
- data/aruba.gemspec +10 -2
- data/bin/aruba +7 -0
- data/cucumber.yml +11 -2
- data/features/api/command/extract_text.feature +97 -0
- data/features/api/command/unescape_text.feature +119 -0
- data/features/api/core/expand_path.feature +16 -0
- data/features/api/{cd.feature → filesystem/cd.feature} +2 -1
- data/features/api/filesystem/create_directory.feature +57 -0
- data/features/api/filesystem/disk_usage.feature +151 -0
- data/features/api/filesystem/does_exist.feature +62 -0
- data/features/api/filesystem/is_absolute.feature +48 -0
- data/features/api/filesystem/is_directory.feature +53 -0
- data/features/api/filesystem/is_file.feature +54 -0
- data/features/api/filesystem/is_relative.feature +48 -0
- data/features/cli/console.feature +52 -0
- data/features/configuration/console_history_file.feature +38 -0
- data/features/configuration/exit_timeout.feature +2 -1
- data/features/configuration/fixtures_path_prefix.feature +0 -1
- data/features/configuration/home_directory.feature +0 -1
- data/features/configuration/io_timeout.feature +0 -1
- data/features/configuration/keep_ansi.feature +1 -2
- data/features/configuration/log_level.feature +38 -0
- data/features/configuration/physical_block_size.feature +53 -0
- data/features/configuration/remove_ansi_escape_sequences.feature +38 -0
- data/features/configuration/root_directory.feature +0 -1
- data/features/configuration/working_directory.feature +2 -1
- data/features/fixtures/cli-app/README.md +5 -0
- data/features/fixtures/cli-app/lib/cli/app.rb +1 -1
- data/features/fixtures/cli-app/spec/spec_helper.rb +1 -2
- data/features/fixtures/cli-app/spec/support/aruba.rb +1 -0
- data/features/fixtures/empty-app/lib/cli/app.rb +1 -1
- data/features/fixtures/empty-app/spec/spec_helper.rb +1 -1
- data/features/step_definitions/aruba_dev_steps.rb +12 -1
- data/features/support/env.rb +1 -1
- data/lib/aruba/announcer.rb +1 -14
- data/lib/aruba/api.rb +6 -6
- data/lib/aruba/api/command.rb +74 -12
- data/lib/aruba/api/core.rb +18 -11
- data/lib/aruba/api/deprecated.rb +60 -72
- data/lib/aruba/api/filesystem.rb +41 -16
- data/lib/aruba/aruba_logger.rb +77 -0
- data/lib/aruba/aruba_path.rb +33 -0
- data/lib/aruba/basic_configuration.rb +2 -2
- data/lib/aruba/cli.rb +11 -0
- data/lib/aruba/config.rb +13 -3
- data/lib/aruba/config/jruby.rb +5 -2
- data/lib/aruba/console.rb +66 -0
- data/lib/aruba/console/help.rb +33 -0
- data/lib/aruba/contracts/is_power_of_two.rb +15 -0
- data/lib/aruba/cucumber.rb +27 -10
- data/lib/aruba/cucumber/hooks.rb +15 -8
- data/lib/aruba/disk_usage_calculator.rb +7 -0
- data/lib/aruba/file_size.rb +52 -0
- data/lib/aruba/in_process.rb +1 -1
- data/lib/aruba/jruby.rb +1 -1
- data/lib/aruba/matchers/command.rb +1 -1
- data/lib/aruba/matchers/directory.rb +1 -1
- data/lib/aruba/matchers/environment.rb +1 -1
- data/lib/aruba/matchers/file.rb +1 -1
- data/lib/aruba/matchers/path.rb +1 -1
- data/lib/aruba/matchers/path/match_path_pattern.rb +1 -1
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +1 -1
- data/lib/aruba/platform.rb +14 -242
- data/lib/aruba/{creators → platforms}/aruba_file_creator.rb +3 -3
- data/lib/aruba/{creators → platforms}/aruba_fixed_size_file_creator.rb +2 -2
- data/lib/aruba/platforms/simple_table.rb +36 -0
- data/lib/aruba/platforms/unix_command_string.rb +24 -0
- data/lib/aruba/platforms/unix_environment_variables.rb +130 -0
- data/lib/aruba/platforms/unix_platform.rb +226 -0
- data/lib/aruba/platforms/unix_which.rb +83 -0
- data/lib/aruba/platforms/windows_command_string.rb +23 -0
- data/lib/aruba/platforms/windows_environment_variables.rb +83 -0
- data/lib/aruba/platforms/windows_platform.rb +39 -0
- data/lib/aruba/platforms/windows_which.rb +104 -0
- data/lib/aruba/process_monitor.rb +3 -3
- data/lib/aruba/processes/basic_process.rb +23 -3
- data/lib/aruba/processes/debug_process.rb +2 -2
- data/lib/aruba/processes/in_process.rb +1 -1
- data/lib/aruba/processes/spawn_process.rb +10 -4
- data/lib/aruba/reporting.rb +1 -1
- data/lib/aruba/rspec.rb +8 -6
- data/lib/aruba/runtime.rb +8 -5
- data/lib/aruba/version.rb +1 -1
- data/spec/aruba/api_spec.rb +25 -23
- data/spec/aruba/aruba_path_spec.rb +37 -0
- data/spec/aruba/jruby_spec.rb +1 -1
- data/spec/aruba/matchers/file_spec.rb +2 -2
- data/spec/aruba/matchers/path_spec.rb +3 -3
- data/spec/aruba/platform/simple_table_spec.rb +23 -0
- data/spec/aruba/platform/windows_environment_variables_spec.rb +500 -0
- data/spec/aruba/spawn_process_spec.rb +3 -1
- metadata +90 -12
- data/lib/aruba/contracts/is_a.rb +0 -21
- data/lib/aruba/environment.rb +0 -121
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'aruba/aruba_path'
|
2
|
+
|
3
|
+
module Aruba
|
4
|
+
module Contracts
|
5
|
+
class IsPowerOfTwo
|
6
|
+
def self.valid?(x)
|
7
|
+
# explanation for algorithm can be found here:
|
8
|
+
# http://www.exploringbinary.com/ten-ways-to-check-if-an-integer-is-a-power-of-two-in-c/
|
9
|
+
x != 0 && (x & (x - 1)) == 0 ? true : false
|
10
|
+
rescue
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/aruba/cucumber.rb
CHANGED
@@ -66,7 +66,7 @@ Given /^a mocked home directory$/ do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
Given /^(?:a|the) directory(?: named)? "([^"]*)" does not exist$/ do |directory_name|
|
69
|
-
|
69
|
+
remove(directory_name, :force => true)
|
70
70
|
end
|
71
71
|
|
72
72
|
When /^I write to "([^"]*)" with:$/ do |file_name, file_content|
|
@@ -86,15 +86,15 @@ When /^I append to "([^"]*)" with "([^"]*)"$/ do |file_name, file_content|
|
|
86
86
|
end
|
87
87
|
|
88
88
|
When /^I remove (?:a|the) file(?: named)? "([^"]*)"$/ do |file_name|
|
89
|
-
|
89
|
+
remove(file_name)
|
90
90
|
end
|
91
91
|
|
92
92
|
Given /^(?:a|the) file(?: named)? "([^"]*)" does not exist$/ do |file_name|
|
93
|
-
|
93
|
+
remove(file_name, :force => true)
|
94
94
|
end
|
95
95
|
|
96
96
|
When(/^I remove (?:a|the) directory(?: named)? "(.*?)"$/) do |directory_name|
|
97
|
-
|
97
|
+
remove(directory_name)
|
98
98
|
end
|
99
99
|
|
100
100
|
When /^I cd to "([^"]*)"$/ do |dir|
|
@@ -121,22 +121,36 @@ end
|
|
121
121
|
|
122
122
|
When /^I run "(.*)"$/ do |cmd|
|
123
123
|
warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
|
124
|
-
|
124
|
+
|
125
|
+
cmd = unescape_text(cmd)
|
126
|
+
cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
|
127
|
+
|
128
|
+
run_simple(cmd, false)
|
125
129
|
end
|
126
130
|
|
127
131
|
When /^I run `([^`]*)`$/ do |cmd|
|
128
|
-
|
132
|
+
cmd = unescape_text(cmd)
|
133
|
+
cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
|
134
|
+
|
135
|
+
run_simple(cmd, false)
|
129
136
|
end
|
130
137
|
|
131
138
|
When /^I successfully run "(.*)"$/ do |cmd|
|
132
139
|
warn(%{\e[35m The /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
|
133
|
-
|
140
|
+
|
141
|
+
cmd = unescape_text(cmd)
|
142
|
+
cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
|
143
|
+
|
144
|
+
run_simple(cmd)
|
134
145
|
end
|
135
146
|
|
136
147
|
## I successfully run `echo -n "Hello"`
|
137
148
|
## I successfully run `sleep 29` for up to 30 seconds
|
138
149
|
When /^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/ do |cmd, secs|
|
139
|
-
|
150
|
+
cmd = unescape_text(cmd)
|
151
|
+
cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
|
152
|
+
|
153
|
+
run_simple(cmd, true, secs && secs.to_i)
|
140
154
|
end
|
141
155
|
|
142
156
|
When /^I run "([^"]*)" interactively$/ do |cmd|
|
@@ -145,11 +159,14 @@ When /^I run "([^"]*)" interactively$/ do |cmd|
|
|
145
159
|
end
|
146
160
|
|
147
161
|
When /^I run `([^`]*)` interactively$/ do |cmd|
|
148
|
-
|
162
|
+
cmd = unescape_text(cmd)
|
163
|
+
cmd = extract_text(cmd) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences
|
164
|
+
|
165
|
+
@interactive = run(cmd)
|
149
166
|
end
|
150
167
|
|
151
168
|
When /^I type "([^"]*)"$/ do |input|
|
152
|
-
type(input)
|
169
|
+
type(unescape_text(input))
|
153
170
|
end
|
154
171
|
|
155
172
|
When /^I close the stdin stream$/ do
|
data/lib/aruba/cucumber/hooks.rb
CHANGED
@@ -6,9 +6,9 @@ if Aruba::VERSION >= '1.0.0'
|
|
6
6
|
Around do |_, block|
|
7
7
|
begin
|
8
8
|
if RUBY_VERSION < '1.9'
|
9
|
-
old_env = ENV.to_hash
|
9
|
+
old_env = ENV.to_hash.dup
|
10
10
|
else
|
11
|
-
old_env = ENV.to_h
|
11
|
+
old_env = ENV.to_h.dup
|
12
12
|
end
|
13
13
|
|
14
14
|
block.call
|
@@ -47,7 +47,7 @@ Before('@announce-command') do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
Before('@announce-cmd') do
|
50
|
-
Aruba
|
50
|
+
Aruba.platform.deprecated 'The use of "@announce-cmd"-hook is deprecated. Please use "@announce-command"'
|
51
51
|
|
52
52
|
announcer.activate :command
|
53
53
|
end
|
@@ -61,7 +61,7 @@ Before('@announce-stderr') do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
Before('@announce-dir') do
|
64
|
-
Aruba
|
64
|
+
Aruba.platform.deprecated 'The use of "@announce-dir"-hook is deprecated. Please use "@announce-directory"'
|
65
65
|
|
66
66
|
announcer.activate :directory
|
67
67
|
end
|
@@ -71,13 +71,13 @@ Before('@announce-directory') do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
Before('@announce-env') do
|
74
|
-
Aruba
|
74
|
+
Aruba.platform.deprecated 'The use of "@announce-env"-hook is deprecated. Please use "@announce-modified-environment"'
|
75
75
|
|
76
76
|
announcer.activate :environment
|
77
77
|
end
|
78
78
|
|
79
79
|
Before('@announce-environment') do
|
80
|
-
Aruba
|
80
|
+
Aruba.platform.deprecated '@announce-environment is deprecated. Use @announce-modified-environment instead'
|
81
81
|
|
82
82
|
announcer.activate :modified_environment
|
83
83
|
end
|
@@ -100,6 +100,7 @@ Before('@announce') do
|
|
100
100
|
announcer.activate :stderr
|
101
101
|
announcer.activate :directory
|
102
102
|
announcer.activate :modified_environment
|
103
|
+
announcer.activate :full_environment
|
103
104
|
announcer.activate :environment
|
104
105
|
announcer.activate :timeout
|
105
106
|
end
|
@@ -113,11 +114,17 @@ end
|
|
113
114
|
# end
|
114
115
|
|
115
116
|
Before('@ansi') do
|
116
|
-
@
|
117
|
+
Aruba.platform.deprecated('The use of "@ansi" is deprecated. Use "@keep-ansi-escape-sequences" instead')
|
118
|
+
|
119
|
+
aruba.config.remove_ansi_escape_sequences = false
|
120
|
+
end
|
121
|
+
|
122
|
+
Before('@keep-ansi-escape-sequences') do
|
123
|
+
aruba.config.remove_ansi_escape_sequences = false
|
117
124
|
end
|
118
125
|
|
119
126
|
Before '@mocked_home_directory' do
|
120
|
-
Aruba
|
127
|
+
Aruba.platform.deprecated('The use of "@mocked_home_directory" is deprecated. Use "@mocked-home-directory" instead')
|
121
128
|
|
122
129
|
set_environment_variable 'HOME', expand_path('.')
|
123
130
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module Aruba
|
4
|
+
class FileSize
|
5
|
+
include Comparable
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
attr_reader :bytes, :divisor
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
def initialize(bytes)
|
14
|
+
@bytes = bytes
|
15
|
+
@divisor = 1024
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_byte
|
19
|
+
bytes
|
20
|
+
end
|
21
|
+
alias_method :to_i, :to_byte
|
22
|
+
|
23
|
+
def to_f
|
24
|
+
to_i.to_f
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
to_i.to_s
|
29
|
+
end
|
30
|
+
alias_method :inspect, :to_s
|
31
|
+
|
32
|
+
def coerce(other)
|
33
|
+
[bytes, other]
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_kibi_byte
|
37
|
+
to_byte.to_f / divisor
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_mebi_byte
|
41
|
+
to_kibi_byte.to_f / divisor
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_gibi_byte
|
45
|
+
to_mebi_byte.to_f / divisor
|
46
|
+
end
|
47
|
+
|
48
|
+
def <=>(other)
|
49
|
+
to_i <=> other.to_i
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/aruba/in_process.rb
CHANGED
@@ -4,7 +4,7 @@ require 'aruba/platform'
|
|
4
4
|
module Aruba
|
5
5
|
class InProcess < Aruba::Processes::InProcess
|
6
6
|
def initialize(*args)
|
7
|
-
Aruba
|
7
|
+
Aruba.platform.deprecated('The use of "Aruba::InProcess" is deprecated. Use "Aruba::Processes::InProcess" instead.')
|
8
8
|
|
9
9
|
super
|
10
10
|
end
|
data/lib/aruba/jruby.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Aruba
|
1
|
+
Aruba.platform.require_matching_files('../command/**/*.rb', __FILE__)
|
@@ -1 +1 @@
|
|
1
|
-
Aruba
|
1
|
+
Aruba.platform.require_matching_files('../directory/**/*.rb', __FILE__)
|
@@ -1 +1 @@
|
|
1
|
-
Aruba
|
1
|
+
Aruba.platform.require_matching_files('../matchers/environment/*.rb', __FILE__)
|
data/lib/aruba/matchers/file.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Aruba
|
1
|
+
Aruba.platform.require_matching_files('../file/**/*.rb', __FILE__)
|
data/lib/aruba/matchers/path.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Aruba
|
1
|
+
Aruba.platform.require_matching_files('../path/**/*.rb', __FILE__)
|
@@ -24,7 +24,7 @@
|
|
24
24
|
# end
|
25
25
|
RSpec::Matchers.define :match_path_pattern do |_|
|
26
26
|
match do |actual|
|
27
|
-
Aruba
|
27
|
+
Aruba.platform.deprecated('The use of `expect().to match_path_pattern` is deprecated. Please use `expect().to include pattern /regex/` instead.')
|
28
28
|
|
29
29
|
next !actual.select { |a| a == expected }.empty? if expected.is_a? String
|
30
30
|
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# end
|
19
19
|
RSpec::Matchers.define :include_regexp do |expected|
|
20
20
|
match do |actual|
|
21
|
-
Aruba
|
21
|
+
Aruba.platform.deprecated('The use of "include_regexp"-matchers is deprecated. It will be removed soon.')
|
22
22
|
|
23
23
|
!actual.grep(expected).empty?
|
24
24
|
end
|
data/lib/aruba/platform.rb
CHANGED
@@ -1,249 +1,21 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'thread'
|
2
|
+
require 'aruba/platforms/unix_platform'
|
3
|
+
require 'aruba/platforms/windows_platform'
|
3
4
|
|
4
5
|
module Aruba
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
# Those methods can be changed at any time in the feature or removed without
|
9
|
-
# any further notice.
|
10
|
-
module Platform
|
11
|
-
def detect_ruby(cmd)
|
12
|
-
if cmd =~ /^ruby\s/
|
13
|
-
cmd.gsub(/^ruby\s/, "#{current_ruby} ")
|
14
|
-
else
|
15
|
-
cmd
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def deprecated(msg)
|
20
|
-
warn(format('%s. Called by %s', msg, caller[1]))
|
21
|
-
end
|
22
|
-
|
23
|
-
def current_ruby
|
24
|
-
::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
25
|
-
end
|
26
|
-
|
27
|
-
# @deprecated
|
28
|
-
# Add newline at the end
|
29
|
-
def ensure_newline(str)
|
30
|
-
deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon')
|
31
|
-
|
32
|
-
str.chomp << "\n"
|
33
|
-
end
|
34
|
-
|
35
|
-
def require_matching_files(pattern, base)
|
36
|
-
if RUBY_VERSION < '1.9.'
|
37
|
-
::Dir.glob(::File.expand_path(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
|
38
|
-
else
|
39
|
-
::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Create directory and subdirectories
|
44
|
-
def mkdir(dir_name)
|
45
|
-
dir_name = ::File.expand_path(dir_name)
|
46
|
-
|
47
|
-
::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Remove file, directory + sub-directories
|
51
|
-
def rm(paths, options = {})
|
52
|
-
paths = Array(paths).map { |p| ::File.expand_path(p) }
|
53
|
-
|
54
|
-
FileUtils.rm_r(paths, options)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Get current working directory
|
58
|
-
def getwd
|
59
|
-
Dir.getwd
|
60
|
-
end
|
61
|
-
|
62
|
-
# Change to directory
|
63
|
-
def chdir(dir_name, &block)
|
64
|
-
dir_name = ::File.expand_path(dir_name.to_s)
|
65
|
-
|
66
|
-
begin
|
67
|
-
if RUBY_VERSION <= '1.9.3'
|
68
|
-
old_env = ENV.to_hash
|
69
|
-
else
|
70
|
-
old_env = ENV.to_h
|
71
|
-
end
|
72
|
-
|
73
|
-
ENV['OLDPWD'] = getwd
|
74
|
-
ENV['PWD'] = dir_name
|
75
|
-
::Dir.chdir(dir_name, &block)
|
76
|
-
ensure
|
77
|
-
ENV.clear
|
78
|
-
ENV.update old_env
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Touch file, directory
|
83
|
-
def touch(args, options)
|
84
|
-
FileUtils.touch(args, options)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Copy file/directory
|
88
|
-
def cp(args, options)
|
89
|
-
FileUtils.cp_r(args, options)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Change mode of file/directory
|
93
|
-
def chmod(mode, args, options)
|
94
|
-
FileUtils.chmod_R(mode, args, options)
|
95
|
-
end
|
96
|
-
|
97
|
-
# Exists and is file
|
98
|
-
def file?(f)
|
99
|
-
File.file? f
|
100
|
-
end
|
101
|
-
|
102
|
-
# Exists and is directory
|
103
|
-
def directory?(f)
|
104
|
-
File.directory? f
|
105
|
-
end
|
106
|
-
|
107
|
-
# Path Exists
|
108
|
-
def exist?(f)
|
109
|
-
File.exist? f
|
110
|
-
end
|
111
|
-
|
112
|
-
# Path is executable
|
113
|
-
def executable_file?(f)
|
114
|
-
File.file?(f) && File.executable?(f)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Expand path
|
118
|
-
def expand_path(path, base)
|
119
|
-
File.expand_path(path, base)
|
120
|
-
end
|
121
|
-
|
122
|
-
def absolute_path?(path)
|
123
|
-
Pathname.new(path).absolute?
|
124
|
-
end
|
125
|
-
|
126
|
-
# Check if command is relative
|
127
|
-
#
|
128
|
-
# @return [TrueClass, FalseClass]
|
129
|
-
# true
|
130
|
-
# * bin/command.sh
|
131
|
-
#
|
132
|
-
# false
|
133
|
-
# * /bin/command.sh
|
134
|
-
# * command.sh
|
135
|
-
def relative_command?(path)
|
136
|
-
p = Pathname.new(path)
|
137
|
-
p.relative? && p.basename != p
|
138
|
-
end
|
139
|
-
|
140
|
-
# Write to file
|
141
|
-
def write_file(path, content)
|
142
|
-
if RUBY_VERSION < '1.9'
|
143
|
-
File.open(path, 'wb') do |f|
|
144
|
-
f.print content
|
145
|
-
end
|
146
|
-
else
|
147
|
-
File.write(path, content)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# Unescape string
|
152
|
-
#
|
153
|
-
# @param [String] string
|
154
|
-
# The string which should be unescaped, e.g. the output of a command
|
155
|
-
#
|
156
|
-
# @return
|
157
|
-
# The string stripped from escape sequences
|
158
|
-
def unescape(string, keep_ansi = true)
|
159
|
-
string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
|
160
|
-
string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless keep_ansi
|
161
|
-
string
|
162
|
-
end
|
163
|
-
|
164
|
-
# Resolve path for command using the PATH-environment variable
|
165
|
-
#
|
166
|
-
# Mostly taken from here: https://github.com/djberg96/ptools
|
167
|
-
#
|
168
|
-
# @param [#to_s] program
|
169
|
-
# The name of the program which should be resolved
|
170
|
-
#
|
171
|
-
# @param [String] path
|
172
|
-
# The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
|
173
|
-
# UNIX-system
|
174
|
-
#
|
175
|
-
# rubocop:disable Metrics/MethodLength
|
176
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
177
|
-
def which(program, path = ENV['PATH'])
|
178
|
-
on_windows = false
|
179
|
-
on_windows = true if File::ALT_SEPARATOR
|
180
|
-
|
181
|
-
program = program.to_s
|
182
|
-
|
183
|
-
path_exts = ENV['PATHEXT'] ? ('.{' + ENV['PATHEXT'].tr(';', ',').tr('.','') + '}').downcase : '.{exe,com,bat}' if on_windows
|
184
|
-
|
185
|
-
raise ArgumentError, "ENV['PATH'] cannot be empty" if path.nil? || path.empty?
|
186
|
-
|
187
|
-
# Bail out early if an absolute path is provided or the command path is relative
|
188
|
-
# Examples: /usr/bin/command or bin/command.sh
|
189
|
-
if Aruba::Platform.absolute_path?(program) || Aruba::Platform.relative_command?(program)
|
190
|
-
program += path_exts if on_windows && File.extname(program).empty?
|
191
|
-
|
192
|
-
found = Dir[program].first
|
193
|
-
|
194
|
-
return File.expand_path(found) if found && Aruba::Platform.executable_file?(found)
|
195
|
-
return nil
|
196
|
-
end
|
197
|
-
|
198
|
-
# Iterate over each path glob the dir + program.
|
199
|
-
path.split(File::PATH_SEPARATOR).each do |dir|
|
200
|
-
dir = Aruba::Platform.expand_path(dir, Dir.getwd)
|
201
|
-
|
202
|
-
next unless Aruba::Platform.exist?(dir) # In case of bogus second argument
|
203
|
-
file = File.join(dir, program)
|
204
|
-
|
205
|
-
# Dir[] doesn't handle backslashes properly, so convert them. Also, if
|
206
|
-
# the program name doesn't have an extension, try them all.
|
207
|
-
if on_windows
|
208
|
-
file = file.tr("\\", "/")
|
209
|
-
file += path_exts if File.extname(program).empty?
|
210
|
-
end
|
211
|
-
|
212
|
-
found = Dir[file].first
|
6
|
+
PLATFORM_MUTEX = Mutex.new
|
7
|
+
end
|
213
8
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
return found
|
218
|
-
end
|
219
|
-
end
|
9
|
+
module Aruba
|
10
|
+
Platform = [Platforms::WindowsPlatform, Platforms::UnixPlatform].find(&:match?)
|
11
|
+
end
|
220
12
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
13
|
+
module Aruba
|
14
|
+
PLATFORM_MUTEX.synchronize do
|
15
|
+
@platform = Platform.new
|
16
|
+
end
|
225
17
|
|
226
|
-
|
227
|
-
|
228
|
-
:ensure_newline, \
|
229
|
-
:require_matching_files, \
|
230
|
-
:mkdir, \
|
231
|
-
:rm, \
|
232
|
-
:chdir, \
|
233
|
-
:deprecated, \
|
234
|
-
:touch, \
|
235
|
-
:cp, \
|
236
|
-
:chmod, \
|
237
|
-
:file?, \
|
238
|
-
:directory?, \
|
239
|
-
:exist?, \
|
240
|
-
:expand_path, \
|
241
|
-
:absolute_path?, \
|
242
|
-
:relative_command?, \
|
243
|
-
:executable_file?, \
|
244
|
-
:unescape, \
|
245
|
-
:getwd, \
|
246
|
-
:which, \
|
247
|
-
:write_file
|
18
|
+
class << self
|
19
|
+
attr_reader :platform
|
248
20
|
end
|
249
21
|
end
|