1 // Compiler options: -langversion:future
4 using System.Threading.Tasks;
5 using System.Threading;
6 using System.Reflection;
8 using System.Collections.Generic;
10 class Base : IDisposable
12 protected static int dispose_counter;
14 public void Dispose ()
22 async Task<int> SwitchTest_1 ()
24 switch (await Task.Factory.StartNew (() => "X").ConfigureAwait (false)) {
40 async Task<int> Using_1 ()
42 using (Base a = await Task.Factory.StartNew (() => new Base ()).ConfigureAwait (false),
43 b = await Task.Factory.StartNew (() => new Tester ()).ConfigureAwait (false),
44 c = await Task.Factory.StartNew (() => new Base ()).ConfigureAwait (false),
45 d = await Task.Factory.StartNew (() => new Base ()).ConfigureAwait (false)) {
48 if (dispose_counter != 4)
54 async Task<int> Foreach_1 ()
57 foreach (var e in await Task.Factory.StartNew (() => new List<int> () { 1, 2, 3 }).ConfigureAwait (false)) {
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;
69 if (!Task.WaitAll (new[] { t }, 1000)) {
70 Console.WriteLine ("FAILED (Timeout)");
74 var ti = t as Task<int>;
77 Console.WriteLine ("FAILED (Result={0})", ti.Result);
81 var tb = t as Task<bool>;
84 Console.WriteLine ("FAILED (Result={0})", tb.Result);
90 Console.WriteLine ("OK");
92 } catch (Exception e) {
93 Console.WriteLine ("FAILED");
94 Console.WriteLine (e.ToString ());
99 public static int Main ()
101 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
102 where test.GetParameters ().Length == 0
104 select RunTest (test);
106 int failures = tests.Count (a => !a);
107 Console.WriteLine (failures + " tests failed");