Skip to content

Commit 122aaab

Browse files
authored
Merge pull request #80 from nunit/issue-79
Updates to AgentRunner
2 parents 8147203 + 35d5770 commit 122aaab

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

recipe/test-results.cake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public class ActualResult : TestResultSummary
5151
doc.Load(resultFile);
5252

5353
Xml = doc.DocumentElement;
54-
if (Xml.Name != "test-run")
55-
throw new Exception("The test-run element was not found.");
54+
if (Xml.Name != "test-run" && Xml.Name != "test-suite")
55+
throw new Exception("Top-level <test-run> or <test-suite> element not found.");
5656

5757
OverallResult = GetAttribute(Xml, "result");
5858
Total = IntAttribute(Xml, "total");
@@ -63,14 +63,10 @@ public class ActualResult : TestResultSummary
6363
Skipped = IntAttribute(Xml, "skipped");
6464

6565
var assemblies = new List<ActualAssemblyResult>();
66-
//var engineVersion = new Version(GetAttribute(Xml, "engine-version"));
6766

6867
foreach (XmlNode node in Xml.SelectNodes("//test-suite[@type='Assembly']"))
6968
assemblies.Add(new ActualAssemblyResult(node));
7069

71-
//foreach (XmlNode node in Xml.SelectNodes("//test-suite[@type='Assembly']"))
72-
// assemblies.Add(new ActualAssemblyResult(node, engineVersion));
73-
7470
Assemblies = assemblies.ToArray();
7571
}
7672

recipe/test-runners.cake

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public abstract class TestRunner
4646

4747
public IEnumerable<string> Output { get; protected set; }
4848

49+
protected int RunPackageTest(FilePath executablePath, string arguments = null, bool redirectOutput = false)
50+
{
51+
return RunPackageTest(executablePath, new ProcessSettings { Arguments = arguments, RedirectStandardOutput = redirectOutput });
52+
}
53+
4954
protected int RunUnitTest(FilePath executablePath, ProcessSettings processSettings)
5055
{
5156
if (executablePath == null)
@@ -266,29 +271,43 @@ public class NUnit4DotNetRunner : NUnitConsoleRunnerBase
266271
/////////////////////////////////////////////////////////////////////////////
267272

268273
/// <summary>
269-
/// Class that knows how to run an agent directly. (For future use)
274+
/// Class that knows how to find and run an agent directly.
270275
/// </summary>
271276
public class AgentRunner : TestRunner, IPackageTestRunner
272277
{
273-
private string _stdExecutable;
274-
private string _x86Executable;
278+
private DirectoryPath _agentBaseDirectory;
275279

276-
private FilePath _executablePath;
280+
public AgentRunner(DirectoryPath agentBaseDirectory)
281+
{
282+
if (agentBaseDirectory == null)
283+
throw new ArgumentNullException("Null argument", nameof(agentBaseDirectory));
277284

278-
public AgentRunner(string stdExecutable, string x86Executable = null)
279-
{
280-
_stdExecutable = stdExecutable;
281-
_x86Executable = x86Executable;
285+
_agentBaseDirectory = agentBaseDirectory;
282286
}
283287

284288
public int RunPackageTest(string arguments, bool redirectOutput = false)
285289
{
286-
_executablePath = arguments.Contains("--x86")
287-
? _x86Executable
288-
: _stdExecutable;
289-
290-
return base.RunPackageTest(
291-
_executablePath,
292-
new ProcessSettings { Arguments = arguments.Replace("--x86", string.Empty), RedirectStandardOutput = redirectOutput });
290+
if (!SIO.Directory.Exists(_agentBaseDirectory.ToString()))
291+
throw new DirectoryNotFoundException($"Directory not found: {_agentBaseDirectory}");
292+
293+
string runtime = arguments.Contains("net462") ? "net462" : "net8.0";
294+
bool isX86 = arguments.Contains("--x86");
295+
arguments = arguments.Replace("--x86", string.Empty);
296+
DirectoryPath agentDirectory = _agentBaseDirectory.Combine(runtime);
297+
298+
if (runtime == "net462")
299+
{
300+
string agentName = isX86 ? "nunit-agent-net462-x86.exe" : "nunit-agent-net462.exe";
301+
FilePath agentPath = agentDirectory.CombineWithFilePath(agentName);
302+
var settings = new ProcessSettings() { Arguments = arguments, RedirectStandardOutput = redirectOutput };
303+
return base.RunPackageTest(agentPath, settings);
304+
}
305+
else // must be "net8.0"
306+
{
307+
string agentName = "nunit-agent-net80.dll";
308+
FilePath agentPath = agentDirectory.CombineWithFilePath(agentName);
309+
var settings = new ProcessSettings() { Arguments = $"\"{agentPath}\" {arguments}", RedirectStandardOutput = redirectOutput };
310+
return base.RunPackageTest("dotnet", settings);
311+
}
293312
}
294313
}

0 commit comments

Comments
 (0)