示例#1
0
        /// <summary>
        /// Returns a string with data contained in the result.
        /// </summary>
        /// <returns>A string</returns>
        private static string FormatResult(ExternalExecutableResult result)
        {
            var returnValue = new StringBuilder();

            returnValue.AppendLine();
            returnValue.AppendLine("----------------");
            returnValue.AppendLine("Tool run result:");
            returnValue.AppendLine("----------------");
            returnValue.AppendLine("Command:");
            returnValue.AppendLine($"\"{result.StartInfo.FileName}\" {result.StartInfo.Arguments}");
            returnValue.AppendLine();
            returnValue.AppendLine("Standard Output:");
            foreach (var line in result.StandardOutput ?? new string[0])
            {
                returnValue.AppendLine(line);
            }
            returnValue.AppendLine("Standard Error:");
            foreach (var line in result.StandardError ?? new string[0])
            {
                returnValue.AppendLine(line);
            }
            returnValue.AppendLine("Exit Code:");
            returnValue.AppendLine(Convert.ToString(result.ExitCode));
            returnValue.AppendLine("----------------");

            return(returnValue.ToString());
        }
示例#2
0
        /// <summary>
        /// Checks that the result from a run matches the expected results
        /// </summary>
        /// <param name="result">A result from a run</param>
        /// <returns>A list of errors</returns>
        public virtual List <string> CheckResult(ExternalExecutableResult result)
        {
            List <string> errors = new List <string>();

            // Verify that the expected return code matched the actual return code
            if (null != this.ExpectedExitCode && this.ExpectedExitCode != result.ExitCode)
            {
                errors.Add(String.Format("Expected exit code {0} did not match actual exit code {1}", this.ExpectedExitCode, result.ExitCode));
            }

            var standardErrorString = string.Join(Environment.NewLine, result.StandardError);

            // Verify that the expected error string are in stderr
            if (null != this.ExpectedErrorStrings)
            {
                foreach (string expectedString in this.ExpectedErrorStrings)
                {
                    if (!standardErrorString.Contains(expectedString))
                    {
                        errors.Add(String.Format("The text '{0}' was not found in stderr", expectedString));
                    }
                }
            }

            var standardOutputString = string.Join(Environment.NewLine, result.StandardOutput);

            // Verify that the expected output string are in stdout
            if (null != this.ExpectedOutputStrings)
            {
                foreach (string expectedString in this.ExpectedOutputStrings)
                {
                    if (!standardOutputString.Contains(expectedString))
                    {
                        errors.Add(String.Format("The text '{0}' was not found in stdout", expectedString));
                    }
                }
            }

            // Verify that the expected regular expressions match stderr
            if (null != this.ExpectedOutputRegexs)
            {
                foreach (Regex expectedRegex in this.ExpectedOutputRegexs)
                {
                    if (!expectedRegex.IsMatch(standardOutputString))
                    {
                        errors.Add(String.Format("Regex {0} did not match stdout", expectedRegex.ToString()));
                    }
                }
            }

            // Verify that the expected regular expressions match stdout
            if (null != this.ExpectedErrorRegexs)
            {
                foreach (Regex expectedRegex in this.ExpectedErrorRegexs)
                {
                    if (!expectedRegex.IsMatch(standardErrorString))
                    {
                        errors.Add(String.Format("Regex {0} did not match stderr", expectedRegex.ToString()));
                    }
                }
            }

            return(errors);
        }