Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Rebased] Improve AppVeyor build #567

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
19fe24c
Test on appveyor only with Ruby 2.0 and up
mvz Nov 7, 2017
45f9f46
Wrap long lines
mvz Nov 8, 2017
113d5cf
Remove trailing blank space
mvz Nov 8, 2017
eb645e4
Make command_runtime_environment blank by default
mvz Nov 8, 2017
f5a8fba
Clean up environment variable handling
mvz Nov 8, 2017
6b51f06
Remove parameters with defaults
mvz Nov 8, 2017
e871767
Replace ENV.to_hash with platform-specific code
mvz Nov 8, 2017
5073f66
Simplify specs for stderr handling
mvz Nov 8, 2017
1f24406
Test command and arguments for SpawnProcess
mvz Nov 8, 2017
330fb90
Clean up spec for ChildProcess launch error
mvz Mar 11, 2018
85f4b99
Unify preparations for specs for SpawnProcess#start
mvz Mar 11, 2018
c77da7b
Add specs for #to_s for command string classes
mvz Mar 11, 2018
a295dd6
Properly escape command and arguments on windows
mvz Mar 11, 2018
ea5c3b6
Remove #to_s from CommandString classes
mvz Mar 11, 2018
95dc752
Replace match? to support older Rubies
mvz Mar 11, 2018
7ca2e64
Allow any line ending
mvz Mar 11, 2018
6d01a37
Make spec pass with Windows' read-only permissions
mvz Mar 11, 2018
9f899bf
Skip permission scenarios on Windows
mvz Mar 11, 2018
8b441b9
Use correct path separator in RSpec setup
mvz Mar 14, 2018
9f97f96
Skip scenarios tagged with `@requires-bash` unless bash is installed
xtrasimplicity May 19, 2018
2210189
Moved `@requires-bash` before hook to hooks.rb
xtrasimplicity May 19, 2018
bdad6ea
Updated `@requires-bash` before hook.
xtrasimplicity May 19, 2018
dcd0015
Fixed `run_commands` feature on Windows
xtrasimplicity May 19, 2018
5859fb3
Feature - Run_commands: Added Batch program scenarios
xtrasimplicity May 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ test_script:

environment:
matrix:
- ruby_version: '19'
- ruby_version: '20'
- ruby_version: '200'
- ruby_version: '21'
- ruby_version: '22'

41 changes: 40 additions & 1 deletion features/01_getting_started_with_aruba/run_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,46 @@ Feature: Run commands with Aruba
When I successfully run `cucumber`
Then the features should all pass

@requires-ruby

@requires-cmd
Scenario: Batch Program
Given an executable named "bin/aruba-test-cli.bat" with:
"""bash
echo "Hello, Aruba!"
"""
And a file named "features/hello_aruba.feature" with:
"""
Feature: Getting Started With Aruba
Scenario: First Run of Command
Given I successfully run `aruba-test-cli`
Then the output should contain:
\"\"\"
Hello, Aruba!
\"\"\"
"""
When I successfully run `cucumber`
Then the features should all pass

@requires-cmd
Scenario: Batch Program run via cmd
Given a file named "features/hello_aruba.feature" with:
"""
Feature: Getting Started With Aruba
Scenario: First Run of Command
Given a file named "cli.bat" with:
\"\"\"
echo "Hello, Aruba!"
\"\"\"
When I successfully run `cmd.exe /c cli.bat`
Then the output should contain:
\"\"\"
Hello, Aruba!
\"\"\"
"""
When I successfully run `cucumber`
Then the features should all pass

