blue-shell 0.1.0 → 0.2.0
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.
@@ -50,7 +50,8 @@ module BlueShell
|
|
50
50
|
|
51
51
|
STDOUT.putc c if @debug
|
52
52
|
|
53
|
-
#
|
53
|
+
# evaluate true when \e is read and continue to
|
54
|
+
# until m is read
|
54
55
|
unless (c == "\e") .. (c == "m")
|
55
56
|
if c == "\b"
|
56
57
|
if position > 0 && buffer[position - 1] && buffer[position - 1].chr != "\n"
|
@@ -77,10 +78,12 @@ module BlueShell
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def output_ended?(timeout)
|
80
|
-
timeout.to_i.times do
|
81
|
-
|
81
|
+
[timeout.to_i, 1].max.times do
|
82
|
+
if(@out.is_a?(IO) && IO.select([@out], nil, nil, 1))
|
83
|
+
return @out.eof?
|
84
|
+
end
|
82
85
|
end
|
83
|
-
|
86
|
+
true
|
84
87
|
end
|
85
88
|
end
|
86
89
|
end
|
data/lib/blue-shell/errors.rb
CHANGED
data/lib/blue-shell/runner.rb
CHANGED
data/lib/blue-shell/version.rb
CHANGED
@@ -23,20 +23,45 @@ describe BlueShell::BufferedReaderExpector do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "output_ended?" do
|
26
|
-
it "
|
26
|
+
it "does not wait the full timeout if the command has already exited" do
|
27
27
|
begin_time = Time.now
|
28
28
|
Thread.new() do
|
29
29
|
sleep(2)
|
30
|
-
write.
|
30
|
+
write.close
|
31
31
|
end
|
32
|
-
subject.send(:output_ended?, 10)
|
32
|
+
subject.send(:output_ended?, 10).should be_true
|
33
33
|
duration = Time.now - begin_time
|
34
34
|
|
35
35
|
duration.should <= 5
|
36
36
|
end
|
37
37
|
|
38
|
-
it "
|
38
|
+
it "handles non-integer timeouts" do
|
39
39
|
expect { subject.send(:output_ended?, 0.1) }.to_not raise_error
|
40
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
|
41
66
|
end
|
42
67
|
end
|
data/spec/runner_spec.rb
CHANGED
@@ -8,25 +8,15 @@ module BlueShell
|
|
8
8
|
describe "running a command" do
|
9
9
|
let(:file) do
|
10
10
|
file = Tempfile.new('blue-shell-runner')
|
11
|
-
sleep 1
|
11
|
+
sleep 1 # wait one second to make sure touching the file does something measurable
|
12
12
|
file
|
13
13
|
end
|
14
14
|
|
15
15
|
after { file.unlink }
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
BlueShell::Runner.run("false")
|
21
|
-
}.to raise_error(Errors::NonZeroExitCodeError) { |error| error.exit_code.should == 1 }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with a valid command" do
|
26
|
-
it "runs a command" do
|
27
|
-
BlueShell::Runner.run("touch -a #{file.path}")
|
28
|
-
file.stat.atime.should > file.stat.mtime
|
29
|
-
end
|
17
|
+
it "runs a command" do
|
18
|
+
BlueShell::Runner.run("touch -a #{file.path}")
|
19
|
+
file.stat.atime.should > file.stat.mtime
|
30
20
|
end
|
31
21
|
end
|
32
22
|
|
@@ -38,6 +28,10 @@ module BlueShell
|
|
38
28
|
}
|
39
29
|
runner.should_not be_success
|
40
30
|
runner.should_not be_successful
|
31
|
+
|
32
|
+
runner = BlueShell::Runner.run("false")
|
33
|
+
runner.should_not be_success
|
34
|
+
runner.should_not be_successful
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|