cexpect 0.1.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd6bc730347682ee7cb83f6397e57cdbd97441469bcdd23a45762ead541fa65b
4
- data.tar.gz: ddb67b29b21e989a3f885a25464166c9f641bd72c7bc8546cfe7bf695fdcd7b9
3
+ metadata.gz: beaafefd8da9cc27f26ca3ec0e6aa72c5d74e7c693d1fbd47fec019975636511
4
+ data.tar.gz: 468e494c7a35350c51f629ba486888f107c69f009bbec7be43a388c8d94992a1
5
5
  SHA512:
6
- metadata.gz: 5eac45f42370b2bd9bd373f064330b45d7ad325d0c2cdd278b1901969bd30e0aef3f906ac4602a152736868c13cf2af6b204c3e8a787439c1863f4be40acc9b5
7
- data.tar.gz: d1c3f35a437e74295bbfe7aecd2334439e849ea2cbabec7f78d0a31a2d28760f04ca80f859448b6a2cc82e5a2ad35ce3719e77f994e256a03d5875ef133dbad0
6
+ metadata.gz: 81abfc895b814481b8cb1c261696f597f93833212eed8120f53ace4d16f7ed521f6533db05f23fad9c482a9494751a6b3b80984954898c515582d3618e0137be
7
+ data.tar.gz: 939d84e0607b7bb23546cbdd9c8898b2fe9f6710613417e960128ef198cf173043acae2c150943c3dffc9d7f9bda93e1859dc4482cf3745bff2901bcf844b8cb
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@v1.70.1
28
+ with:
29
+ ruby-version: 3.0
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rake
data/Gemfile.lock CHANGED
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cexpect (0.1.1)
4
+ cexpect (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.0)
10
- diff-lcs (1.3)
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
11
  jaro_winkler (1.5.4)
12
- parallel (1.19.1)
13
- parser (2.7.1.1)
14
- ast (~> 2.4.0)
12
+ parallel (1.20.1)
13
+ parser (3.0.1.1)
14
+ ast (~> 2.4.1)
15
15
  rainbow (3.0.0)
16
16
  rake (12.3.3)
17
- rexml (3.2.4)
18
- rspec (3.9.0)
19
- rspec-core (~> 3.9.0)
20
- rspec-expectations (~> 3.9.0)
21
- rspec-mocks (~> 3.9.0)
22
- rspec-core (3.9.1)
23
- rspec-support (~> 3.9.1)
24
- rspec-expectations (3.9.1)
17
+ rexml (3.2.5)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.9.0)
27
- rspec-mocks (3.9.1)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.9.0)
30
- rspec-support (3.9.2)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
31
  rubocop (0.82.0)
32
32
  jaro_winkler (~> 1.5.1)
33
33
  parallel (~> 1.10)
@@ -36,9 +36,9 @@ GEM
36
36
  rexml
37
37
  ruby-progressbar (~> 1.7)
38
38
  unicode-display_width (>= 1.4.0, < 2.0)
39
- rubocop-rspec (1.38.1)
39
+ rubocop-rspec (1.41.0)
40
40
  rubocop (>= 0.68.1)
41
- ruby-progressbar (1.10.1)
41
+ ruby-progressbar (1.11.0)
42
42
  unicode-display_width (1.7.0)
43
43
 
44
44
  PLATFORMS
data/cexpect.gemspec CHANGED
@@ -4,7 +4,7 @@ require_relative 'lib/cexpect/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'cexpect'
7
- spec.version = Cexpect::VERSION
7
+ spec.version = CExpect::VERSION
8
8
  spec.authors = ['Christer Jansson']
9
9
  spec.email = ['christer@janssons.org']
10
10
 
data/lib/cexpect.rb CHANGED
@@ -1,33 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cexpect/module_methods'
3
4
  require 'delegate'
4
5
  require 'observer'
5
- require 'pty'
6
6
 
7
7
  #
8
8
  # A module for supplying a different expect method
9
9
  #
10
10
  module CExpect
11
- def self.spawn(*args)
12
- original_rd, wr, pid = PTY.spawn(*args)
13
- rd = CExpect::Reader.new(original_rd)
14
- if block_given?
15
- yield(rd, wr, pid)
16
- else
17
- [rd, wr, pid]
18
- end
19
- end
11
+ extend CExpect::ModuleMethods
20
12
 
21
13
  #
