summaryrefslogtreecommitdiff
path: root/test/ruby/envutil.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 06:29:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 06:29:44 +0000
commit5551307dd3a016d79b0df50e22cbc4db6a975cee (patch)
tree4a9236afefde771524ec628c8e412876694ca399 /test/ruby/envutil.rb
parentb8e6fd6ffe9f24921c7138f656596ae3bbdd7ad7 (diff)
envutil.rb: optional fname
* test/ruby/envutil.rb (Test::Unit::Assertions#assert_valid_syntax): make fname optional for inline source. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/envutil.rb')
-rw-r--r--test/ruby/envutil.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb
index 9759da0f73..e9b4b30896 100644
--- a/test/ruby/envutil.rb
+++ b/test/ruby/envutil.rb
@@ -133,7 +133,7 @@ module Test
module Unit
module Assertions
public
- def assert_valid_syntax(code, fname, mesg = fname)
+ def assert_valid_syntax(code, 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, :ok}\n"
@@ -141,15 +141,23 @@ module Test
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
assert_nothing_raised(SyntaxError, mesg) do
- assert_equal(:ok, catch {|tag| eval(code, binding, fname, 0)}, mesg)
+ assert_equal(:ok, catch {|tag| eval(code, binding, fname, line)}, mesg)
end
ensure
$VERBOSE = verbose
end
def assert_normal_exit(testsrc, message = '', opt = {})
- assert_valid_syntax(testsrc, caller_locations(1, 1)[0].path)
+ assert_valid_syntax(testsrc, caller_locations(1, 1)[0])
if opt.include?(:child_env)
opt = opt.dup
child_env = [opt.delete(:child_env)] || []