[ilasm] Don't break arguments compatiblity
[mono-project.git] / mcs / tests / test-async-17.cs
blob9f9720bc2bc17e5715fc3be970ce3af4fb4e141e
1 using System;
2 using System.Threading.Tasks;
3 using System.Threading;
4 using System.Reflection;
5 using System.Linq;
7 class Tester
9 async Task<int> TestException_1 ()
11 await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
12 return 1;
15 async Task TestException_2 ()
17 await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
20 async Task TestException_3 ()
22 Func<Task> a = async () => await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
23 await a ().ConfigureAwait (false);
26 async Task<int> TestException_4 ()
28 try {
29 await Task.Factory.StartNew (() => 5).ConfigureAwait (false);
30 } finally {
31 throw new ApplicationException ();
35 async Task<int> TestException_5 ()
37 int state = 0;
38 try {
39 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
40 state = 1;
41 } catch (ArgumentException) {
42 state = 2;
43 } finally {
44 if (state == 2)
45 throw new ApplicationException ();
48 return 1;
51 async Task<int> TestException_6 ()
53 try {
54 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
55 } catch (ArgumentException) {
56 throw new ApplicationException ();
59 return 1;
62 async Task<int> TestException_7 ()
64 try {
65 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
66 } catch (ArgumentException e) {
67 if (e.StackTrace.Contains (".MoveNext"))
68 throw new ApplicationException ();
71 return 1;
74 static bool RunTest (MethodInfo test)
76 Console.Write ("Running test {0, -25}", test.Name);
77 try {
78 Task t = test.Invoke (new Tester (), null) as Task;
79 try {
80 if (!Task.WaitAll (new[] { t }, 1000)) {
81 Console.WriteLine ("FAILED (Timeout)");
82 return false;
84 } catch (AggregateException) {
87 if (t.Status != TaskStatus.Faulted) {
88 Console.WriteLine ("FAILED (Status={0})", t.Status);
89 return false;
92 if (!(t.Exception.InnerException is ApplicationException)) {
93 Console.WriteLine ("FAILED with wrong exception");
94 return false;
97 Console.WriteLine ("OK");
98 return true;
99 } catch (Exception e) {
100 Console.WriteLine ("FAILED");
101 Console.WriteLine (e.ToString ());
102 return false;
106 public static int Main ()
108 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
109 where test.GetParameters ().Length == 0
110 orderby test.Name
111 select RunTest (test);
113 int failures = tests.Count (a => !a);
114 Console.WriteLine (failures + " tests failed");
115 return failures;