[DRE-commits] [ruby-aruba] 61/98: Implement the shell feature and introduce first generators
Hideki Yamane
henrich at moszumanska.debian.org
Tue Mar 22 12:20:40 UTC 2016
This is an automated email from the git hooks/post-receive script.
henrich pushed a commit to branch debian/sid
in repository ruby-aruba.
commit fb439d1793ec51f3049f59f5c8831abcd003d18e
Author: AdrieanKhisbe <adriean.khisbe at live.fr>
Date: Mon Jan 4 22:52:19 2016 +0100
Implement the shell feature and introduce first generators
---
.travis.yml | 10 +++++++--
features/steps/command/shell.feature | 4 ++--
lib/aruba/cucumber/command.rb | 12 +++++++++++
lib/aruba/generators/script_file.rb | 41 ++++++++++++++++++++++++++++++++++++
lib/aruba/platforms/unix_platform.rb | 4 ++++
5 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 39846d2..f0b4b05 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -39,5 +39,11 @@ notifications:
env:
global:
- secure: l8uznA5K4K9mZ1krmP3lTMD8WcJ32qGxFOR3jubKHcOBSLB4xSzU2aIqjyJdO+rLzebkwamhJc8pGSIWOUDQYvFiX7splK+uEkbBJ5huAhXtLF4Qgl86bCWbEXYzN7rvn0DQfpJAovyFMNRMnfo70XhwqWzFsaYa7Z0YbqYsJE4=
- # - JRUBY_OPTS='-Xcli.debug=true --debug'
- - JRUBY_OPTS='--dev'
+ - JRUBY_OPTS='-Xcli.debug=true --debug'
+cache: apt
+addons:
+ apt:
+ packages:
+ - dash
+ - fish
+ - zsh
diff --git a/features/steps/command/shell.feature b/features/steps/command/shell.feature
index 7c32e27..d9c8589 100644
--- a/features/steps/command/shell.feature
+++ b/features/steps/command/shell.feature
@@ -62,7 +62,7 @@ Feature: Running shell commands
Scenario: Running bash commands
When I run the following commands with `bash`:
\"\"\"bash
- echo "Hello \c"
+ echo -n "Hello "
echo `echo bash` # subshell
\"\"\"
Then the output should contain exactly "Hello bash"
@@ -98,7 +98,7 @@ Feature: Running shell commands
"""
Feature: Running fish scripts
Scenario: Running fish commands
- When I run the following commands with `fish`:
+ When I run the following commands in `fish`:
\"\"\"bash
echo -n "Hello "
echo (echo fish)
diff --git a/lib/aruba/cucumber/command.rb b/lib/aruba/cucumber/command.rb
index a31e18c..8897649 100644
--- a/lib/aruba/cucumber/command.rb
+++ b/lib/aruba/cucumber/command.rb
@@ -1,6 +1,7 @@
if Aruba::VERSION < '1.0.0'
require 'aruba/cucumber/core'
end
+require 'aruba/generators/script_file'
When(/^I run "(.*)"$/)do |cmd|
warn(%{\e[35m The /^I run "(.*)"$/ step definition is deprecated. Please use the `backticks` version\e[0m})
@@ -28,6 +29,17 @@ When(/^I successfully run `(.*?)`(?: for up to (\d+) seconds)?$/)do |cmd, secs|
run_simple(cmd, :fail_on_error => true, :exit_timeout => secs && secs.to_i)
end
+When(/^I run the following (?:commands|script)(?: (?:with|in) `([^`]+)`)?:$/) do |shell, commands|
+ prepend_environment_variable('PATH', expand_path('bin') + ':')
+
+ Aruba.platform.mkdir(expand_path('bin'))
+ shell ||= Aruba.platform.default_shell
+
+ Aruba::ScriptFile.new(:interpreter => shell, :content => commands,
+ :path => expand_path('bin/myscript')).call
+ step 'I run `myscript`'
+end
+
When(/^I run "([^"]*)" interactively$/) do |cmd|
Aruba.platform.deprecated(%{\e[35m The /^I run "([^"]*)" interactively$/ step definition is deprecated. Please use the `backticks` version\e[0m})
diff --git a/lib/aruba/generators/script_file.rb b/lib/aruba/generators/script_file.rb
new file mode 100644
index 0000000..e55fd7c
--- /dev/null
+++ b/lib/aruba/generators/script_file.rb
@@ -0,0 +1,41 @@
+# Aruba
+module Aruba
+ # ScriptFile
+ class ScriptFile
+ def initialize(opts = {})
+ @path = opts[:path]
+ @content = opts[:content]
+ @interpreter = opts[:interpreter]
+ end
+
+ def call
+ Aruba.platform.write_file(@path, "#{header}#{@content}")
+ Aruba.platform.chmod(0755, @path, {})
+ end
+
+ private
+
+ def header
+ if script_starts_with_shebang?
+ ''
+ elsif interpreter_is_absolute_path?
+ format("#!%s\n", @interpreter)
+ elsif interpreter_is_just_the_name_of_shell?
+ format("#!/usr/bin/env %s\n", @interpreter)
+ end
+ end
+
+ def interpreter_is_absolute_path?
+ Aruba.platform.absolute_path? @interpreter
+ end
+
+ def interpreter_is_just_the_name_of_shell?
+ @interpreter =~ /^[-_a-zA-Z.]+$/
+ end
+
+ def script_starts_with_shebang?
+ @content.start_with? '#!'
+ end
+
+ end
+end
diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb
index 8b6b12a..a656130 100644
--- a/lib/aruba/platforms/unix_platform.rb
+++ b/lib/aruba/platforms/unix_platform.rb
@@ -78,6 +78,10 @@ module Aruba
LocalEnvironment.new.call(env, &block)
end
+ def default_shell
+ 'bash'
+ end
+
def detect_ruby(cmd)
if cmd =~ /^ruby\s/
cmd.gsub(/^ruby\s/, "#{current_ruby} ")
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-aruba.git
More information about the Pkg-ruby-extras-commits
mailing list