Skip to content
This repository

Open3 test cases #137

Open
wants to merge 2 commits into from

2 participants

Clayton Wheeler Hiro Asari
Clayton Wheeler
csw commented May 15, 2012

This patch adds simple test cases for Open3.popen3(). The "accepts an array arg giving path and argv[0] for execve" cases cover a bug observed in JRuby 1.6.7, to be reported shortly.

added some commits May 15, 2012
Clayton Wheeler Created basic spec for Open3.popen3.
The "accepts an array arg giving path and argv[0] for execve" case
covers a bug observed in JRuby.
b1e0e80
Clayton Wheeler Test Open3 more completely, exposing a bug in the multiple-arg case. eab3353
Hiro Asari
Collaborator

You'd need guards so that these specs behave on Windows. Also, are you sure that echo and cat always reside in /bin? (I'm just asking. I do not know either way for certain.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

May 15, 2012
Clayton Wheeler Created basic spec for Open3.popen3.
The "accepts an array arg giving path and argv[0] for execve" case
covers a bug observed in JRuby.
b1e0e80
Clayton Wheeler Test Open3 more completely, exposing a bug in the multiple-arg case. eab3353
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 69 additions and 0 deletions. Show diff stats Hide diff stats

  1. 69  library/open3/open3_spec.rb
69  library/open3/open3_spec.rb
... ...
@@ -0,0 +1,69 @@
  1
+require File.expand_path('../../../spec_helper', __FILE__)
  2
+require "open3"
  3
+
  4
+describe "Open3.popen3" do
  5
+  after :each do
  6
+    [@in, @out, @err].each do |stream|
  7
+      stream.close if stream and !stream.closed?
  8
+    end
  9
+  end
  10
+
  11
+  it "returns an open stdin" do
  12
+    @in, @out, @err = Open3.popen3("cat")
  13
+    @in.closed?.should be_false
  14
+  end
  15
+
  16
+  it "returns an open stdout" do
  17
+    @in, @out, @err = Open3.popen3("cat")
  18
+    @out.closed?.should be_false
  19
+  end
  20
+
  21
+  it "returns an open stderr" do
  22
+    @in, @out, @err = Open3.popen3("cat")
  23
+    @err.closed?.should be_false
  24
+  end
  25
+
  26
+  it "returns a write-only stdin" do
  27
+    @in, @out, @err = Open3.popen3("cat")
  28
+    lambda { @in.read(1) }.should raise_error
  29
+  end
  30
+
  31
+it "returns a read-only stdout" do
  32
+    @in, @out, @err = Open3.popen3("cat")
  33
+    lambda { @out.write('foo') }.should raise_error(IOError)
  34
+  end
  35
+
  36
+  it "returns a read-only stderr" do
  37
+    @in, @out, @err = Open3.popen3("cat")
  38
+    lambda { @out.write('foo') }.should raise_error(IOError)
  39
+  end
  40
+
  41
+  it "returns a readable stdout" do
  42
+    @in, @out, @err = Open3.popen3("echo foo")
  43
+    @out.read.should == "foo\n"
  44
+  end
  45
+
  46
+  it "reads and writes successfully" do
  47
+    @in, @out, @err = Open3.popen3("cat")
  48
+    @in.write("foo")
  49
+    @in.close
  50
+    @out.read(3).should == "foo"
  51
+  end
  52
+
  53
+  it "accepts an array arg giving path and argv[0] for execve" do
  54
+    lambda {
  55
+      @in, @out, @err = Open3.popen3(["/bin/cat", "cat"])
  56
+    }.should_not raise_error(NoMethodError)
  57
+  end
  58
+
  59
+  it "accepts an array arg giving path and argv[0] for execve, with args" do
  60
+    lambda {
  61
+      @in, @out, @err = Open3.popen3(["/bin/echo", "echo"], "foo")
  62
+    }.should_not raise_error(NoMethodError)
  63
+  end
  64
+
  65
+  it "functions with an array arg giving path and argv[0] for execve, w/args" do
  66
+    @in, @out, @err = Open3.popen3(["/bin/echo", "echo"], "foo")
  67
+    @out.read.should == "foo\n"
  68
+  end
  69
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.