Skip to content

Commit

Permalink
Merge pull request #12 from OskiKervinen-MF/topic/tempfile-locations
Browse files Browse the repository at this point in the history
Fix tempfile locations
  • Loading branch information
xkbeyer authored Jun 7, 2018
2 parents 8dda462 + c1b78f0 commit fa87b5e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
13 changes: 7 additions & 6 deletions TestAdapter/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace CatchTestAdapter
/// <summary>
/// Runs external processes.
/// </summary>
class ProcessRunner
public class ProcessRunner
{
/// <summary>
/// Execute a plain external process.
/// </summary>
/// <param name="cmd">Path to executable.</param>
/// <param name="args">Command line arguments.</param>
/// <returns></returns>
public static IList<string> RunProcess(string cmd, string args )
public static IList<string> RunProcess(string cmd, string args, string workingDirectory )
{
// Start a new process.
var processStartInfo = new ProcessStartInfo( cmd, args )
Expand All @@ -27,7 +27,7 @@ public static IList<string> RunProcess(string cmd, string args )
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = @"."
WorkingDirectory = workingDirectory
};

using ( Process process = Process.Start( processStartInfo ) )
Expand All @@ -43,7 +43,7 @@ public static IList<string> RunProcess(string cmd, string args )
/// <param name="cmd">The executable.</param>
/// <param name="args">Command-line parameters.</param>
/// <returns></returns>
public static IList<string> RunDebugProcess( IFrameworkHandle frameworkHandle, string cmd, string args )
public static IList<string> RunDebugProcess( IFrameworkHandle frameworkHandle, string cmd, string args, string workingDirectory )
{
// We cannot reliably capture the output of a process launched by the framework.
// We store the output in a temp file instead.
Expand All @@ -53,7 +53,7 @@ public static IList<string> RunDebugProcess( IFrameworkHandle frameworkHandle, s

// Tell the framework to run the process in a debugger.
int pid = frameworkHandle.LaunchProcessWithDebuggerAttached(
cmd, System.Environment.CurrentDirectory,
cmd, workingDirectory,
argsWithOutFile, new Dictionary<string, string>() );

// Wait for exit.
Expand All @@ -63,7 +63,8 @@ public static IList<string> RunDebugProcess( IFrameworkHandle frameworkHandle, s
}

// Get the output.
var outputLines = new List<string>( System.IO.File.ReadAllLines( outputFile ) );
var outputLines = new List<string>( System.IO.File.ReadAllLines( workingDirectory +
System.IO.Path.DirectorySeparatorChar + outputFile ) );
System.IO.File.Delete( outputFile );

return outputLines;
Expand Down
6 changes: 5 additions & 1 deletion TestAdapter/TestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove
public static IList<TestCase> CreateTestCases( string exeName )
{
var testCases = new List<TestCase>();
var output = ProcessRunner.RunProcess(exeName, "--list-tests --verbosity high");

// Use the directory of the executable as the working directory.
string workingDirectory = System.IO.Path.GetDirectoryName( exeName );

var output = ProcessRunner.RunProcess(exeName, "--list-tests --verbosity high", workingDirectory);

foreach (var test in ParseListing( exeName, output ) )
{
Expand Down
13 changes: 10 additions & 3 deletions TestAdapter/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,16 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
// Get a list of all test case names
var listOfTestCases = tests.Aggregate("", (acc, test) => acc + test.DisplayName + "\n");

// Use the directory of the executable as the working directory.
string workingDirectory = System.IO.Path.GetDirectoryName( CatchExe );
if ( workingDirectory == "" )
workingDirectory = ".";

// Write them to the input file for Catch runner
string caseFile = "test.cases";
System.IO.File.WriteAllText(caseFile, listOfTestCases);
System.IO.File.WriteAllText(
workingDirectory + System.IO.Path.DirectorySeparatorChar + caseFile,
listOfTestCases);
string originalDirectory = Directory.GetCurrentDirectory();

// Execute the tests
Expand All @@ -144,11 +151,11 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
string arguments = "-r xml --durations yes --input-file=" + caseFile;
if ( runContext.IsBeingDebugged )
{
output_text = ProcessRunner.RunDebugProcess( frameworkHandle, CatchExe, arguments );
output_text = ProcessRunner.RunDebugProcess( frameworkHandle, CatchExe, arguments, workingDirectory );
}
else
{
output_text = ProcessRunner.RunProcess( CatchExe, arguments );
output_text = ProcessRunner.RunProcess( CatchExe, arguments, workingDirectory );
}

timer.Stop();
Expand Down
3 changes: 2 additions & 1 deletion TestAdapterTest/Mocks/MockFrameworkHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public struct TestMessage {

public int LaunchProcessWithDebuggerAttached( string filePath, string workingDirectory, string arguments, IDictionary<string, string> environmentVariables )
{
throw new NotImplementedException();
CatchTestAdapter.ProcessRunner.RunProcess( filePath, arguments, workingDirectory );
return 0;
}

public void RecordAttachments( IList<AttachmentSet> attachmentSets )
Expand Down

0 comments on commit fa87b5e

Please sign in to comment.