blue-shell 0.2.0 → 0.2.1
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.
- data/lib/blue-shell/buffered_reader_expector.rb +2 -8
- data/lib/blue-shell/matchers.rb +3 -0
- data/lib/blue-shell/runner.rb +4 -0
- data/lib/blue-shell/version.rb +1 -1
- data/spec/assets/unbuffered_input.rb +49 -0
- data/spec/buffered_reader_expector_spec.rb +0 -43
- data/spec/matchers_spec.rb +5 -0
- data/spec/runner_spec.rb +12 -2
- data/spec/spec_helper.rb +1 -3
- data/spec/support/escaped_keys.rb +3 -0
- metadata +7 -19
@@ -50,8 +50,7 @@ module BlueShell
|
|
50
50
|
|
51
51
|
STDOUT.putc c if @debug
|
52
52
|
|
53
|
-
#
|
54
|
-
# until m is read
|
53
|
+
# wear your flip flops
|
55
54
|
unless (c == "\e") .. (c == "m")
|
56
55
|
if c == "\b"
|
57
56
|
if position > 0 && buffer[position - 1] && buffer[position - 1].chr != "\n"
|
@@ -78,12 +77,7 @@ module BlueShell
|
|
78
77
|
end
|
79
78
|
|
80
79
|
def output_ended?(timeout)
|
81
|
-
[
|
82
|
-
if(@out.is_a?(IO) && IO.select([@out], nil, nil, 1))
|
83
|
-
return @out.eof?
|
84
|
-
end
|
85
|
-
end
|
86
|
-
true
|
80
|
+
(@out.is_a?(IO) && !IO.select([@out], nil, nil, timeout)) || @out.eof?
|
87
81
|
end
|
88
82
|
end
|
89
83
|
end
|
data/lib/blue-shell/matchers.rb
CHANGED
@@ -4,10 +4,13 @@ module BlueShell
|
|
4
4
|
OutputMatcher.new(expected_output, timeout)
|
5
5
|
end
|
6
6
|
|
7
|
+
alias :have_output :say
|
8
|
+
|
7
9
|
def have_exited_with(expected_code)
|
8
10
|
ExitCodeMatcher.new(expected_code)
|
9
11
|
end
|
10
12
|
|
13
|
+
alias :have_exit_code :have_exited_with
|
11
14
|
alias :exit_with :have_exited_with
|
12
15
|
end
|
13
16
|
end
|
data/lib/blue-shell/runner.rb
CHANGED
data/lib/blue-shell/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'io/wait'
|
4
|
+
require_relative '../../spec/support/escaped_keys'
|
5
|
+
|
6
|
+
class UnbufferedInput
|
7
|
+
$stdout.sync = true
|
8
|
+
|
9
|
+
def initialize(exit_on_character)
|
10
|
+
@exit_on_character = exit_on_character
|
11
|
+
puts "started"
|
12
|
+
result = read_input
|
13
|
+
puts %Q{received: #{result.inspect}} if result
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
alias_method :run, :new
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def read_input
|
22
|
+
begin
|
23
|
+
system("stty raw -echo -icanon isig <&2")
|
24
|
+
|
25
|
+
line = ""
|
26
|
+
input_character = ""
|
27
|
+
|
28
|
+
escaped = false
|
29
|
+
exit_on = ""
|
30
|
+
while exit_on != @exit_on_character
|
31
|
+
input_character = $stdin.getc
|
32
|
+
|
33
|
+
exit_on << input_character if escaped
|
34
|
+
|
35
|
+
if input_character == "\e"
|
36
|
+
escaped = true
|
37
|
+
end
|
38
|
+
|
39
|
+
line << input_character
|
40
|
+
end
|
41
|
+
line
|
42
|
+
ensure
|
43
|
+
system "stty -raw echo" # turn raw input off
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
exit_on_character = ARGF.argv[0]
|
49
|
+
UnbufferedInput.run(exit_on_character)
|
@@ -21,47 +21,4 @@ describe BlueShell::BufferedReaderExpector do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
describe "output_ended?" do
|
26
|
-
it "does not wait the full timeout if the command has already exited" do
|
27
|
-
begin_time = Time.now
|
28
|
-
Thread.new() do
|
29
|
-
sleep(2)
|
30
|
-
write.close
|
31
|
-
end
|
32
|
-
subject.send(:output_ended?, 10).should be_true
|
33
|
-
duration = Time.now - begin_time
|
34
|
-
|
35
|
-
duration.should <= 5
|
36
|
-
end
|
37
|
-
|
38
|
-
it "handles non-integer timeouts" do
|
39
|
-
expect { subject.send(:output_ended?, 0.1) }.to_not raise_error
|
40
|
-
end
|
41
|
-
|
42
|
-
it "waits the full timeout when no output is arriving" do
|
43
|
-
begin_time = Time.now
|
44
|
-
Thread.new() do
|
45
|
-
sleep(3)
|
46
|
-
write.puts("not done")
|
47
|
-
end
|
48
|
-
subject.send(:output_ended?, 2).should be_true
|
49
|
-
duration = Time.now - begin_time
|
50
|
-
|
51
|
-
duration.should < 3
|
52
|
-
duration.should >= 1.9
|
53
|
-
end
|
54
|
-
|
55
|
-
it "returns false if the output is readable" do
|
56
|
-
begin_time = Time.now
|
57
|
-
Thread.new() do
|
58
|
-
sleep(1)
|
59
|
-
write.puts("not done")
|
60
|
-
end
|
61
|
-
subject.send(:output_ended?, 4).should be_false
|
62
|
-
duration = Time.now - begin_time
|
63
|
-
|
64
|
-
duration.should <= 2
|
65
|
-
end
|
66
|
-
end
|
67
24
|
end
|
data/spec/matchers_spec.rb
CHANGED
@@ -9,6 +9,10 @@ module BlueShell
|
|
9
9
|
say("").should be_a(Matchers::OutputMatcher)
|
10
10
|
end
|
11
11
|
|
12
|
+
it "has synonyms" do
|
13
|
+
have_output("").should be_a(Matchers::OutputMatcher)
|
14
|
+
end
|
15
|
+
|
12
16
|
context "with an explicit timeout" do
|
13
17
|
it "returns an ExpectOutputMatcher" do
|
14
18
|
matcher = say("", 30)
|
@@ -25,6 +29,7 @@ module BlueShell
|
|
25
29
|
|
26
30
|
it "has synonyms" do
|
27
31
|
exit_with(1).should be_a(Matchers::ExitCodeMatcher)
|
32
|
+
have_exit_code(1).should be_a(Matchers::ExitCodeMatcher)
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -119,7 +119,7 @@ module BlueShell
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it "calls the matched callback" do
|
122
|
-
callback =
|
122
|
+
callback = double(:callback)
|
123
123
|
BlueShell::Runner.run("echo 1 3") do |runner|
|
124
124
|
branches = {
|
125
125
|
"1" => proc { callback }
|
@@ -161,7 +161,7 @@ module BlueShell
|
|
161
161
|
end
|
162
162
|
|
163
163
|
describe "#send_return" do
|
164
|
-
it "sends a return and expects more output
|
164
|
+
it "sends a return and expects more output af`terwards" do
|
165
165
|
BlueShell::Runner.run("ruby #{asset("input.rb")}") do |runner|
|
166
166
|
expect(runner.expect("started")).to be_true
|
167
167
|
runner.send_return
|
@@ -170,6 +170,16 @@ module BlueShell
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
describe "#send_up_arrow" do
|
174
|
+
it "sends an up arrow key press and expects more output afterwards" do
|
175
|
+
BlueShell::Runner.run("ruby #{asset("unbuffered_input.rb")} #{EscapedKeys::KEY_UP}") do |runner|
|
176
|
+
expect(runner.expect("started")).to be_true
|
177
|
+
runner.send_up_arrow
|
178
|
+
expect(runner.expect('received: "\e[A"')).to be_true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
173
183
|
context "#exit_code" do
|
174
184
|
it "returns the exit code" do
|
175
185
|
BlueShell::Runner.run("ruby -e 'exit 42'") do |runner|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'blue-shell'
|
2
|
-
require 'rr'
|
3
2
|
|
4
3
|
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
|
5
4
|
require file
|
6
5
|
end
|
7
6
|
|
8
7
|
RSpec.configure do |config|
|
9
|
-
config.mock_with :rr
|
10
|
-
|
11
8
|
config.include BlueShell::Helpers
|
9
|
+
config.include EscapedKeys
|
12
10
|
end
|
13
11
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blue-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -44,22 +44,6 @@ dependencies:
|
|
44
44
|
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rr
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ! '>='
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
47
|
description:
|
64
48
|
email:
|
65
49
|
- cfpi-frontend@googlegroups.com
|
@@ -79,12 +63,14 @@ files:
|
|
79
63
|
- lib/blue-shell.rb
|
80
64
|
- spec/assets/input.rb
|
81
65
|
- spec/assets/pause.rb
|
66
|
+
- spec/assets/unbuffered_input.rb
|
82
67
|
- spec/buffered_reader_expector_spec.rb
|
83
68
|
- spec/matchers/exit_code_matcher_spec.rb
|
84
69
|
- spec/matchers/output_matcher_spec.rb
|
85
70
|
- spec/matchers_spec.rb
|
86
71
|
- spec/runner_spec.rb
|
87
72
|
- spec/spec_helper.rb
|
73
|
+
- spec/support/escaped_keys.rb
|
88
74
|
- spec/support/helpers.rb
|
89
75
|
homepage: http://github.com/pivotal/blue-shell
|
90
76
|
licenses:
|
@@ -107,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
93
|
version: '0'
|
108
94
|
requirements: []
|
109
95
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.8.
|
96
|
+
rubygems_version: 1.8.25
|
111
97
|
signing_key:
|
112
98
|
specification_version: 3
|
113
99
|
summary: Friendly command-line test runner and matchers for shell scripting in ruby
|
@@ -115,10 +101,12 @@ summary: Friendly command-line test runner and matchers for shell scripting in r
|
|
115
101
|
test_files:
|
116
102
|
- spec/assets/input.rb
|
117
103
|
- spec/assets/pause.rb
|
104
|
+
- spec/assets/unbuffered_input.rb
|
118
105
|
- spec/buffered_reader_expector_spec.rb
|
119
106
|
- spec/matchers/exit_code_matcher_spec.rb
|
120
107
|
- spec/matchers/output_matcher_spec.rb
|
121
108
|
- spec/matchers_spec.rb
|
122
109
|
- spec/runner_spec.rb
|
123
110
|
- spec/spec_helper.rb
|
111
|
+
- spec/support/escaped_keys.rb
|
124
112
|
- spec/support/helpers.rb
|