session 2.4.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.
- data/lib/session-2.4.0.rb +744 -0
- data/lib/session.rb +744 -0
- data/test/session.rb +227 -0
- metadata +41 -0
data/test/session.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
|
2
|
+
%w(lib ../lib . ..).each{|d| $:.unshift d}
|
3
|
+
require 'session'
|
4
|
+
|
5
|
+
$VERBOSE=nil
|
6
|
+
STDOUT.sync = true
|
7
|
+
STDERR.sync = true
|
8
|
+
STDOUT.puts "Session::VERSION <#{ Session::VERSION }>"
|
9
|
+
STDOUT.puts "Session.use_spawn <#{ Session.use_spawn ? 'true' : 'false' }>"
|
10
|
+
STDOUT.puts "Session.use_open3 <#{ Session.use_open3 ? 'true' : 'false' }>"
|
11
|
+
Session::debug = true
|
12
|
+
|
13
|
+
#
|
14
|
+
# a timeout method which does not stop all threads!
|
15
|
+
# for testing only!
|
16
|
+
#
|
17
|
+
class TimeoutError < StandardError; end
|
18
|
+
def timeout n
|
19
|
+
#{{{
|
20
|
+
ret = nil
|
21
|
+
cid = fork
|
22
|
+
unless cid
|
23
|
+
trap('SIGQUIT'){ exit! }
|
24
|
+
sleep n
|
25
|
+
begin; Process.kill 'SIGUSR1', Process.ppid; rescue Errno::Exception; end
|
26
|
+
exit!
|
27
|
+
else
|
28
|
+
begin
|
29
|
+
handler = trap('SIGUSR1'){throw :timeout, TimeoutError.new}
|
30
|
+
thrown = catch(:timeout){ ret = yield }
|
31
|
+
if TimeoutError === thrown
|
32
|
+
display
|
33
|
+
STDIN.gets
|
34
|
+
raise thrown
|
35
|
+
end
|
36
|
+
ensure
|
37
|
+
begin; Process.kill 'SIGQUIT', cid; rescue Exception; end
|
38
|
+
begin; Process.wait; rescue Exception => e; end
|
39
|
+
trap 'SIGUSR1', handler if defined? handler
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ret
|
43
|
+
#}}}
|
44
|
+
end
|
45
|
+
def display
|
46
|
+
#{{{
|
47
|
+
puts "$session_command < #{ $session_command.inspect }> "
|
48
|
+
puts "$session_iodat < #{ $session_iodat.inspect }> "
|
49
|
+
puts "$session_selecting < #{ $session_selecting.inspect }> "
|
50
|
+
# puts "$session_buffer < #{ $session_buffer.inspect }> "
|
51
|
+
# puts "$session_err < #{ $session_err.inspect }> "
|
52
|
+
# puts "$session_out < #{ $session_out.inspect }> "
|
53
|
+
# puts "$session_iodat_name < #{ $session_iodat_name.inspect }> "
|
54
|
+
# puts "$session_reading < #{ $session_reading.inspect }> "
|
55
|
+
# puts "$session_buf < #{ $session_buf.inspect }> "
|
56
|
+
# puts "$session_lines < #{ $session_lines.inspect }> "
|
57
|
+
# puts "$session_line < #{ $session_line.inspect }> "
|
58
|
+
# puts "$session_getting_status < #{ $session_getting_status.inspect }> "
|
59
|
+
self
|
60
|
+
#}}}
|
61
|
+
end
|
62
|
+
|
63
|
+
system "which idl > /dev/null 2>&1"
|
64
|
+
HAVE_IDL = ($?.exitstatus == 0 ? true : false)
|
65
|
+
|
66
|
+
require "test/unit"
|
67
|
+
module Session
|
68
|
+
class Test < Test::Unit::TestCase
|
69
|
+
def test_0
|
70
|
+
#{{{
|
71
|
+
sh = nil
|
72
|
+
assert_nothing_raised { sh = Shell.new }
|
73
|
+
#}}}
|
74
|
+
end
|
75
|
+
def test_1
|
76
|
+
#{{{
|
77
|
+
assert_nothing_raised {
|
78
|
+
timeout(16) {
|
79
|
+
sh = nil
|
80
|
+
assert_nothing_raised { sh = Shell.new }
|
81
|
+
sh.execute 'ls'
|
82
|
+
}
|
83
|
+
}
|
84
|
+
#}}}
|
85
|
+
end
|
86
|
+
def test_3
|
87
|
+
#{{{
|
88
|
+
assert_nothing_raised {
|
89
|
+
timeout(64) {
|
90
|
+
sh = nil
|
91
|
+
assert_nothing_raised { sh = Shell.new }
|
92
|
+
128.times { sh.execute 'echo 42' }
|
93
|
+
}
|
94
|
+
}
|
95
|
+
#}}}
|
96
|
+
end
|
97
|
+
def test_4
|
98
|
+
#{{{
|
99
|
+
cmds = ['ls', 'echo 42', 'printf "foobar"', 'printf "foobar\n"']
|
100
|
+
assert_nothing_raised {
|
101
|
+
timeout(64) {
|
102
|
+
sh = nil
|
103
|
+
assert_nothing_raised { sh = Shell.new }
|
104
|
+
128.times { cmds.each{|cmd| sh.execute cmd;sh.execute "#{cmd} 1>&2"} }
|
105
|
+
}
|
106
|
+
}
|
107
|
+
#}}}
|
108
|
+
end
|
109
|
+
def test_5
|
110
|
+
#{{{
|
111
|
+
assert_nothing_raised {
|
112
|
+
timeout(16) {
|
113
|
+
sh = nil
|
114
|
+
assert_nothing_raised { sh = Shell.new }
|
115
|
+
out, err = sh.execute 'echo 42'
|
116
|
+
assert_equal '42', out.strip
|
117
|
+
out, err = sh.execute 'echo "forty-two" 1>&2'
|
118
|
+
assert_equal 'forty-two', err.strip
|
119
|
+
}
|
120
|
+
}
|
121
|
+
#}}}
|
122
|
+
end
|
123
|
+
def test_6
|
124
|
+
#{{{
|
125
|
+
out = ''
|
126
|
+
err = ''
|
127
|
+
assert_nothing_raised {
|
128
|
+
timeout(16) {
|
129
|
+
sh = nil
|
130
|
+
assert_nothing_raised { sh = Shell.new }
|
131
|
+
sh.execute 'echo 42', :stdout => out, :stderr => err
|
132
|
+
assert_equal '42', out.strip
|
133
|
+
sh.execute 'echo "forty-two" 1>&2', :stdout => out, :stderr => err
|
134
|
+
assert_equal 'forty-two', err.strip
|
135
|
+
}
|
136
|
+
}
|
137
|
+
#}}}
|
138
|
+
end
|
139
|
+
def test_7
|
140
|
+
#{{{
|
141
|
+
#$DEBUG = true
|
142
|
+
assert_nothing_raised {
|
143
|
+
timeout(16) {
|
144
|
+
sh = nil
|
145
|
+
assert_nothing_raised { sh = Shell.new }
|
146
|
+
sh.execute('echo 42') do |out, err|
|
147
|
+
if out
|
148
|
+
assert_equal '42', out.strip
|
149
|
+
end
|
150
|
+
end
|
151
|
+
sh.execute('echo "forty-two" 1>&2') do |out, err|
|
152
|
+
if err
|
153
|
+
assert_equal 'forty-two', err.strip
|
154
|
+
end
|
155
|
+
end
|
156
|
+
}
|
157
|
+
}
|
158
|
+
#ensure
|
159
|
+
#$DEBUG = true
|
160
|
+
#}}}
|
161
|
+
end
|
162
|
+
if HAVE_IDL
|
163
|
+
def test_8
|
164
|
+
#{{{
|
165
|
+
assert_nothing_raised {
|
166
|
+
timeout(16) {
|
167
|
+
idl = nil
|
168
|
+
assert_nothing_raised { idl = IDL.new }
|
169
|
+
|
170
|
+
out = ''; err = ''
|
171
|
+
idl.execute 'printf, -1, 42', :stdout => out, :stderr => err
|
172
|
+
assert_equal '42', out.strip
|
173
|
+
|
174
|
+
out = ''; err = ''
|
175
|
+
idl.execute 'printf, -2, \'forty-two\'', :stdout => out, :stderr => err
|
176
|
+
assert_equal 'forty-two', err.strip
|
177
|
+
|
178
|
+
out = ''; err = ''
|
179
|
+
idl.execute 'foo', :stdout => out, :stderr => err
|
180
|
+
assert_match %r/undefined procedure/io, err
|
181
|
+
}
|
182
|
+
}
|
183
|
+
#}}}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
def test_9
|
187
|
+
#{{{
|
188
|
+
assert_nothing_raised {
|
189
|
+
timeout(16) {
|
190
|
+
lines = []
|
191
|
+
Thread.new {
|
192
|
+
sh = nil
|
193
|
+
assert_nothing_raised { sh = Shell.new }
|
194
|
+
sh.debug = true
|
195
|
+
#cmd = 'date; sleep 1;' * 3
|
196
|
+
cmd = 'ruby -e "puts 42; sleep 0.1"' * 3
|
197
|
+
sh.execute(cmd) do |o,e|
|
198
|
+
line = o || e
|
199
|
+
lines << [Time.now.to_f, line]
|
200
|
+
end
|
201
|
+
}.join
|
202
|
+
|
203
|
+
i = 0
|
204
|
+
while((a = lines[i]) and (b = lines[i + 1]))
|
205
|
+
ta = a.first
|
206
|
+
tb = b.first
|
207
|
+
# they all come back at once if thread hung sending cmd...
|
208
|
+
# make sure we got output about a second apart...
|
209
|
+
begin
|
210
|
+
assert( (tb - ta) >= 0.1 )
|
211
|
+
rescue Exception
|
212
|
+
STDERR.puts "lines : <#{ lines.inspect}>"
|
213
|
+
STDERR.puts "i : <#{ i }>"
|
214
|
+
STDERR.puts "b : <#{ b.inspect }>"
|
215
|
+
STDERR.puts "a : <#{ a.inspect }>"
|
216
|
+
STDERR.puts "tb : <#{ tb }>"
|
217
|
+
STDERR.puts "ta : <#{ ta }>"
|
218
|
+
raise
|
219
|
+
end
|
220
|
+
i += 1
|
221
|
+
end
|
222
|
+
}
|
223
|
+
}
|
224
|
+
#}}}
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
metadata
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: session
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 2.4.0
|
7
|
+
date: 2005-11-13 00:00:00.000000 -07:00
|
8
|
+
summary: session
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ara.t.howard@noaa.gov
|
12
|
+
homepage: http://codeforpeople.com/lib/ruby/session/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: session
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- Ara T. Howard
|
31
|
+
files:
|
32
|
+
- lib/session.rb
|
33
|
+
- lib/session-2.4.0.rb
|
34
|
+
test_files:
|
35
|
+
- test/session.rb
|
36
|
+
rdoc_options: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
requirements: []
|
41
|
+
dependencies: []
|