~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/pty/lib/expect.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
$expect_verbose = false
2
2
 
3
3
class IO
 
4
  # Reads ios until pattern matches or the timeout is over. It returns
 
5
  # an array with the read buffer, followed by the matches. If a block is given,
 
6
  # the result is yielded to the block and returns nil. The optional timeout parameter defines,
 
7
  # in seconds, the total time to wait for pattern. If it is over of eof is found, it 
 
8
  # returns/yields nil. However, the buffer in a timeout session is kept for the next expect call.
 
9
  # The default timeout is 9999999 seconds.
4
10
  def expect(pat,timeout=9999999)
5
11
    buf = ''
6
12
    case pat
8
14
      e_pat = Regexp.new(Regexp.quote(pat))
9
15
    when Regexp
10
16
      e_pat = pat
 
17
    else
 
18
      raise TypeError, "unsupported pattern class: #{pattern.class}"
11
19
    end
 
20
    @unusedBuf ||= ''
12
21
    while true
13
 
      if !IO.select([self],nil,nil,timeout) or eof? then
 
22
      if not @unusedBuf.empty?
 
23
        c = @unusedBuf.slice!(0).chr
 
24
      elsif !IO.select([self],nil,nil,timeout) or eof? then
14
25
        result = nil
 
26
        @unusedBuf = buf
15
27
        break
 
28
      else
 
29
        c = getc.chr
16
30
      end
17
 
      c = getc.chr
18
31
      buf << c
19
32
      if $expect_verbose
20
33
        STDOUT.print c