Skip to content

Instantly share code, notes, and snippets.

@julesx
Created June 21, 2018 15:11
Show Gist options
  • Save julesx/7a0cb167fba1e2d3483f2770f329b057 to your computer and use it in GitHub Desktop.
Save julesx/7a0cb167fba1e2d3483f2770f329b057 to your computer and use it in GitHub Desktop.
command line work
private static void RunSelectedTests(List<String> apexClasses)
{
using (var cmdProcess = InitCmdProcess())
{
using (StreamWriter cmdProcessWriter = cmdProcess.StandardInput)
{
var selectedTests = string.Join(",", apexClasses);
cmdProcessWriter.WriteLine("sfdx force:apex:test:run -n " + selectedTests);// + " -d \"c:\\my stuff\\logs\"");
}
String output;
while ((output = cmdProcess.StandardOutput.ReadLine()) != null)
{
if (output.Contains("retrieve test results"))
{
Regex regex = new Regex("([\"'])(?:(?=(\\\\?))\\2.)*?\\1");
Match match = regex.Match(output);
if (match.Success)
{
GetTestResults(match.Value.Trim('"'), apexClasses);
}
}
else
{
Console.Error.WriteLine(output);
}
}
}
}
private static Process InitCmdProcess()
{
var cmdProcess = new Process();
cmdProcess.StartInfo.FileName = "cmd.exe";
cmdProcess.StartInfo.RedirectStandardOutput = true;
cmdProcess.StartInfo.RedirectStandardInput = true;
cmdProcess.StartInfo.UseShellExecute = false;
cmdProcess.Start();
return cmdProcess;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment