Exemplo n.º 1
0
        Program(Assembly assembly, string[] args)
        {
            Options = new ProgramOptions(assembly, args);

            switch (Options.Command)
            {
            case Command.Simulator:
            case Command.Device:
            case Command.TVOS:
                Launcher = new TouchLauncher(this);
                break;

            case Command.Mac:
                Launcher = new MacLauncher(this);
                break;

            case Command.Android:
                DroidHelper = new DroidHelper(this);
                Launcher    = new DroidLauncher(this);
                break;

            case Command.Avd:
            case Command.Emulator:
            case Command.Apk:
                DroidHelper = new DroidHelper(this);
                break;
            }

            Logger = new TestLogger(new ConsoleLogger(this));

            if (Launcher != null)
            {
                LauncherOptions = new LauncherOptions {
                    Category = Options.Category, Features = Options.Features
                };
            }
        }
Exemplo n.º 2
0
        void ParseArguments(Assembly assembly, string[] args)
        {
            var dependencies = new List <string> ();

            ResultOutput = "TestResult.xml";

            var p = new OptionSet();

            p.Add("settings=", v => SettingsFile = v);
            p.Add("endpoint=", v => EndPoint     = GetEndPoint(v));
            p.Add("extra-launcher-args=", v => extraLauncherArgs = v);
            p.Add("gui=", v => GuiEndPoint               = GetEndPoint(v));
            p.Add("wait", v => Wait                      = true);
            p.Add("no-result", v => ResultOutput         = null);
            p.Add("result=", v => ResultOutput           = v);
            p.Add("log-level=", v => LogLevel            = int.Parse(v));
            p.Add("local-log-level=", v => LocalLogLevel = int.Parse(v));
            p.Add("dependency=", v => dependencies.Add(v));
            p.Add("optional-gui", v => optionalGui       = true);
            p.Add("set=", v => customSettings            = v);
            p.Add("category=", v => category             = v);
            p.Add("features=", v => features             = v);
            p.Add("debug", v => DebugMode                = true);
            p.Add("save-options", v => saveOptions       = true);
            p.Add("show-categories", v => showCategories = true);
            p.Add("show-features", v => showFeatures     = true);
            p.Add("show-config", v => showCategories     = showFeatures = true);
            p.Add("stdout=", v => stdout   = v);
            p.Add("stderr=", v => stderr   = v);
            p.Add("device=", v => device   = v);
            p.Add("sdkroot=", v => sdkroot = v);
            p.Add("wrench", v => Wrench    = true);
            var remaining = p.Parse(args);

            if (assembly != null)
            {
                command = Command.Local;

                if (remaining.Count > 0 && remaining[0].Equals("local"))
                {
                    remaining.RemoveAt(0);
                }
            }
            else
            {
                if (remaining.Count < 1)
                {
                    throw new InvalidOperationException("Missing argument.");
                }

                if (!Enum.TryParse <Command> (remaining[0], true, out command))
                {
                    throw new InvalidOperationException("Unknown command.");
                }
                remaining.RemoveAt(0);
            }

            arguments = remaining;

            dependencyAssemblies = new Assembly [dependencies.Count];
            for (int i = 0; i < dependencyAssemblies.Length; i++)
            {
                dependencyAssemblies [i] = Assembly.LoadFile(dependencies [i]);
            }

            if (command == Command.Listen)
            {
                if (EndPoint == null)
                {
                    EndPoint = GetLocalEndPoint();
                }
            }
            else if (command == Command.Local || command == Command.Listen)
            {
                if (assembly != null)
                {
                    if (arguments.Count != 0)
                    {
                        arguments.ForEach(a => Debug("Unexpected remaining argument: {0}", a));
                        throw new InvalidOperationException("Unexpected extra argument.");
                    }
                    Assembly = assembly;
                }
                else if (arguments.Count == 1)
                {
                    Assembly = Assembly.LoadFile(arguments [0]);
                }
                else if (EndPoint == null)
                {
                    throw new InvalidOperationException("Missing endpoint");
                }
            }
            else if (command == Command.Connect)
            {
                if (assembly != null)
                {
                    throw new InvalidOperationException();
                }
                if (arguments.Count == 1)
                {
                    EndPoint = GetEndPoint(arguments [0]);
                }
                else if (arguments.Count == 0)
                {
                    if (EndPoint == null)
                    {
                        throw new InvalidOperationException("Missing endpoint");
                    }
                }
                else
                {
                    arguments.ForEach(a => Debug("Unexpected remaining argument: {0}", a));
                    throw new InvalidOperationException("Unexpected extra argument.");
                }
            }
            else if (command == Command.Simulator || command == Command.Device || command == Command.TVOS)
            {
                if (arguments.Count < 1)
                {
                    throw new InvalidOperationException("Expected .app argument");
                }
                Launcher = new TouchLauncher(arguments [0], command, sdkroot, stdout, stderr, device, extraLauncherArgs);
                arguments.RemoveAt(0);

                if (EndPoint == null)
                {
                    EndPoint = GetLocalEndPoint();
                }
            }
            else if (command == Command.Mac)
            {
                if (arguments.Count < 1)
                {
                    throw new InvalidOperationException("Expected .app argument");
                }
                Launcher = new MacLauncher(arguments [0], stdout, stderr);
                arguments.RemoveAt(0);

                if (EndPoint == null)
                {
                    EndPoint = GetLocalEndPoint();
                }
            }
            else if (command == Command.Android || command == Command.Avd)
            {
                if (arguments.Count < 1)
                {
                    throw new InvalidOperationException("Expected activity argument");
                }

                Launcher = new DroidLauncher(arguments [0], stdout, stderr);
                arguments.RemoveAt(0);

                if (EndPoint == null)
                {
                    EndPoint = GetLocalEndPoint();
                }
            }
            else if (command == Command.Avd || command == Command.Emulator)
            {
                if (arguments.Count != 0)
                {
                    throw new InvalidOperationException("Unexpected extra arguments");
                }

                droidHelper = new DroidHelper(sdkroot);
            }
            else if (command == Command.Result)
            {
                if (arguments.Count != 1)
                {
                    throw new InvalidOperationException("Expected TestResult.xml argument");
                }
                ResultOutput = arguments[0];
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 3
0
        Program(Assembly assembly, string[] args)
        {
            Options = new ProgramOptions(assembly, args);

            switch (Options.Command)
            {
            case Command.Simulator:
            case Command.Device:
            case Command.TVOS:
                Launcher = new TouchLauncher(this);
                break;

            case Command.Mac:
                if (Options.StdOut != null)
                {
                    StdOut = new StreamWriter(Options.StdOut);
                }
                Launcher = new MacLauncher(this);
                break;

            case Command.Android:
                if (Options.StdOut != null)
                {
                    StdOut = new StreamWriter(Options.StdOut);
                }
                DroidHelper = new DroidHelper(this);
                Launcher    = new DroidLauncher(this);
                break;

            case Command.Avd:
            case Command.Emulator:
            case Command.Apk:
                DroidHelper = new DroidHelper(this);
                break;

            default:
                if (Options.StdOut != null)
                {
                    StdOut = new StreamWriter(Options.StdOut);
                }
                break;
            }

            if (StdOut != null)
            {
                SD.Debug.Listeners.Add(new SD.TextWriterTraceListener(StdOut));
            }

            Jenkins = Options.Jenkins;

            Logger = new TestLogger(new ConsoleLogger(this));

            if (Options.JenkinsHtml != null)
            {
                JenkinsHtml = new StreamWriter(Options.JenkinsHtml);
            }

            if (Launcher != null)
            {
                LauncherOptions = new LauncherOptions {
                    Category = Options.Category, Features = Options.Features
                };
            }
        }