public void InitializeShouldThrowErrorIfArgumentIsInValid(string arg) { var args = new string[] { arg }; var str = string.Format(CommandLineResources.MalformedRunSettingsKey); CommandLineException ex = Assert.ThrowsException <CommandLineException>(() => this.executor.Initialize(args)); Assert.AreEqual(str, ex.Message); }
public void InitializeShouldThrowErrorIfTestRunParameterNodeIsInValid(string arg) { var args = new string[] { arg }; var str = string.Format(CommandLineResources.InvalidTestRunParameterArgument, arg); CommandLineException ex = Assert.ThrowsException <CommandLineException>(() => this.executor.Initialize(args)); Assert.AreEqual(str, ex.Message); }
public void UnknownParameterExceptionTest() { string[] args = { "/attribute1=101", "/aa=102", "/attribute3=103", "/a4=104" }; try { (TestingClass commandLineSwitches, List <string> unparsedCommandLineElements)result = CommandLine.CommandLineParser <TestingClass> .Parse(args); } catch (AggregateException aex) { CommandLineException ex = aex.InnerExceptions[0] as CommandLineException; Assert.IsNotNull(ex, "unexpected exception type in AggregateException"); Assert.AreEqual("aa", ex.ParameterName); Assert.AreEqual("102", ex.ParameterValue); Assert.IsNull(ex.ParameterType); Assert.AreEqual("Exception parsing comand line parameter: name = aa, value = 102, reason = Unknown command line switch: aa", ex.Message); return; } Assert.Fail("Expected AggregateException not thrown"); }
public void BadParameterExceptionTest() { string[] args = { "/attribute1=101", "/a2=102", "/attribute3=103", "/a4=aaa" }; try { (TestingClass commandLineSwitches, List <string> unparsedCommandLineElements)result = CommandLine.CommandLineParser <TestingClass> .Parse(args); } catch (AggregateException aex) { CommandLineException ex = aex.InnerExceptions[0] as CommandLineException; Assert.IsNotNull(ex, "unexpected exception type in AggregateException"); Assert.AreEqual("a4", ex.ParameterName); Assert.AreEqual("aaa", ex.ParameterValue); Assert.AreEqual(typeof(int), ex.ParameterType); Assert.AreEqual("Exception parsing comand line parameter: name = a4, value = aaa, type = Int32 exception = Input string was not in a correct format.", ex.Message); return; } Assert.Fail("Expected AggregateException not thrown"); }
/// <summary> A private variation on <code>accept()</code> that also has an argument /// indicating that the process we are waiting for is an AIR application. If /// it is, then we can sometimes give slightly better error messages (see bug /// FB-7544). /// /// </summary> /// <param name="isAIRapp">if <code>true</code>, then the process we are waiting for /// is an AIR application. This is only used to give better error /// messages in the event that we can't establish a connection to /// that process. /// </param> private Session accept(IProgress waitReporter, bool isAIRapp) { // get timeout int timeout = getPreference(SessionManager.PREF_ACCEPT_TIMEOUT); int totalTimeout = timeout; int iterateOn = 100; PlayerSession session = null; try { m_processDead = false; m_serverSocket.Server.ReceiveTimeout = iterateOn; // Wait 100ms per iteration. We have to do that so that we can report how long // we have been waiting. System.Net.Sockets.TcpClient s = null; while (s == null && !m_processDead) { try { if (m_serverSocket.Pending()) { s = m_serverSocket.AcceptTcpClient(); } else { System.Threading.Thread.Sleep(iterateOn); timeout -= iterateOn; if (timeout < 0) throw new IOException(); } } catch (IOException ste) { timeout -= iterateOn; if (timeout < 0 || m_serverSocket == null || !m_serverSocket.Server.Connected) throw ste; // we reached the timeout, or someome called stopListening() } // Tell the progress monitor we've waited a little while longer, // so that the Eclipse progress bar can keep chugging along if (waitReporter != null) waitReporter.setProgress(totalTimeout - timeout, totalTimeout); } if (s == null && m_processDead) { IOException e = null; String detailMessage = LocalizationManager.getLocalizedTextString("processTerminatedWithoutDebuggerConnection"); //$NON-NLS-1$ if (m_processMessages != null) { String commandLineMessage = m_processMessages.ToString(); if (commandLineMessage.Length > 0) e = new CommandLineException(detailMessage, m_launchCommand, commandLineMessage, m_processExitValue); } if (e == null) { if (isAIRapp) { // For bug FB-7544: give the user a hint about what might have gone wrong. detailMessage += s_newline; detailMessage += LocalizationManager.getLocalizedTextString("maybeAlreadyRunning"); //$NON-NLS-1$ } e = new IOException(detailMessage); } throw e; } /* create a new session around this socket */ session = PlayerSession.createFromSocket(s); // transfer preferences session.Preferences = m_prefs; } catch (NullReferenceException) { throw new SocketException(); //$NON-NLS-1$ } finally { m_processMessages = null; m_launchCommand = null; } return session; }
/// <summary> A private variation on <code>accept()</code> that also has an argument /// indicating that the process we are waiting for is an AIR application. If /// it is, then we can sometimes give slightly better error messages (see bug /// FB-7544). /// /// </summary> /// <param name="isAIRapp">if <code>true</code>, then the process we are waiting for /// is an AIR application. This is only used to give better error /// messages in the event that we can't establish a connection to /// that process. /// </param> private Session accept(IProgress waitReporter, bool isAIRapp) { // get timeout int timeout = getPreference(SessionManager.PREF_ACCEPT_TIMEOUT); int totalTimeout = timeout; int iterateOn = 100; PlayerSession session = null; try { m_processDead = false; m_serverSocket.Server.ReceiveTimeout = iterateOn; // Wait 100ms per iteration. We have to do that so that we can report how long // we have been waiting. System.Net.Sockets.TcpClient s = null; while (s == null && !m_processDead) { try { if (m_serverSocket.Pending()) { s = m_serverSocket.AcceptTcpClient(); } else { System.Threading.Thread.Sleep(iterateOn); timeout -= iterateOn; if (timeout < 0) { throw new IOException(); } } } catch (IOException ste) { timeout -= iterateOn; if (timeout < 0 || m_serverSocket == null || !m_serverSocket.Server.Connected) { throw ste; // we reached the timeout, or someome called stopListening() } } // Tell the progress monitor we've waited a little while longer, // so that the Eclipse progress bar can keep chugging along if (waitReporter != null) { waitReporter.setProgress(totalTimeout - timeout, totalTimeout); } } if (s == null && m_processDead) { IOException e = null; String detailMessage = LocalizationManager.getLocalizedTextString("processTerminatedWithoutDebuggerConnection"); //$NON-NLS-1$ if (m_processMessages != null) { String commandLineMessage = m_processMessages.ToString(); if (commandLineMessage.Length > 0) { e = new CommandLineException(detailMessage, m_launchCommand, commandLineMessage, m_processExitValue); } } if (e == null) { if (isAIRapp) { // For bug FB-7544: give the user a hint about what might have gone wrong. detailMessage += s_newline; detailMessage += LocalizationManager.getLocalizedTextString("maybeAlreadyRunning"); //$NON-NLS-1$ } e = new IOException(detailMessage); } throw e; } /* create a new session around this socket */ session = PlayerSession.createFromSocket(s); // transfer preferences session.Preferences = m_prefs; } catch (NullReferenceException) { throw new SocketException(); //$NON-NLS-1$ } finally { m_processMessages = null; m_launchCommand = null; } return(session); }
private static void HandleArgumentsParsingError(CommandLineParser.CommandLineParser parser, CommandLineException ex) { Console.Error.WriteLine(ex.Message); parser?.ShowUsage(); }