public List<TestRunResults> Run(string arguments, string workingDirectory, string testLocation, Action<string> onLine) {
     var file = Path.GetTempFileName();
     if (File.Exists(file))
         File.Delete(file);
     var results = new List<TestRunResults>();
     var errors = new StringBuilder();
     var lastStatus = DateTime.Now;
     var proc = new Process();
     var procArguments = "--log-junit \"" + file + "\" --tap " + arguments;
     AutoTest.Core.DebugLog.Debug.WriteDebug("Running: phpunit " + procArguments);
     proc.Query(
         "phpunit",
         procArguments,
         false,
         workingDirectory,
         (error, line) => {
             if (error) {
                 errors.AppendLine(line);
                 proc.Kill();
                 return;
             }
             if (DateTime.Now.Subtract(lastStatus) > TimeSpan.FromMilliseconds(300)) {
                 onLine(line);
                 lastStatus = DateTime.Now;
             }
         });
     
     if (errors.Length != 0) {
         AutoTest.Core.DebugLog.Debug.WriteDebug("Parse error is: " + errors);
         results
             .Add(
                 new TestRunResults(
                     "PHP Parse error",
                     testLocation,
                     true,
                     TestRunner.PhpParseError,
                     new[] {
                         PhpUnitParseErrorParser.Parse(errors.ToString())
                     }));
     } else {
         results.Add(removeParseErrorsForLocation(testLocation));
     }
     AutoTest.Core.DebugLog.Debug.WriteDebug("Error length is " + errors.Length + " and file exists for file " + file + " is " + File.Exists(file).ToString());
     if (errors.Length == 0 && File.Exists(file)) {
         AutoTest.Core.DebugLog.Debug.WriteDebug("Prasing output for " + file);
         var testRunResults = JUnitXmlParser.Parse(File.ReadAllText(file), testLocation);
         var finalResults = removeDeletedTests(testRunResults);
         results.AddRange(finalResults);
     }
     return results;
 }
Beispiel #2
0
 private void execute(Process proc, string cmd, string arguments, Action<bool, string> onLineReceived)
 {
     Logger.Write("Executing {0} {1}", cmd, arguments);
     if (onLineReceived != null)
         proc.Query(cmd, arguments, false, Environment.CurrentDirectory, onLineReceived);
     else
         proc.Run(cmd, arguments, false, Environment.CurrentDirectory);
 }
Beispiel #3
0
        private void run(string arguments)
        {
            var proc = new Process();
            proc.Query(
                "oi",
                arguments,
                false,
                _directory,
                (error, line) => {
                        if (error) {
                            Logger.Write("Failed to run oi with " + arguments + " in " + _directory);
                            Logger.Write(line);
                            return;
                        }
                        Console.WriteLine(line);
                    });

            /*if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
                proc.StartInfo = new ProcessStartInfo("oi", arguments);
            else
            {
                proc.StartInfo =
                    new ProcessStartInfo(
                        "cmd.exe", "/c oi \"" +
                        arguments.Replace("\"", "^\"") + "\"");
            }
            Console.WriteLine("Running: " + proc.StartInfo.FileName + " " + proc.StartInfo.Arguments);
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.WorkingDirectory = _directory;
            proc.Start();
            var output = proc.StandardOutput.ReadToEnd();
            if (output.Length > Environment.NewLine.Length)
                output = output.Substring(0, output.Length - Environment.NewLine.Length);
            Console.WriteLine(output);*/
        }
