cexpect 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +43 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +22 -1
- data/README.md +7 -0
- data/Rakefile +7 -3
- data/cexpect.gemspec +21 -16
- data/lib/cexpect.rb +24 -13
- data/lib/cexpect/version.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c069d8b016446307cbdc97331682a9aac2a0bdb0a70fefb40c5fdd946f71cef
|
4
|
+
data.tar.gz: 8f0b4dabc8fd1d75b223c3a55822ab26400b3e6fa96ef0178f4b18f4e6fc1e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a73e2690ed2625d7be89045cf65ed3601301fb3f8afd581464231daba94cfed43cc51d2185159ea5d2df64585db9f24580e307f7af8b721be7aa42c2dfb1e3c
|
7
|
+
data.tar.gz: e2713329c4fb95c1e78d4107dfebd052548b7db5a6211fbdabdb38b51ef374afa934479a742d903ce886575d86e7ce710ce48006b9b71fd18358c60e11b37f88
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- 'bin/{console,setup}' # not mine
|
6
|
+
- 'Gemfile' # maintained through "bundle" command
|
7
|
+
|
8
|
+
# TODO: Clean up tests
|
9
|
+
RSpec/ExpectInHook:
|
10
|
+
Enabled: false
|
11
|
+
RSpec/FilePath:
|
12
|
+
Exclude:
|
13
|
+
- spec/cexpect_spec.rb
|
14
|
+
RSpec/MessageSpies:
|
15
|
+
Enabled: false
|
16
|
+
RSpec/NestedGroups:
|
17
|
+
Enabled: false
|
18
|
+
RSpec/VerifiedDoubles:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# Personal preferences
|
22
|
+
Layout/DotPosition:
|
23
|
+
EnforcedStyle: trailing
|
24
|
+
Style/PercentLiteralDelimiters:
|
25
|
+
PreferredDelimiters:
|
26
|
+
'%i': '()'
|
27
|
+
|
28
|
+
# New stuff in rubocop, not yet enabled/disabled by default
|
29
|
+
Layout/SpaceAroundMethodCallOperator:
|
30
|
+
Enabled: true
|
31
|
+
Lint/RaiseException:
|
32
|
+
Enabled: true
|
33
|
+
Lint/StructNewOverride:
|
34
|
+
Enabled: true
|
35
|
+
Style/HashEachMethods:
|
36
|
+
Enabled: true
|
37
|
+
Style/HashTransformKeys:
|
38
|
+
Enabled: true
|
39
|
+
Style/HashTransformValues:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Style/ExponentialNotation:
|
43
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cexpect (0.1.
|
4
|
+
cexpect (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
ast (2.4.0)
|
9
10
|
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.4)
|
12
|
+
parallel (1.19.1)
|
13
|
+
parser (2.7.1.1)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
10
16
|
rake (12.3.3)
|
17
|
+
rexml (3.2.4)
|
11
18
|
rspec (3.9.0)
|
12
19
|
rspec-core (~> 3.9.0)
|
13
20
|
rspec-expectations (~> 3.9.0)
|
@@ -21,6 +28,18 @@ GEM
|
|
21
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
29
|
rspec-support (~> 3.9.0)
|
23
30
|
rspec-support (3.9.2)
|
31
|
+
rubocop (0.82.0)
|
32
|
+
jaro_winkler (~> 1.5.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.7.0.1)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
rexml
|
37
|
+
ruby-progressbar (~> 1.7)
|
38
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
39
|
+
rubocop-rspec (1.38.1)
|
40
|
+
rubocop (>= 0.68.1)
|
41
|
+
ruby-progressbar (1.10.1)
|
42
|
+
unicode-display_width (1.7.0)
|
24
43
|
|
25
44
|
PLATFORMS
|
26
45
|
ruby
|
@@ -29,6 +48,8 @@ DEPENDENCIES
|
|
29
48
|
cexpect!
|
30
49
|
rake (~> 12.0)
|
31
50
|
rspec (~> 3.0)
|
51
|
+
rubocop (~> 0.82.0)
|
52
|
+
rubocop-rspec (~> 1.38)
|
32
53
|
|
33
54
|
BUNDLED WITH
|
34
55
|
2.1.4
|
data/README.md
CHANGED
@@ -62,6 +62,13 @@ end
|
|
62
62
|
|
63
63
|
wr.puts('cat very-large-file')
|
64
64
|
contents = rd.fexpect('$ ')
|
65
|
+
|
66
|
+
# If CExpect.spawn doesn't suit you
|
67
|
+
orig_rd, wr = IO.pipe
|
68
|
+
rd = CExpect::Reader.new(orig_rd)
|
69
|
+
|
70
|
+
wr.puts "Hello, World!\n"
|
71
|
+
greeting = rd.fexpect("\n")
|
65
72
|
```
|
66
73
|
|
67
74
|
## Development
|
data/Rakefile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
RuboCop::RakeTask.new
|
5
9
|
|
6
|
-
task :
|
10
|
+
task default: %i(spec rubocop)
|
data/cexpect.gemspec
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/cexpect/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'cexpect'
|
5
7
|
spec.version = Cexpect::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['Christer Jansson']
|
9
|
+
spec.email = ['christer@janssons.org']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
|
12
|
-
spec.
|
13
|
-
spec.
|
11
|
+
spec.summary = 'An improved expect method'
|
12
|
+
spec.description = 'An expect method with more reasonable return' \
|
13
|
+
' values and logging functionality'
|
14
|
+
spec.homepage = 'https://github.com/kondensatorn/cexpect'
|
15
|
+
spec.license = 'BSD 2-clause'
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
14
17
|
|
15
|
-
spec.metadata[
|
16
|
-
spec.metadata[
|
17
|
-
spec.metadata[
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
|
18
21
|
|
19
22
|
# Specify which files should be added to the gem when it is released.
|
20
|
-
# The `git ls-files -z` loads the files in the RubyGem that have
|
21
|
-
|
22
|
-
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have
|
24
|
+
# been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.
|
27
|
+
split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
28
|
end
|
24
|
-
spec.bindir =
|
29
|
+
spec.bindir = 'exe'
|
25
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
-
spec.require_paths = [
|
31
|
+
spec.require_paths = ['lib']
|
27
32
|
end
|
data/lib/cexpect.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'delegate'
|
2
4
|
require 'observer'
|
3
5
|
require 'pty'
|
4
6
|
|
7
|
+
#
|
8
|
+
# A module for supplying a different expect method
|
9
|
+
#
|
5
10
|
module CExpect
|
6
11
|
def self.spawn(*args)
|
7
12
|
original_rd, wr, pid = PTY.spawn(*args)
|
@@ -13,6 +18,10 @@ module CExpect
|
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
21
|
+
#
|
22
|
+
# A class delegating normal operations to a wrapped IO, adding an
|
23
|
+
# expect method
|
24
|
+
#
|
16
25
|
class Reader < SimpleDelegator
|
17
26
|
include Observable
|
18
27
|
|
@@ -21,11 +30,11 @@ module CExpect
|
|
21
30
|
super
|
22
31
|
end
|
23
32
|
|
24
|
-
def expect(pat, timeout = nil, match_method: :
|
33
|
+
def expect(pat, timeout = nil, match_method: :re_match)
|
25
34
|
buf = +''
|
26
35
|
|
27
36
|
result = catch(:result) do
|
28
|
-
loop {
|
37
|
+
loop { expect_try(pat, buf, timeout, match_method) }
|
29
38
|
end
|
30
39
|
|
31
40
|
if block_given?
|
@@ -36,13 +45,13 @@ module CExpect
|
|
36
45
|
end
|
37
46
|
|
38
47
|
def fexpect(pat, timeout = nil)
|
39
|
-
expect(pat, timeout, match_method: :
|
48
|
+
expect(pat, timeout, match_method: :string_match)
|
40
49
|
end
|
41
50
|
|
42
51
|
private
|
43
52
|
|
44
|
-
def
|
45
|
-
c =
|
53
|
+
def expect_try(pat, buf, timeout, match_method)
|
54
|
+
c = getc(timeout)
|
46
55
|
|
47
56
|
if c.nil?
|
48
57
|
@leftovers = buf
|
@@ -51,32 +60,34 @@ module CExpect
|
|
51
60
|
|
52
61
|
buf << c
|
53
62
|
|
54
|
-
|
63
|
+
log(pat, buf)
|
55
64
|
|
56
65
|
result = send(match_method, buf, pat)
|
57
66
|
throw(:result, result) if result
|
58
67
|
end
|
59
68
|
|
60
|
-
def
|
69
|
+
def getc(timeout)
|
61
70
|
return @leftovers.slice!(0).chr unless @leftovers.empty?
|
62
71
|
|
63
|
-
|
72
|
+
rd = __getobj__
|
73
|
+
|
74
|
+
return nil if !IO.select([rd], nil, nil, timeout) || eof?
|
64
75
|
|
65
|
-
getc.chr
|
76
|
+
rd.getc.chr
|
66
77
|
end
|
67
78
|
|
68
|
-
def
|
79
|
+
def log(pat, buf)
|
69
80
|
return if count_observers.zero?
|
70
81
|
|
71
82
|
changed
|
72
|
-
notify_observers(
|
83
|
+
notify_observers(pat, buf)
|
73
84
|
end
|
74
85
|
|
75
|
-
def
|
86
|
+
def re_match(buf, pat)
|
76
87
|
buf.match(pat)
|
77
88
|
end
|
78
89
|
|
79
|
-
def
|
90
|
+
def string_match(buf, pat)
|
80
91
|
buf[0, buf.size - pat.size] if buf.end_with?(pat)
|
81
92
|
end
|
82
93
|
end
|
data/lib/cexpect/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cexpect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christer Jansson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An expect method with more reasonable return values and logging functionality
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
21
|
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
22
23
|
- ".travis.yml"
|
23
24
|
- CHANGELOG.md
|
24
25
|
- Gemfile
|