Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid modifying errorCode and errorInfo during Var.find

  • Loading branch information...
commit b893140c734c129e47b3fdf3214c71918a346393 1 parent 2918eaf
@sstephenson sstephenson authored
Showing with 21 additions and 4 deletions.
  1. +4 −4 lib/tcl/var.rb
  2. +17 −0 test/var_test.rb
View
8 lib/tcl/var.rb
@@ -9,12 +9,12 @@ class Var
class << self
def find(interp, name)
- StringVar.new(interp, name)
- rescue Tcl::Error => e
- if e.message["variable is array"]
+ if interp._!(:array, :exists, name) == "1"
ArrayVar.new(interp, name)
+ elsif interp._!(:info, :exists, name) == "1"
+ StringVar.new(interp, name)
else
- raise
+ raise Tcl::Error, "can't read \"#{name}\": no such variable"
end
end
end
View
17 test/var_test.rb
@@ -36,4 +36,21 @@ def test_string_var_to_tcl
def test_array_var_to_tcl
assert_equal "array set b {a 1 b 2}", @interp.var("b").to_tcl
end
+
+ def test_array_var_to_tcl_does_not_modify_errorInfo
+ assert_errorinfo ""
+ Tcl::Var.find(@interp, "b")
+ assert_errorinfo ""
+ end
+
+ def test_attempting_to_find_nonexistent_variable_does_not_modify_errorInfo
+ assert_errorinfo ""
+ assert_raises(Tcl::Error) { Tcl::Var.find(@interp, "nonexistent") }
+ assert_errorinfo ""
+ end
+
+ protected
+ def assert_errorinfo(value)
+ assert_equal value, @interp.var("errorInfo").value
+ end
end

0 comments on commit b893140

Please sign in to comment.
Something went wrong with that request. Please try again.