Ejemplo n.º 1
0
        internal static void SupportAbortNew(UnitTestLaunch launch)
        {
            try
            {
                const string assemblyName = "UnityEditor.TestRunner";
                const string typeName     = "UnityEditor.TestTools.TestRunner.Api.TestRunnerApi";
                const string methodName   = "CancelAllTestRuns";

                MethodInfo stopRunMethod = null;

                var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.Equals(assemblyName));
                if (assembly == null)
                {
                    ourLogger.Verbose($"Could not find {assemblyName} in the AppDomain.");
                }
                else
                {
                    var apiType = assembly.GetType(typeName);
                    if (apiType == null)
                    {
                        ourLogger.Verbose($"Could not find {typeName} in the {assemblyName}.");
                    }
                    else
                    {
                        stopRunMethod = apiType.GetMethod(methodName);
                        if (stopRunMethod == null)
                        {
                            ourLogger.Verbose($"Could not find {methodName} in the {typeName}.");
                        }
                    }
                }

                launch.Abort.Set((lifetime, _) =>
                {
                    var task = new RdTask <bool>();

                    if (stopRunMethod != null)
                    {
                        ourLogger.Verbose($"Call {methodName} method via reflection.");
                        try
                        {
                            stopRunMethod.Invoke(null, null);
                            task.Set(true);
                            if (!launch.RunStarted.HasTrueValue()) // if RunStarted never happened
                            {
                                launch.RunResult(new RunResult(false));
                            }
                        }
                        catch (Exception)
                        {
                            ourLogger.Verbose($"Call {methodName} method failed.");
                            task.Set(false);
                        }
                    }
                    else
                    {
                        task.Set(false);
                    }

                    return(task);
                });
            }
            catch (Exception e)
            {
                ourLogger.Error(e, "Unexpected exception in SupportAbortNew");
            }
        }
Ejemplo n.º 2
0
 public static void RunFinished(UnitTestLaunch launch, RunResult result)
 {
     launch.RunResult(result);
 }
Ejemplo n.º 3
0
 public static void RunFinished(UnitTestLaunch launch)
 {
     launch.RunResult(new RunResult(true));
 }