Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Open3 test cases #137

Closed
wants to merge 2 commits into from

3 participants

@csw

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.

csw added some commits
@csw csw 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
@csw csw Test Open3 more completely, exposing a bug in the multiple-arg case. eab3353
@BanzaiMan

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.)

@YorickPeterse

Closing this since Open3 is no longer part of RubySpec as RubySpec only covers Ruby plus the core library, not the standard library. Specs for open3 can be added, if needed, at https://github.com/rubysl/rubysl-open3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 15, 2012
  1. @csw

    Created basic spec for Open3.popen3.

    csw authored
    The "accepts an array arg giving path and argv[0] for execve" case
    covers a bug observed in JRuby.
  2. @csw
This page is out of date. Refresh to see the latest.
Showing with 69 additions and 0 deletions.
  1. +69 −0 library/open3/open3_spec.rb
View
69 library/open3/open3_spec.rb
@@ -0,0 +1,69 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require "open3"
+
+describe "Open3.popen3" do
+ after :each do
+ [@in, @out, @err].each do |stream|
+ stream.close if stream and !stream.closed?
+ end
+ end
+
+ it "returns an open stdin" do
+ @in, @out, @err = Open3.popen3("cat")
+ @in.closed?.should be_false
+ end
+
+ it "returns an open stdout" do
+ @in, @out, @err = Open3.popen3("cat")
+ @out.closed?.should be_false
+ end
+
+ it "returns an open stderr" do
+ @in, @out, @err = Open3.popen3("cat")
+ @err.closed?.should be_false
+ end
+
+ it "returns a write-only stdin" do
+ @in, @out, @err = Open3.popen3("cat")
+ lambda { @in.read(1) }.should raise_error
+ end
+
+it "returns a read-only stdout" do
+ @in, @out, @err = Open3.popen3("cat")
+ lambda { @out.write('foo') }.should raise_error(IOError)
+ end
+
+ it "returns a read-only stderr" do
+ @in, @out, @err = Open3.popen3("cat")
+ lambda { @out.write('foo') }.should raise_error(IOError)
+ end
+
+ it "returns a readable stdout" do
+ @in, @out, @err = Open3.popen3("echo foo")
+ @out.read.should == "foo\n"
+ end
+
+ it "reads and writes successfully" do
+ @in, @out, @err = Open3.popen3("cat")
+ @in.write("foo")
+ @in.close
+ @out.read(3).should == "foo"
+ end
+
+ it "accepts an array arg giving path and argv[0] for execve" do
+ lambda {
+ @in, @out, @err = Open3.popen3(["/bin/cat", "cat"])
+ }.should_not raise_error(NoMethodError)
+ end
+
+ it "accepts an array arg giving path and argv[0] for execve, with args" do
+ lambda {
+ @in, @out, @err = Open3.popen3(["/bin/echo", "echo"], "foo")
+ }.should_not raise_error(NoMethodError)
+ end
+
+ it "functions with an array arg giving path and argv[0] for execve, w/args" do
+ @in, @out, @err = Open3.popen3(["/bin/echo", "echo"], "foo")
+ @out.read.should == "foo\n"
+ end
+end
Something went wrong with that request. Please try again.