summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-20 02:05:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-20 02:05:37 +0000
commit0de805f62bda2cbfac2a0c6392bdf7cae014cde4 (patch)
tree1a47b73ac36f022b58a0dcb1d78c9d431e0fff0e /test/ruby
parent3ec171510eafbf682d67b1997460f2c5c27a3636 (diff)
envutil.rb: validate syntax
* test/ruby/envutil.rb (assert_valid_syntax): move from test_syntax.rb. * test/ruby/envutil.rb (assert_normal_exit): validate syntax before running because this assertion passes even if the code fails by SyntaxError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/envutil.rb16
-rw-r--r--test/ruby/test_syntax.rb15
2 files changed, 16 insertions, 15 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index 6006ae75b4..42a9bf0aa6 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -133,7 +133,23 @@ module Test
module Unit
module Assertions
public
+ 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")
+ verbose, $VERBOSE = $VERBOSE, nil
+ yield if defined?(yield)
+ assert_nothing_raised(SyntaxError, mesg) do
+ assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg)
+ end
+ ensure
+ $VERBOSE = verbose
+ end
+
def assert_normal_exit(testsrc, message = '', opt = {})
+ assert_valid_syntax(testsrc, caller_locations(1, 1)[0].path)
if opt.include?(:child_env)
opt = opt.dup
child_env = [opt.delete(:child_env)] || []
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index f9f279d751..b2d625cd2a 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -2,21 +2,6 @@ require 'test/unit'
require_relative 'envutil'
class TestSyntax < Test::Unit::TestCase
- 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")
- verbose, $VERBOSE = $VERBOSE, nil
- yield if defined?(yield)
- 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