From 9e0ad7c0b14fbd017dc6be61e792bf69dd54e8fa Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 22 Jun 2011 12:03:05 +0100 Subject: Add tests for the external_command library, and fix a bug (which was actually a fairly late regression, showing the benefits of formal tests vs informal testing). I believe this bug was the cause of the recent Xapian indexing errors. --- spec/lib/external_command_spec.rb | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 spec/lib/external_command_spec.rb (limited to 'spec/lib/external_command_spec.rb') diff --git a/spec/lib/external_command_spec.rb b/spec/lib/external_command_spec.rb new file mode 100644 index 000000000..0ff1a9c0a --- /dev/null +++ b/spec/lib/external_command_spec.rb @@ -0,0 +1,40 @@ +# This is a test of the external_command library + +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +script_dir = File.join(File.dirname(__FILE__), 'external_command_scripts') +output_script = File.join(script_dir, "output.sh") + +require 'external_command' + +describe "when running ExternalCommand" do + + it "should get correct status code for /bin/true" do + t = ExternalCommand.new("/bin/true").run() + t.status.should == 0 + t.out.should == "" + t.err.should == "" + end + + it "should get correct status code for /bin/false" do + f = ExternalCommand.new("/bin/false").run() + f.status.should == 1 + f.out.should == "" + f.err.should == "" + end + + it "should get stdout and stderr" do + f = ExternalCommand.new(output_script, "out", "err", "10", "23").run() + f.status.should == 23 + f.out.should == (0..9).map {|i| "out #{i}\n"}.join("") + f.err.should == (0..9).map {|i| "err #{i}\n"}.join("") + end + + it "should work with large amounts of data" do + f = ExternalCommand.new(output_script, "a longer output line", "a longer error line", "10000", "5").run() + f.status.should == 5 + f.out.should == (0..9999).map {|i| "a longer output line #{i}\n"}.join("") + f.err.should == (0..9999).map {|i| "a longer error line #{i}\n"}.join("") + end + +end + -- cgit v1.2.3