/// <summary> /// Executes the provided command line as an external process. /// </summary> /// <param name="commandLine">The process command line</param> /// <returns>true if the process terminated successfully (exit code = 0); false otherwise.</returns> private static bool ExecuteCommand(CommandLine commandLine) { ProcessStartInfo info = new ProcessStartInfo { CreateNoWindow = false, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = Path.GetTempPath(), FileName = commandLine.FileName, Arguments = commandLine.Arguments, RedirectStandardError = false, RedirectStandardInput = false }; Process process = Process.Start(ProcessStartInfoEx.StartThroughCmdShell(info)); if (process != null) { process.WaitForExit(); return (process.ExitCode == 0); } return false; }
/// <summary> /// Executes the discovery command as specified in the configuration for the requested test source. /// </summary> /// <param name="source">The test source module</param> /// <returns>The test framework describing all tests contained within the test source or null if one cannot be provided.</returns> private TestFramework ExecuteExternalDiscoveryCommand(string source) { // Use a temporary file to host the result of the external discovery process string path = Path.Combine(Path.GetDirectoryName(source), Path.GetFileName(source) + ListFileSuffix); // Perform cleanup to avoid inconsistent listing if (File.Exists(path)) { File.Delete(path); } CommandEvaluator evaluator = new CommandEvaluator(); evaluator.SetVariable("source", source); evaluator.SetVariable("out", path); // Evaluate the discovery command CommandLine commandLine = new CommandLine { FileName = evaluator.Evaluate(this.Settings.DiscoveryCommandLine.FileName).Result, Arguments = evaluator.Evaluate(this.Settings.DiscoveryCommandLine.Arguments).Result }; // Execute the discovery command via an external process if (ExecuteCommand(commandLine)) { // Parse the generate TestFramework from the temporary file return ParseTestFramework(path); } return null; }