diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-25 12:20:00 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-25 12:20:00 +0000 |
commit | 51ea3db6d565f7048d2953479e90625226f75740 (patch) | |
tree | f6875003e8b9c86eedeb1270fc0b41c3077640b1 /test | |
parent | 1059cf6e30d6ce7ad91acb94ed142c19cf05fe0a (diff) |
merge revision(s) 34910:
assert_valid_syntax
* test/ruby/test_syntax.rb (assert_valid_syntax): new assertion to
validate syntax.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_syntax.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 215785a051..d924679c7f 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1,21 +1,24 @@ require 'test/unit' class TestSyntax < Test::Unit::TestCase - def valid_syntax?(code, fname) + def assert_valid_syntax(code, fname, mesg = fname) code = code.dup.force_encoding("ascii-8bit") code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) { "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n" } code.force_encoding("us-ascii") - catch {|tag| eval(code, binding, fname, 0)} - rescue SyntaxError - false + verbose, $VERBOSE = $VERBOSE, nil + assert_nothing_raised(SyntaxError, mesg) do + assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg) + end + ensure + $VERBOSE = verbose end def test_syntax assert_nothing_raised(Exception) do for script in Dir[File.expand_path("../../../{lib,sample,ext,test}/**/*.rb", __FILE__)].sort - assert(valid_syntax?(IO::read(script), script), script) + assert_valid_syntax(IO::read(script), script) end end end @@ -57,11 +60,6 @@ class TestSyntax < Test::Unit::TestCase assert_valid_syntax("def self; :foo; end", __FILE__, bug6403) end - def test_reserved_method_no_args - bug6403 = '[ruby-dev:45626]' - assert_valid_syntax("def self; :foo; end", __FILE__, bug6403) - end - private def make_tmpsrc(f, src) |