Beispiel #4
0
        public void Execute(string[] arguments)
        {
            if (arguments.Length < 1)
                return;
            var scriptName = arguments[0];
            var script =
                Bootstrapper.GetDefinitionBuilder()
                    .Definitions
                    .FirstOrDefault(x => x.Name == scriptName &&
                                         (x.Type == DefinitionCacheItemType.Script ||
                                          x.Type == DefinitionCacheItemType.LanguageScript));
            if (script == null)
                return;

            var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var match1 = "codemodel raw-filesystem-change-filecreated \"" + script.Location + "\"";
            var match2 = "codemodel raw-filesystem-change-filechanged \"" + script.Location + "\"";
            Logger.Write("Looking for: " + match1);
            Logger.Write("Looking for: " + match2);
            var hash = 0;
            try {
                var proc = new Process();
                proc.Query(
                    Path.Combine(root, Path.Combine("EventListener", "OpenIDE.EventListener.exe")),
                    "",
                    false,
                    _token,
                    (error, s) => {
                        if (s == match1 || s == match2) {
                            var newHas = File.ReadAllText(script.Location).GetHashCode();
                            if (newHas != hash) {
                                hash = newHas;
                                _dispatch("Running command:");
                                runCommand(arguments);
                            }
                        }
                    }
                );
            } catch (Exception ex) {
                Logger.Write(ex);
            }
        }
 private void query(string cmd, string arguments, string filter, Action<string> onMatch)
 {
     if (filter != null) {
         _matcher = new Regex(
             "^" + Regex.Escape(filter)
                 .Replace( "\\*", ".*" )
                 .Replace( "\\?", "." ) + "$");
     }
     try {
         var proc = new Process();
         proc.Query(
             cmd,
             arguments,
             false,
             _path,
             (error, s) => {
                 if (error || filter == null || match(s))
                     onMatch(s);
             });
     } catch (Exception ex) {
         Console.WriteLine(ex.ToString());
     }
 }
        public void Execute(string[] arguments)
        {
            if (arguments.Length < 2)
                return;
            var scripts = new ReactiveScriptReader(
                _token,
                _pluginLocator,
                (p, m) => {},
                (m) => {})
                .Read();
            var script = scripts.FirstOrDefault(x => x.Name.Equals(arguments[0]));
            if (script == null)
                return;

            var root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var match1 = "'codemodel' 'raw-filesystem-change-filecreated' '" + script.File + "'";
            var match2 = "'codemodel' 'raw-filesystem-change-filechanged' '" + script.File + "'";
            Logger.Write("Looking for: " + match1);
            Logger.Write("Looking for: " + match2);
            var name = "rscript-" + Path.GetFileNameWithoutExtension(script.File);
            var hash = 0;
            try {
                using (var output = new OutputClient(_token, (publisher, msg) => { if (name == publisher) _dispatch(msg); }))
                {
                    output.Connect();
                    var proc = new Process();
                    proc.Query(
                        Path.Combine(root, Path.Combine("EventListener", "OpenIDE.EventListener.exe")),
                        "",
                        false,
                        _token,
                        (error, s) => {
                            if (s == match1 || s == match2) {
                                var newHas = File.ReadAllText(script.File).GetHashCode();
                                if (newHas != hash) {
                                    hash = newHas;
                                    Thread.Sleep(200);
                                    _dispatch("");
                                    _dispatch("Triggering reactive script:");
                                    _dispatch("event|"+arguments[1]);
                                }
                            }
                        }
                    );
                }
            } catch (Exception ex) {
                Logger.Write(ex);
            }
        }
Beispiel #7
0
 private string run(string arguments)
 {
     var proc = new Process();
     var sb = new StringBuilder();
     proc.Query(
         _file,
         arguments,
         false,
         Environment.CurrentDirectory,
         (error, s) => {
                 if (error) {
                     sb.AppendLine("error|" + s);
                     return;
                 }
                 sb.AppendLine(s);
             });
     var output = sb.ToString();
     if (output.Length > Environment.NewLine.Length)
         return output.Substring(0, output.Length - Environment.NewLine.Length);
     return output;
 }
Beispiel #8
0
        private void run(string arguments, Action<string> onLine,
						 IEnumerable<KeyValuePair<string,string>> replacements)
        {
            var cmd = _file;
            var finalReplacements = new List<KeyValuePair<string,string>>();
            finalReplacements.Add(new KeyValuePair<string,string>("{run-location}", "\"" + _workingDirectory + "\""));
            finalReplacements.AddRange(replacements);
            arguments = "{run-location} " + arguments;
            var proc = new Process();
            _writer = (msg) => {
                try {
                    Logger.Write("Writing to the process " + msg);
                    proc.Write(msg);
                } catch (Exception ex) {
                    Logger.Write(ex);
                }
            };
            var realArguments = arguments;
            proc
                .Query(
                    cmd,
                    arguments,
                    false,
                    _token,
                    (error, line) => {
                            if (error && !line.StartsWith("error|")) {
                                onLine("error|" + line);
                                Logger.Write(line);
                            } else
                                onLine(line);
                        },
                    finalReplacements.ToArray(),
                    (args) => realArguments = args);
            onLine(string.Format("event|builtin command ran \"{0}\" {1}", Name, realArguments));
            _writer = (msg) => {};
        }