22
- # A class delegating normal operations to a wrapped IO, adding an
23
- # expect method
14
+ # A class delegating normal operations to a wrapped IO, adding
15
+ # expect methods
24
16
  #
25
17
  class Reader < SimpleDelegator
26
- include Observable
18
+ def add_observer(*args)
19
+ extend Observable # overwrites this method with Observable#add_observer
20
+ # Call the new add_observer method
21
+ add_observer(*args)
27
22
 
28
- def initialize(_original)
29
- @leftovers = ''
30
- super
23
+ extend LoggingReader
31
24
  end
32
25
 
33
26
  def expect(pat, timeout = nil, match_method: :re_match)
@@ -53,22 +46,17 @@ module CExpect
53
46
  def expect_try(pat, buf, timeout, match_method)
54
47
  c = getc(timeout)
55
48
 
56
- if c.nil?
57
- @leftovers = buf
58
- throw(:result, nil)
59
- end
49
+ throw(:result, nil) if c.nil?
60
50
 
61
51
  buf << c
62
52
 
63
- log(pat, buf)
53
+ log(pat, buf) if respond_to?(:log)
64
54
 
65
55
  result = send(match_method, buf, pat)
66
56
  throw(:result, result) if result
67
57
  end
68
58
 
69
59
  def getc(timeout)
70
- return @leftovers.slice!(0).chr unless @leftovers.empty?
71
-
72
60
  rd = __getobj__
73
61
 
74
62
  return nil if !IO.select([rd], nil, nil, timeout) || eof?
@@ -76,13 +64,6 @@ module CExpect
76
64
  rd.getc.chr
77
65
  end
78
66
 
79
- def log(pat, buf)
80
- return if count_observers.zero?
81
-
82
- changed
83
- notify_observers(pat, buf)
84
- end
85
-
86
67
  def re_match(buf, pat)
87
68
  buf.match(pat)
88
69
  end
@@ -91,4 +72,16 @@ module CExpect
91
72
  buf[0, buf.size - pat.size] if buf.end_with?(pat)
92
73
  end
93
74
  end
75
+
76
+ #
77
+ # Adds logging capability
78
+ #
79
+ module LoggingReader
80
+ def log(pat, buf)
81
+ return if count_observers.zero?
82
+
83
+ changed
84
+ notify_observers(pat, buf)
85
+ end
86
+ end
94
87
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pty'
4
+
5
+ module CExpect
6
+ #
7
+ # Module methods for CExpect
8
+ #
9
+ module ModuleMethods
10
+ #
11
+ # Assume first element benefits from using CExpect
12
+ #
13
+ # This generalization is a bit iffy; it works for class methods
14
+ # that returns and yields an IO reader first, followed by any
15
+ # other parameters. But hey, if we need to wrap things that behave
16
+ # differently, we can just give this one (and its shared examples
17
+ # in the specs) a more specific name and implement another.
18
+ #
19
+ def cexpect_wrap(array, &block)
20
+ array[0] = CExpect::Reader.new(array[0])
21
+ if block_given?
22
+ block.call(*array)
23
+ else
24
+ array
25
+ end
26
+ end
27
+
28
+ def pipe(*args, &block)
29
+ cexpect_wrap(IO.pipe(*args), &block)
30
+ end
31
+
32
+ def spawn(*args, &block)
33
+ cexpect_wrap(PTY.spawn(*args), &block)
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Cexpect
4
- VERSION = '0.1.2'
3
+ module CExpect
4
+ VERSION = '0.3.0'
5
5
  end
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.2
4
+ version: 0.3.0
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-30 00:00:00.000000000 Z
11
+ date: 2021-08-18 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:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/ruby.yml"
20
21
  - ".gitignore"
21
22
  - ".rspec"
22
23
  - ".rubocop.yml"
@@ -31,6 +32,7 @@ files:
31
32
  - bin/setup
32
33
  - cexpect.gemspec
33
34
  - lib/cexpect.rb
35
+ - lib/cexpect/module_methods.rb
34
36
  - lib/cexpect/version.rb
35
37
  homepage: https://github.com/kondensatorn/cexpect
36
38
  licenses:
@@ -54,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
56
  - !ruby/object:Gem::Version
55
57
  version: '0'
56
58
  requirements: []
57
- rubygems_version: 3.1.2
59
+ rubygems_version: 3.1.6
58
60
  signing_key:
59
61
  specification_version: 4
60
62
  summary: An improved expect method