comparison graal/com.oracle.truffle.ruby.test/src/com/oracle/truffle/ruby/test/language/RaiseRescueTests.java @ 13514:0fbee3eb71f0

Ruby: import project.
author Chris Seaton <chris.seaton@oracle.com>
date Mon, 06 Jan 2014 17:12:09 +0000
parents
children
comparison
equal deleted inserted replaced
13513:64a23ce736a0 13514:0fbee3eb71f0
1 /*
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
3 * code is released under a tri EPL/GPL/LGPL license. You can use it,
4 * redistribute it and/or modify it under the terms of the:
5 *
6 * Eclipse Public License version 1.0
7 * GNU General Public License version 2
8 * GNU Lesser General Public License version 2.1
9 */
10 package com.oracle.truffle.ruby.test.language;
11
12 import org.junit.*;
13
14 import com.oracle.truffle.ruby.runtime.control.*;
15 import com.oracle.truffle.ruby.test.*;
16
17 /**
18 * Test {@code raise} and {@code rescue}.
19 */
20 public class RaiseRescueTests extends RubyTests {
21
22 @Test(expected = RaiseException.class)
23 public void testZeroDivisionError() {
24 assertPrints("", "1/0");
25 }
26
27 @Test
28 public void testBeginRescue() {
29 assertPrints("", "begin; rescue; end");
30 assertPrints("", "begin; rescue => e; end");
31 assertPrints("", "begin; rescue ZeroDivisionError => e; end");
32 assertPrints("", "begin; rescue; ensure; end");
33 assertPrints("", "begin; rescue => e; ensure; end");
34 assertPrints("", "begin; rescue ZeroDivisionError => e; ensure; end");
35 assertPrints("", "begin; rescue; else; end");
36 assertPrints("", "begin; rescue => e; else; end");
37 assertPrints("", "begin; rescue ZeroDivisionError => e; else; end");
38 assertPrints("", "def foo; rescue; end");
39 assertPrints("", "def foo; rescue => e; end");
40 assertPrints("", "def foo; rescue ZeroDivisionError => e; end");
41 assertPrints("", "def foo; rescue; ensure; end");
42 assertPrints("", "def foo; rescue => e; ensure; end");
43 assertPrints("", "def foo; rescue ZeroDivisionError => e; ensure; end");
44 assertPrints("", "def foo; rescue; else; end");
45 assertPrints("", "def foo; rescue => e; else; end");
46 assertPrints("", "def foo; rescue ZeroDivisionError => e; else; end");
47 }
48
49 @Test
50 public void testRescueZeroDivisionError() {
51 assertPrints("divided by 0\n3\n4\n", "begin; 1/0; puts 1; rescue => e; puts e; else puts 2; ensure puts 3; end; puts 4");
52 assertPrints("divided by 0\n3\n4\n", "begin; 1/0; puts 1; rescue ZeroDivisionError => e; puts e; else puts 2; ensure puts 3; end; puts 4");
53 assertPrints("1\n2\n3\n4\n", "begin; 1/1; puts 1; rescue ZeroDivisionError => e; puts e; else puts 2; ensure puts 3; end; puts 4");
54 assertPrints("1\n2\n3\n4\n", "begin; 1/1; puts 1; rescue ZeroDivisionError => e; puts e; rescue NameError => e; puts e; else puts 2; ensure puts 3; end; puts 4");
55 }
56
57 @Test
58 public void testSplatRescue() {
59 assertPrints("2\n", "ERRORS=[ZeroDivisionError]; begin; 1/0; puts 1; rescue *ERRORS; puts 2; end");
60 }
61
62 @Test
63 public void testRetry() {
64 assertPrints("1\n3\n1\n2\n5\n", "x=0; begin; puts 1; 1/x; puts 2; rescue ZeroDivisionError; puts 3; x=1; retry; puts 4; end; puts 5");
65 }
66
67 }