Beispiel #9
0
        public void Execute(string[] arguments)
        {
            _verbose = arguments.Contains("-v");
            _showoutputs = arguments.Contains("-o");
            _showevents = arguments.Contains("-e");
            _printOnlyErrorsAndInconclusives = arguments.Contains("--only-errors");
            _logging = arguments.Contains("-l");
            var profiles = new ProfileLocator(_token);

            var testFiles = new List<string>();
            if (arguments.Length > 0 && File.Exists(arguments[0])) {
                testFiles.Add(arguments[0]);
            } else {
                testFiles
                    .AddRange(
                        getTests(profiles.GetLocalProfilePath("default")));
                testFiles
                    .AddRange(
                        getTests(profiles.GetGlobalProfilePath("default")));
                testFiles
                    .AddRange(
                        getTests(
                            Path.GetDirectoryName(
                                Assembly.GetExecutingAssembly().Location)));
            }

            foreach (var testFile in testFiles) {

                _testRunLocation = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks.ToString());
                Console.WriteLine("Testing: {0}", testFile);
                var eventListenerStarted = false;
                var systemStarted = false;
                var runCompleted = false;
                var eventListener = new Thread(() => {
                            var eventSocketClient = new EventStuff.EventClient(
                                (line) => {
                                            if (line == "codeengine started") {
                                                log("Code engine started");
                                                systemStarted = true;
                                            } if (line == "codeengine stopped") {
                                                log("Code engine stopped");
                                                runCompleted = true;
                                            }
                                            _events.Add(line);
                                        });
                            while (true) {
                                eventSocketClient.Connect(_testRunLocation);
                                eventListenerStarted = true;
                                if (!eventSocketClient.IsConnected) {
                                    Thread.Sleep(10);
                                    if (runCompleted || systemStarted)
                                        break;
                                    continue;
                                }
                                log("Event listener connected");
                                while (eventSocketClient.IsConnected)
                                    Thread.Sleep(10);
                                break;
                            }
                            eventListenerStarted = false;
                        });
                var isQuerying = false;
                var useEditor = false;
                var tests = new List<string>();
                Process proc = null;
                try {
                    Directory.CreateDirectory(_testRunLocation);
                    _events = new List<string>();
                    _outputs = new List<string>();
                    _asserts = new List<string>();

                    log("Initializing test location");
                    runCommand("init");
                    // Make sure we run tests in default profile is
                    // this by any chance overloaded in init command
                    runCommand("profile load default");
                    eventListener.Start();

                    new Thread(() => {
                            log("Starting test process");
                            var testProc = new Process();
                            try {
                                testProc
                                    .Query(
                                        testFile,
                                        _testRunLocation,
                                        false,
                                        Environment.CurrentDirectory,
                                        (error, line) => {
                                                if (line == "initialized" || line.StartsWith("initialized|")) {
                                                    log("Test file initialized");
                                                    proc = testProc;
                                                    var chunks = line.Split(new[] {'|'});
                                                    if (chunks.Length > 1 && chunks[1] == "editor") {
                                                        while (!eventListenerStarted)
                                                            Thread.Sleep(10);
                                                        log("Starting editor");
                                                        new Process().Run("oi", "editor test", false, _testRunLocation);
                                                        log("Editor launched");
                                                        useEditor = true;
                                                    } else {
                                                        log("System started");
                                                        systemStarted = true;
                                                    }
                                                    return;
                                                }
                                                if (line == "end-of-conversation") {
                                                    isQuerying = false;
                                                    return;
                                                }
                                                handleFeedback(proc, error, line);
                                            });
                            } catch (Exception ex) {
                                handleFeedback(testProc, true, "A fatal error occured while running " + testFile + Environment.NewLine + ex.Message);
                            }
                            isQuerying = false;
                            runCompleted = true;
                        }).Start();
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }

                log("Waiting for system to complete loading");
                while (!systemStarted)
                    Thread.Sleep(10);

                log("Getting tests");
                isQuerying = ask(proc, "get-tests");
                while (isQuerying)
                    Thread.Sleep(10);
                tests.AddRange(
                    _summary.ToString()
                    .Replace("\t", "")
                    .Split(
                        new[] { Environment.NewLine },
                        StringSplitOptions.RemoveEmptyEntries));

                foreach (var test in tests) {
                    if (_currentTest != null)
                        writeInconclusive();
                    log("Running test: " + test);
                    _outputs.Clear();
                    _events.Clear();
                    _asserts.Clear();
                    _currentTest = test;
                    _summary = new StringBuilder();
                    if (_verbose)
                        Console.Write(_currentTest + "...");
                    isQuerying = ask(proc, "test|" + _currentTest);
                    while (isQuerying)
                        Thread.Sleep(10);
                }

                if (useEditor) {
                    log("Shuting down editor");
                    new Process().Run("oi", "editor command kill", false, _testRunLocation);
                }

                log("Shuting down system");
                ask(proc, "shutdown");
                while (!runCompleted)
                    Thread.Sleep(10);

                log("Waiting for event listener to stop");
                while (eventListenerStarted)
                    Thread.Sleep(10);

                if (Directory.Exists(_testRunLocation))
                    Directory.Delete(_testRunLocation, true);

                if (_currentTest != null)
                    writeInconclusive();
                _currentTest = null;
                log("Test run finished");
                Console.WriteLine();
            }
        }
 private void run(string arguments)
 {
     var proc = new Process();
     proc.Query(
         "oi",
         arguments,
         false,
         _directory,
         (error, line) => {
                 if (error) {
                     Logger.Write("Failed to run oi with " + arguments + " in " + _directory);
                     Logger.Write(line);
                     return;
                 }
                 Console.WriteLine(line);
             });
 }
 private void startService()
 {
     _service = new Process();
     try
     {
         var responseDispatcher = new ResponseDispatcher(
             _keyPath,
             _dispatchErrors,
             "rscript-" + Name + " ",
             _outputDispatcher,
             internalDispatch,
             (response) => _service.Write(response)
         );
         _service.SetLogger((logMsg) => Logger.Write(logMsg));
         _service.Query(
             _file,
             "{global-profile} {local-profile}",
             false,
             _keyPath,
             (error, m) => {
                 if (m == null)
                     return;
                 Logger.Write("request doing " + m);
                 if (error) {
                     Logger.Write("rscript-" + Name + " produced an error:");
                     Logger.Write("rscript-" + Name + "-" + m);
                 }
                 responseDispatcher.Handle(error, m);
             },
             new[] {
                 new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                 new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
             });
         Logger.Write("Exiting service script");
     }
     catch (Exception ex)
     {
         internalDispatch("rscript-" + Name + " " + ex.ToString());
         Logger.Write(ex.ToString());
     }
 }
 private void runScript(string message)
 {
     if (_isFaulted)
         return;
     var originalMessage = message;
     message = "{event} {global-profile} {local-profile}";
     Logger.Write("Running: " + _file + " " + message);
     ThreadPool.QueueUserWorkItem((task) => {
         try
         {
             var process = new Process();
             var responseDispatcher = new ResponseDispatcher(
                 _keyPath,
                 _dispatchErrors,
                 "rscript-" + Name + " ",
                 _outputDispatcher,
                 internalDispatch,
                 (response) => process.Write(response)
             );
             process.SetLogger((logMsg) => Logger.Write(logMsg));
             var msg = task.ToString();
             process.Query(
                 _file,
                 msg,
                 false,
                 _keyPath,
                 (error, m) => {
                     if (m == null)
                         return;
                     Logger.Write("request doing " + m);
                     if (error) {
                         Logger.Write("rscript-" + Name + " produced an error:");
                         Logger.Write("rscript-" + Name + "-" + m);
                     }
                     responseDispatcher.Handle(error, m);
                 },
                 new[] {
                     new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
                     new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                     new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
                 });
             Logger.Write("RScript completed");
         }
         catch (Exception ex)
         {
             internalDispatch("rscript-" + Name + " " + ex.ToString());
             Logger.Write(ex.ToString());
         }
     }, message);
 }
