1 // Compiler options: -langversion:future
4 using System.Threading.Tasks;
5 using System.Threading;
6 using System.Reflection;
11 async Task<int> TestException_1 ()
13 await Task.Factory.StartNew (() => { throw new ApplicationException (); });
17 async Task TestException_2 ()
19 await Task.Factory.StartNew (() => { throw new ApplicationException (); });
22 async Task TestException_3 ()
24 Func<Task> a = async () => await Task.Factory.StartNew (() => { throw new ApplicationException (); });
28 async Task<int> TestException_4 ()
31 await Task.Factory.StartNew (() => 5);
33 throw new ApplicationException ();
37 static bool RunTest (MethodInfo test)
39 Console.Write ("Running test {0, -25}", test.Name);
41 Task t = test.Invoke (new Tester (), null) as Task;
43 if (!Task.WaitAll (new[] { t }, 1000)) {
44 Console.WriteLine ("FAILED (Timeout)");
47 } catch (AggregateException) {
50 if (t.Status != TaskStatus.Faulted) {
51 Console.WriteLine ("FAILED (Status={0})", t.Status);
55 if (!(t.Exception.InnerException is ApplicationException)) {
56 Console.WriteLine ("FAILED with wrong exception");
60 Console.WriteLine ("OK");
62 } catch (Exception e) {
63 Console.WriteLine ("FAILED");
64 Console.WriteLine (e.ToString ());
69 public static int Main ()
71 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
72 where test.GetParameters ().Length == 0
74 select RunTest (test);
76 int failures = tests.Count (a => !a);
77 Console.WriteLine (failures + " tests failed");