mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use dedicated assertion methods for warning and syntax error
This commit is contained in:
parent
601f1fb456
commit
d5d5844744
1 changed files with 15 additions and 23 deletions
|
@ -855,32 +855,24 @@ x = __ENCODING__
|
|||
end
|
||||
|
||||
def test_void_expr_stmts_value
|
||||
# This test checks if void contexts are warned correctly.
|
||||
# Thus, warnings MUST NOT be suppressed.
|
||||
$VERBOSE = true
|
||||
stderr = $stderr
|
||||
$stderr = StringIO.new("")
|
||||
x = 1
|
||||
assert_nil eval("x; nil")
|
||||
assert_nil eval("1+1; nil")
|
||||
assert_nil eval("1.+(1); nil")
|
||||
assert_nil eval("TestParse; nil")
|
||||
assert_nil eval("::TestParse; nil")
|
||||
assert_nil eval("x..x; nil")
|
||||
assert_nil eval("x...x; nil")
|
||||
assert_nil eval("self; nil")
|
||||
assert_nil eval("nil; nil")
|
||||
assert_nil eval("true; nil")
|
||||
assert_nil eval("false; nil")
|
||||
assert_nil eval("defined?(1); nil")
|
||||
useless_use = /useless use/
|
||||
unused = /unused/
|
||||
assert_nil assert_warning(useless_use) {eval("x; nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("1+1; nil")}
|
||||
assert_nil assert_warning('') {eval("1.+(1); nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("TestParse; nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("::TestParse; nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("x..x; nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("x...x; nil")}
|
||||
assert_nil assert_warning(unused) {eval("self; nil")}
|
||||
assert_nil assert_warning(unused) {eval("nil; nil")}
|
||||
assert_nil assert_warning(unused) {eval("true; nil")}
|
||||
assert_nil assert_warning(unused) {eval("false; nil")}
|
||||
assert_nil assert_warning(useless_use) {eval("defined?(1); nil")}
|
||||
assert_equal 1, x
|
||||
|
||||
assert_raise(SyntaxError) do
|
||||
eval %q(1; next; 2)
|
||||
end
|
||||
|
||||
assert_equal(13, $stderr.string.lines.to_a.size)
|
||||
$stderr = stderr
|
||||
assert_syntax_error("1; next; 2", /Invalid next/)
|
||||
end
|
||||
|
||||
def test_assign_in_conditional
|
||||
|
|
Loading…
Reference in a new issue