Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / test-async-13.cs
index bd72820d14245f088d8f63aa4466a2b05e9da7f6..33279ff09595988f1308bea6f370a134fa8349b4 100644 (file)
@@ -1,18 +1,19 @@
-// Compiler options: -langversion:future
-
 using System;
 using System.Threading.Tasks;
 using System.Threading;
 using System.Reflection;
 using System.Linq;
+using System.Runtime.CompilerServices;
 
 struct S
 {
        public int Value;
+       public S2 s2;
        
        public S (int a1, string a2)
        {
                Value = a1;
+               s2 = new S2 ();
        }
        
        public void SetValue (int value)
@@ -33,6 +34,11 @@ struct S
        }
 }
 
+struct S2
+{
+       public int Value;
+}
+
 enum E
 {
        E_1 = 1
@@ -271,6 +277,21 @@ class Tester : Base
                return 0;
        }
 
+       async Task<bool> ArrayAccessTest_10 ()
+       {
+               var b = new bool [1] { true };
+               
+               var r = b [await Task.Factory.StartNew (() => 0)];
+               return r;
+       }
+
+       async Task<bool> ArrayAccessTest_11 ()
+       {
+               var a = new S [1];
+               a [await Task.Factory.StartNew (() => 0)].s2.Value += 5;
+               return a [await Task.Factory.StartNew(() => 0)].s2.Value == 5;
+       }
+
        async Task<int> AssignTest_1 ()
        {
                field_int = await Task.Factory.StartNew (() => 0);
@@ -341,6 +362,28 @@ class Tester : Base
                return 0;
        }
        
+       async Task<int> BinaryTest_5 ()
+       {
+               var r1 = await Task.FromResult (1) == 9;
+               if (r1)
+                       return 1;
+               
+               var r2 = 1 == await Task.FromResult (1);
+               if (!r2)
+                       return 2;
+               
+               return 0;
+       }
+
+       async Task<bool> BinaryTest_6 ()
+       {
+               var t = Task.Delay (1);
+               if (t == await Task.WhenAny(new [] { t }))
+                       return true;
+
+               return false;
+       }
+
        async Task<int> CallTest_1 ()
        {
                return Call (
@@ -405,10 +448,7 @@ class Tester : Base
        
        async Task<int> ConditionalTest_1 ()
        {
-               // TODO: problem with Resumable point setup when the expression never emitted
-               //bool b = true;
-               //return true ? await Task.Factory.StartNew (() => 0) : await Task.Factory.StartNew (() => 1);
-               return 0;
+               return true ? await Task.Factory.StartNew (() => 0) : await Task.Factory.StartNew (() => 1);
        }
        
        async Task<int> ConditionalTest_2 ()
@@ -567,6 +607,18 @@ class Tester : Base
                var s = new S (await Task.Factory.StartNew (() => 77), await Task.Factory.StartNew (() => "b"));
                return s.Value == 77;
        }
+
+       async Task<int> NewDelegate_1 ()
+       {
+               var f = new Func<int> (await NewDelegate_1_0 ());
+               return f ();
+       }
+
+       static async Task<Func<int>> NewDelegate_1_0 ()
+       {
+               await Task.Factory.StartNew (() => { });
+               return () => 0;         
+       }
        
        async Task<int> NewInitTest_1 ()
        {
@@ -657,10 +709,15 @@ class Tester : Base
        async Task<bool> NewArrayInitTest_6 ()
        {
                var a = new int[] { 2, 3, 2, 3, 5, 6, 7, 2, 4, await Task.Factory.StartNew (() => 5), 11, 23, 45 };
-               Console.WriteLine (a.Length);
                return a.Length == 13;
        }
        
+       async Task<bool> NewArrayInitTest_7 ()
+       {
+               var res = new [] { "a", new [] { "1", await Task.FromResult ("2") } [1], "b" };
+               return res [1] == "2";
+       }
+
        async Task<bool> PropertyTest_1 ()
        {
                PropertyInt = await Task.Factory.StartNew (() => 6);
@@ -722,6 +779,12 @@ class Tester : Base
                return r == 5;
        }
        
+       async Task<bool> VariableInitializer_1 ()
+       {
+               int a = 2, b = await Task.Factory.StartNew (() => 1), c = await Task.Factory.StartNew (() => 1);
+               return a == (b + c);
+       }
+
        static bool RunTest (MethodInfo test)
        {
                Console.Write ("Running test {0, -25}", test.Name);
@@ -760,7 +823,7 @@ class Tester : Base
        public static int Main ()
        {
                var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
-                                       where test.GetParameters ().Length == 0
+                                       where test.GetParameters ().Length == 0 && !test.IsDefined (typeof (CompilerGeneratedAttribute), false)
                                        orderby test.Name
                                        select RunTest (test);