Project

General

Profile

Feature #5219 ยป pack.c.warn_on_unknown_directive.patch

drbrain (Eric Hodel), 03/27/2012 09:09 AM

View differences:

pack.c (working copy)
1026 1026
	    break;
1027 1027

  
1028 1028
	  default:
1029
	    rb_warning("unknown pack directive '%c' in '%s'",
1030
		type, RSTRING_PTR(fmt));
1029 1031
	    break;
1030 1032
	}
1031 1033
    }
......
2143 2145
	    break;
2144 2146

  
2145 2147
	  default:
2148
	    rb_warning("unknown unpack directive '%c' in '%s'",
2149
		type, RSTRING_PTR(fmt));
2146 2150
	    break;
2147 2151
	}
2148 2152
    }
test/ruby/test_pack.rb (working copy)
651 651
    assert_nil("".unpack("i") {|x| result = x}, bug4059)
652 652
    assert_equal(:ok, result)
653 653
  end
654

  
655
  def test_pack_garbage
656
    assert_silent do
657
      assert_equal "\000", [0].pack("*U")
658
    end
659

  
660
    verbose = $VERBOSE
661
    $VERBOSE = true
662

  
663
    _, err = capture_io do
664
      assert_equal "\000", [0].pack("*U")
665
    end
666

  
667
    assert_match %r%unknown pack directive '\*' in '\*U'$%, err
668
  ensure
669
    $VERBOSE = verbose
670
  end
671

  
672
  def test_unpack_garbage
673
    assert_silent do
674
      assert_equal [0], "\000".unpack("*U")
675
    end
676

  
677
    verbose = $VERBOSE
678
    $VERBOSE = true
679

  
680
    _, err = capture_io do
681
      assert_equal [0], "\000".unpack("*U")
682
    end
683

  
684
    assert_match %r%unknown unpack directive '\*' in '\*U'$%, err
685
  ensure
686
    $VERBOSE = verbose
687
  end
688

  
654 689
end