Beispiel #13
0
 public void Run(string message)
 {
     if (Environment.OSVersion.Platform != PlatformID.Unix &&
         Environment.OSVersion.Platform != PlatformID.MacOSX)
     {
         message = message
                     .Replace(" ", "^ ")
                     .Replace("|", "^|")
                     .Replace("%", "^&")
                     .Replace("&", "^&")
                     .Replace("<", "^<")
                     .Replace(">", "^>");
     }
     var originalMessage = message;
     message = "{event} {global-profile} {local-profile}";
     Logger.Write("Running: " + _file + " " + message);
     ThreadPool.QueueUserWorkItem((task) => {
         try
         {
             var process = new Process();
             process.SetLogger((logMsg) => Logger.Write(logMsg));
             var msg = task.ToString();
             process.Query(
                 _file,
                 msg,
                 false,
                 _keyPath,
                 (error, m) => {
                     if (m == null)
                         return;
                     var cmdText = "command|";
                     var eventText = "event|";
                     if (error) {
                         Logger.Write("rscript-" + Name + " produced an error:");
                         Logger.Write("rscript-" + Name + "-" + m);
                     } else {
                         if (m.StartsWith(cmdText))
                             _dispatch(m.Substring(cmdText.Length, m.Length - cmdText.Length));
                         else if (m.StartsWith(eventText))
                             _dispatch(m.Substring(eventText.Length, m.Length - eventText.Length));
                         else
                             _dispatch("rscript-" + Name + " " + m);
                     }
                 },
                 new[] {
                     new KeyValuePair<string,string>("{event}", "\"" + originalMessage + "\""),
                     new KeyValuePair<string,string>("{global-profile}", "\"" + _globalProfileName + "\""),
                     new KeyValuePair<string,string>("{local-profile}", "\"" + _localProfileName + "\"")
                 });
         }
         catch (Exception ex)
         {
             Logger.Write(ex.ToString());
         }
     }, message);
 }
Beispiel #14
0
 private string run(string arguments)
 {
     var proc = new Process();
     var sb = new StringBuilder();
     foreach (var line in proc.Query(_file, arguments, false, Environment.CurrentDirectory))
         sb.AppendLine(line);
     var output = sb.ToString();
     if (output.Length > Environment.NewLine.Length)
         return output.Substring(0, output.Length - Environment.NewLine.Length);
     return output;
 }