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 (); }).ConfigureAwait (false);
17 async Task TestException_2 ()
19 await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
22 async Task TestException_3 ()
24 Func<Task> a = async () => await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
25 await a ().ConfigureAwait (false);
28 async Task<int> TestException_4 ()
31 await Task.Factory.StartNew (() => 5).ConfigureAwait (false);
33 throw new ApplicationException ();
37 async Task<int> TestException_5 ()
41 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
43 } catch (ArgumentException) {
47 throw new ApplicationException ();
53 async Task<int> TestException_6 ()
56 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
57 } catch (ArgumentException) {
58 throw new ApplicationException ();
64 static bool RunTest (MethodInfo test)
66 Console.Write ("Running test {0, -25}", test.Name);
68 Task t = test.Invoke (new Tester (), null) as Task;
70 if (!Task.WaitAll (new[] { t }, 1000)) {
71 Console.WriteLine ("FAILED (Timeout)");
74 } catch (AggregateException) {
77 if (t.Status != TaskStatus.Faulted) {
78 Console.WriteLine ("FAILED (Status={0})", t.Status);
82 if (!(t.Exception.InnerException is ApplicationException)) {
83 Console.WriteLine ("FAILED with wrong exception");
87 Console.WriteLine ("OK");
89 } catch (Exception e) {
90 Console.WriteLine ("FAILED");
91 Console.WriteLine (e.ToString ());
96 public static int Main ()
98 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
99 where test.GetParameters ().Length == 0
101 select RunTest (test);
103 int failures = tests.Count (a => !a);
104 Console.WriteLine (failures + " tests failed");