summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 06:29:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 06:29:48 +0000
commit86c0eae56e496584105f550b0d123b666885a99f (patch)
tree8067f2787c4739eed60a3bf03900950527b3eabe
parent5551307dd3a016d79b0df50e22cbc4db6a975cee (diff)
envutil.rb: assert_syntax_error
* test/ruby/envutil.rb (Test::Unit::Assertions#assert_syntax_error): new assertion for syntax error and error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/envutil.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index e9b4b30896..34963df653 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -156,6 +156,30 @@ module Test
$VERBOSE = verbose
end
+ def assert_syntax_error(code, error, fname = caller_locations(1, 1)[0], mesg = fname.to_s)
+ code = code.dup.force_encoding("ascii-8bit")
+ code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
+ "#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ng}\n"
+ }
+ code.force_encoding("us-ascii")
+ verbose, $VERBOSE = $VERBOSE, nil
+ yield if defined?(yield)
+ case
+ when Array === fname
+ fname, line = *fname
+ when defined?(fname.path) && defined?(fname.lineno)
+ fname, line = fname.path, fname.lineno
+ else
+ line = 0
+ end
+ e = assert_raise(SyntaxError, mesg) do
+ catch {|tag| eval(code, binding, fname, line)}
+ end
+ assert_match(error, e.message, mesg)
+ ensure
+ $VERBOSE = verbose
+ end
+
def assert_normal_exit(testsrc, message = '', opt = {})
assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
if opt.include?(:child_env)