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(); } }
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(); } }