@requires-ruby @unsupported-on-platform-windows
Scenario: Ruby Program
Given an executable named "bin/aruba-test-cli" with:
"""ruby
Expand Down
10 changes: 5 additions & 5 deletions features/02_configure_aruba/command_runtime_environment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'

Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end

RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -44,7 +44,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'

Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end

RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -67,7 +67,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'

Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end

RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -90,7 +90,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'

Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end

RSpec.describe 'Environment command', :type => :aruba do
Expand All @@ -113,7 +113,7 @@ Feature: Define default process environment
ENV['LONG_LONG_VARIABLE'] = 'y'

Aruba.configure do |config|
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
config.command_runtime_environment = { 'LONG_LONG_VARIABLE' => 'x' }
end

RSpec.describe 'Environment command', :type => :aruba do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@unsupported-on-platform-windows
Feature: Check if path has permissions in filesystem

If you need to check if a given path has some permissions in filesystem, you
Expand Down
20 changes: 20 additions & 0 deletions features/step_definitions/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,23 @@
skip_this_scenario
end
end

Before('@requires-bash') do |scenario|
next if Aruba.platform.which('bash')

if Cucumber::VERSION < '2'
scenario.skip_invoke!
else
skip_this_scenario
end
end

Before('@requires-cmd') do |scenario|
next if Aruba.platform.which('cmd')

if Cucumber::VERSION < '2'
scenario.skip_invoke!
else
skip_this_scenario
end
end
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@

# set environment variable so child processes will merge their coverage data with parent process's coverage data.
ENV['RUBYOPT'] = "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}"
end
end
3 changes: 0 additions & 3 deletions fixtures/spawn_process/stderr.sh

This file was deleted.

2 changes: 1 addition & 1 deletion lib/aruba/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Configuration < BasicConfiguration
option_accessor :io_wait_timeout, contract: { Num => Num }, default: 0.1
option_accessor :startup_wait_time, contract: { Num => Num }, default: 0
option_accessor :fixtures_directories, contract: { Array => ArrayOf[String] }, default: %w(features/fixtures spec/fixtures test/fixtures fixtures)
option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: ENV.to_hash
option_accessor :command_runtime_environment, contract: { Hash => Hash }, default: {}
# rubocop:disable Metrics/LineLength
option_accessor(:command_search_paths, contract: { ArrayOf[String] => ArrayOf[String] }) { |config| [File.join(config.root_directory.value, 'bin'), File.join(config.root_directory.value, 'exe')] }
# rubocop:enable Metrics/LineLength
Expand Down
2 changes: 1 addition & 1 deletion lib/aruba/platforms/local_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LocalEnvironment
# @yield
# The block of code which should with local ENV
def call(env)
old_env = ENV.to_hash.dup
old_env = Aruba.platform.environment_variables.hash_from_env

ENV.clear
ENV.update env
Expand Down
11 changes: 7 additions & 4 deletions lib/aruba/platforms/unix_command_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ module Aruba
# Platforms
module Platforms
# This is a command which should be run
class UnixCommandString < SimpleDelegator
def initialize(cmd)
__setobj__ cmd
#
# @private
class UnixCommandString
def initialize(command, *arguments)
@command = command
@arguments = arguments
end

# Convert to array
def to_a
[__getobj__]
[@command, *@arguments]
end
end
end
Expand Down
20 changes: 8 additions & 12 deletions lib/aruba/platforms/unix_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def initialize(env = ENV)
def update(other_env)
actions << UpdateAction.new(other_env)

UnixEnvironmentVariables.new(to_h)
self
end

# Fetch variable from environment
Expand Down Expand Up @@ -184,11 +184,7 @@ def respond_to_missing?(name, _private)
# @return [Hash]
# A new hash from environment
def to_h
if RUBY_VERSION < '2.0'
Marshal.load(Marshal.dump(prepared_environment.to_hash))
else
Marshal.load(Marshal.dump(prepared_environment.to_h))
end
actions.inject(hash_from_env.merge(env)) { |a, e| e.call(a) }
end

# Reset environment
Expand All @@ -200,14 +196,14 @@ def clear
value
end

def self.hash_from_env
ENV.to_hash
end

private

def prepared_environment
if RUBY_VERSION == '1.9.3'
actions.inject(ENV.to_hash.merge(env)) { |a, e| e.call(a) }
else
actions.each_with_object(ENV.to_hash.merge(env)) { |e, a| a = e.call(a) }
end
def hash_from_env
self.class.hash_from_env
end
end
end
Expand Down
20 changes: 16 additions & 4 deletions lib/aruba/platforms/windows_command_string.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'delegate'

# Aruba
module Aruba
# Platforms
Expand All @@ -9,14 +7,28 @@ module Platforms
# This adds `cmd.exec` in front of commmand
#
# @private
class WindowsCommandString < SimpleDelegator
class WindowsCommandString
def initialize(command, *arguments)
@command = command
@arguments = arguments
end

# Convert to array
def to_a
[cmd_path, '/c', __getobj__]
[cmd_path, '/c', [escaped_command, *escaped_arguments].join(' ')]
end

private

def escaped_arguments
@arguments.map { |arg| arg.gsub(/"/, '"""') }.
map { |arg| arg =~ / / ? "\"#{arg}\"" : arg }
end

def escaped_command
@command.gsub(/ /, '""" """')
end

def cmd_path
Aruba.platform.which('cmd.exe')
end
Expand Down
24 changes: 17 additions & 7 deletions lib/aruba/platforms/windows_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ module Platforms
# env["PATH"]
# # => nil
class WindowsEnvironmentVariables < UnixEnvironmentVariables
def initialize(env = ENV.to_hash)
@actions = []

@env = env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }
def initialize(env = ENV)
super(upcase_env env)
end

def update(other_env, &block)
other_env = other_env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }

super(other_env, &block)
super(upcase_env(other_env), &block)
end

def fetch(name, default = UnixEnvironmentVariables::UNDEFINED)
Expand Down Expand Up @@ -67,6 +63,20 @@ def prepend(name, value)
def delete(name)
super(name.upcase)
end

def self.hash_from_env
upcase_env(ENV)
end

def self.upcase_env(env)
env.each_with_object({}) { |(k, v), a| a[k.to_s.upcase] = v }
end

private

def upcase_env(env)
self.class.upcase_env(env)
end
end
end
end
8 changes: 5 additions & 3 deletions lib/aruba/processes/basic_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class BasicProcess
attr_reader :exit_status, :environment, :working_directory, :main_class,
:io_wait_timeout, :exit_timeout, :startup_wait_time, :stop_signal

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)
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
environment = Aruba.platform.environment_variables.hash_from_env,
main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@working_directory = working_directory
@environment = environment
Expand Down Expand Up @@ -120,8 +122,6 @@ def inspect

alias to_s inspect

private

def command
Shellwords.split(commandline).first
end
Expand All @@ -132,6 +132,8 @@ def arguments
[]
end

private

def truncate(string, max_length)
return string if string.length <= max_length
string[0, max_length - 1] + ' ...'
Expand Down
4 changes: 3 additions & 1 deletion lib/aruba/processes/in_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def exit(exitstatus)
# @private
attr_reader :main_class

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)
def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
environment = Aruba.platform.environment_variables.hash_from_env,
main_class = nil, stop_signal = nil, startup_wait_time = 0)
@cmd = cmd
@argv = arguments
@stdin = StringIO.new
Expand Down
Loading