From 46b6825301b7b3b08a4fc12f63b93a6a16715017 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 20 Oct 2012 22:54:58 -0700 Subject: [PATCH] Don't show result of evaluating comments. --- lib/pry/pry_instance.rb | 4 +++- test/test_pry_output.rb | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 1158e905..4dd33eee 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -309,7 +309,9 @@ class Pry end end - @suppress_output = true if eval_string =~ /;\Z/ || eval_string.empty? + if eval_string =~ /;\Z/ || eval_string.empty? || eval_string =~ /\A *#.*\n\z/ + @suppress_output = true + end exec_hook :after_read, eval_string, self eval_string diff --git a/test/test_pry_output.rb b/test/test_pry_output.rb index 5c991240..a13a9d93 100644 --- a/test/test_pry_output.rb +++ b/test/test_pry_output.rb @@ -38,4 +38,25 @@ describe Pry do mock_pry("class NastyClass; undef pretty_inspect; end", "NastyClass.new").should =~ /#/ end end + + describe "output suppression" do + before do + @t = pry_tester + end + it "should normally output the result" do + mock_pry("1 + 2").should == "=> 3\n\n" + end + + it "should not output anything if the input ends with a semicolon" do + mock_pry("1 + 2;").should == "\n" + end + + it "should output something if the input ends with a comment" do + mock_pry("1 + 2 # basic addition").should == "=> 3\n\n" + end + + it "should not output something if the input is only a comment" do + mock_pry("# basic addition").should == "\n" + end + end end