[Harness] Fix XHarness unit tests (#8208)
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
This commit is contained in:
Родитель
b55b8e8e0b
Коммит
46a2d96c55
|
@ -20,8 +20,11 @@ namespace Xharness.Tests.BCLTestImporter.Tests {
|
|||
public void GenerateCodeNullProjectName ()
|
||||
{
|
||||
var tmp = Path.GetTempFileName ();
|
||||
Assert.ThrowsAsync <ArgumentNullException> (() =>
|
||||
BCLTestInfoPlistGenerator.GenerateCodeAsync (File.Create (tmp), null));
|
||||
File.WriteAllText (tmp, "Hello");
|
||||
using (var stream = new FileStream (tmp, FileMode.Open)) {
|
||||
Assert.ThrowsAsync<ArgumentNullException> (() => BCLTestInfoPlistGenerator.GenerateCodeAsync (stream, null));
|
||||
}
|
||||
|
||||
File.Delete (tmp);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Xharness.BCLTestImporter;
|
||||
using Xharness.BCLTestImporter.Templates;
|
||||
using Xharness.BCLTestImporter.Xamarin;
|
||||
|
||||
namespace Xharness.Tests.BCLTestImporter.Xamarin.Tests {
|
||||
|
@ -67,11 +65,11 @@ namespace Xharness.Tests.BCLTestImporter.Xamarin.Tests {
|
|||
Directory.CreateDirectory (ignoreFilesRootDir);
|
||||
// create a few ignore files
|
||||
foreach (var a in assemblies) {
|
||||
File.Create (Path.Combine (ignoreRootDir, $"iOS-{a}.ignore"));
|
||||
File.Create (Path.Combine (ignoreRootDir, $"macOSFull-{a}.ignore"));
|
||||
File.Create (Path.Combine (ignoreRootDir, $"macOS-{a}.ignore"));
|
||||
File.Create (Path.Combine (ignoreRootDir, $"tvOS-{a}.ignore"));
|
||||
File.Create (Path.Combine (ignoreRootDir, $"watchOS-{a}.ignore"));
|
||||
File.WriteAllText (Path.Combine (ignoreRootDir, $"iOS-{a}.ignore"), string.Empty);
|
||||
File.WriteAllText (Path.Combine (ignoreRootDir, $"macOSFull-{a}.ignore"), string.Empty);
|
||||
File.WriteAllText (Path.Combine (ignoreRootDir, $"macOS-{a}.ignore"), string.Empty);
|
||||
File.WriteAllText (Path.Combine (ignoreRootDir, $"tvOS-{a}.ignore"), string.Empty);
|
||||
File.WriteAllText (Path.Combine (ignoreRootDir, $"watchOS-{a}.ignore"), string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,7 +80,7 @@ namespace Xharness.Tests.BCLTestImporter.Xamarin.Tests {
|
|||
Directory.CreateDirectory (traitsRootDir);
|
||||
// create a few ignore files
|
||||
foreach (var t in traitsFiles)
|
||||
File.Create (Path.Combine (traitsRootDir, t));
|
||||
File.WriteAllText (Path.Combine (traitsRootDir, t), string.Empty);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
|
|
@ -4,7 +4,6 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Xharness.Execution;
|
||||
using Xharness.Logging;
|
||||
|
@ -21,7 +20,6 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
string stderrLogPath;
|
||||
string stdoutMessage;
|
||||
string stderrMessage;
|
||||
Mock<ILogs> logs;
|
||||
ILog executionLog;
|
||||
ILog stdoutLog;
|
||||
ILog stderrLog;
|
||||
|
@ -38,7 +36,6 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
stdoutLogPath = Path.GetTempFileName ();
|
||||
stdoutMessage = "Hola mundo!!!";
|
||||
stderrMessage = "Adios mundo cruel";
|
||||
logs = new Mock<ILogs> ();
|
||||
executionLog = new LogFile ("my execution log", logPath);
|
||||
stdoutLog = new LogFile ("my stdout log", stdoutLogPath);
|
||||
stderrLog = new LogFile ("my stderr log", stderrLogPath);
|
||||
|
@ -60,6 +57,7 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
testProcess?.Dispose ();
|
||||
testProcess = null;
|
||||
manager = null;
|
||||
|
||||
if (File.Exists (logPath))
|
||||
File.Delete (logPath);
|
||||
if (File.Exists (stderrLogPath))
|
||||
|
@ -73,6 +71,8 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
bool stdoutFound = false;
|
||||
bool stderrFound = false;
|
||||
|
||||
executionLog?.Dispose ();
|
||||
|
||||
using (var reader = new StreamReader (logPath)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine ()) != null) {
|
||||
|
@ -91,12 +91,13 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
[TestCase (0, 60, false, true, Description = "Timeout" )] // 0, long timeout, failure, timeout
|
||||
public async Task ExecuteCommandAsyncTest (int resultCode, int timeoutCount, bool success, bool timeout)
|
||||
{
|
||||
var args = new List<string> ();
|
||||
args.Add (dummyProcess);
|
||||
args.Add ($"--exit-code={resultCode}");
|
||||
args.Add ($"--timeout={timeoutCount}");
|
||||
args.Add ($"--stdout=\"{stdoutMessage}\"");
|
||||
args.Add ($"--stderr=\"{stderrMessage}\"");
|
||||
var args = new List<string> {
|
||||
dummyProcess,
|
||||
$"--exit-code={resultCode}",
|
||||
$"--timeout={timeoutCount}",
|
||||
$"--stdout=\"{stdoutMessage}\"",
|
||||
$"--stderr=\"{stderrMessage}\""
|
||||
};
|
||||
var result = await manager.ExecuteCommandAsync ("mono", args, executionLog, new TimeSpan (0, 0, 5));
|
||||
if (!timeout)
|
||||
Assert.AreEqual (resultCode, result.ExitCode, "exit code");
|
||||
|
@ -155,6 +156,9 @@ namespace Xharness.Tests.Execution.Tests {
|
|||
bool stdoutFound = false;
|
||||
bool stderrFound = false;
|
||||
|
||||
stdoutLog?.Dispose ();
|
||||
stderrLog?.Dispose ();
|
||||
|
||||
using (var reader = new StreamReader (stdoutLogPath)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine ()) != null) {
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault();
|
||||
Assert.IsNotNull (sdkRootArg, "sdk arg missing");
|
||||
AssertArgumentValue (sdkRootArg, sdkPath, "sdk arg wrong");
|
||||
AssertArgumentValue (sdkRootArg, $"--sdkroot {sdkPath}", "sdk arg wrong");
|
||||
|
||||
MlaunchArgument listDevArg = passedArguments.Where (a => a is ListDevicesArgument).FirstOrDefault();
|
||||
Assert.IsNotNull (listDevArg, "list devices arg missing");
|
||||
|
@ -99,7 +99,7 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
|
||||
// we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :)
|
||||
var tempPath = args.Where (a => a is ListDevicesArgument).First ().AsCommandLineArgument ();
|
||||
tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1);
|
||||
tempPath = tempPath.Substring (tempPath.IndexOf('=') + 1).Replace ("\"", string.Empty);
|
||||
|
||||
var name = GetType ().Assembly.GetManifestResourceNames ().Where (a => a.EndsWith ("devices.xml", StringComparison.Ordinal)).FirstOrDefault ();
|
||||
using (var outputStream = new StreamWriter (tempPath))
|
||||
|
@ -119,7 +119,7 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault();
|
||||
Assert.IsNotNull (sdkRootArg, "sdk arg missing");
|
||||
AssertArgumentValue (sdkRootArg, sdkPath, "sdk arg wrong");
|
||||
AssertArgumentValue (sdkRootArg, $"--sdkroot {sdkPath}", "sdk arg wrong");
|
||||
|
||||
MlaunchArgument listDevArg = passedArguments.Where (a => a is ListDevicesArgument).FirstOrDefault();
|
||||
Assert.IsNotNull (listDevArg, "list devices arg missing");
|
||||
|
|
|
@ -7,7 +7,6 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Xamarin;
|
||||
using Xharness.Execution;
|
||||
using Xharness.Execution.Mlaunch;
|
||||
using Xharness.Hardware;
|
||||
|
@ -71,14 +70,14 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
});
|
||||
|
||||
// validate the execution of mlaunch
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault();
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (sdkRootArg, "sdk arg missing");
|
||||
AssertArgumentValue (sdkRootArg, sdkPath, "sdk arg wrong");
|
||||
AssertArgumentValue (sdkRootArg, $"--sdkroot {sdkPath}", "sdk arg wrong");
|
||||
|
||||
MlaunchArgument listSimArg = passedArguments.Where (a => a is ListSimulatorsArgument).FirstOrDefault();
|
||||
MlaunchArgument listSimArg = passedArguments.Where (a => a is ListSimulatorsArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (listSimArg, "list devices arg missing");
|
||||
|
||||
MlaunchArgument outputFormatArg = passedArguments.Where (a => a is XmlOutputFormatArgument).FirstOrDefault();
|
||||
|
||||
MlaunchArgument outputFormatArg = passedArguments.Where (a => a is XmlOutputFormatArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (outputFormatArg, "output format arg missing");
|
||||
}
|
||||
|
||||
|
@ -110,28 +109,28 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
|
||||
// we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :)
|
||||
var tempPath = args.Where (a => a is ListSimulatorsArgument).First ().AsCommandLineArgument ();
|
||||
tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1);
|
||||
tempPath = tempPath.Substring (tempPath.IndexOf ('=') + 1).Replace ("\"", string.Empty);
|
||||
|
||||
CopySampleData (tempPath);
|
||||
return Task.FromResult (new ProcessExecutionResult { ExitCode = 0, TimedOut = false });
|
||||
});
|
||||
|
||||
|
||||
await simulators.LoadAsync (executionLog.Object);
|
||||
|
||||
// validate the execution of mlaunch
|
||||
Assert.AreEqual (mlaunchPath, processPath, "process path");
|
||||
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault();
|
||||
MlaunchArgument sdkRootArg = passedArguments.Where (a => a is SdkRootArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (sdkRootArg, "sdk arg missing");
|
||||
AssertArgumentValue (sdkRootArg, sdkPath, "sdk arg wrong");
|
||||
AssertArgumentValue (sdkRootArg, $"--sdkroot {sdkPath}", "sdk arg wrong");
|
||||
|
||||
MlaunchArgument listSimArg = passedArguments.Where (a => a is ListSimulatorsArgument).FirstOrDefault();
|
||||
MlaunchArgument listSimArg = passedArguments.Where (a => a is ListSimulatorsArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (listSimArg, "list devices arg missing");
|
||||
|
||||
MlaunchArgument outputFormatArg = passedArguments.Where (a => a is XmlOutputFormatArgument).FirstOrDefault();
|
||||
|
||||
MlaunchArgument outputFormatArg = passedArguments.Where (a => a is XmlOutputFormatArgument).FirstOrDefault ();
|
||||
Assert.IsNotNull (outputFormatArg, "output format arg missing");
|
||||
|
||||
Assert.AreEqual (75, simulators.AvailableDevices.Count());
|
||||
Assert.AreEqual (75, simulators.AvailableDevices.Count ());
|
||||
}
|
||||
|
||||
[TestCase (TestTarget.Simulator_iOS64, 1)]
|
||||
|
@ -147,7 +146,7 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
harness.Setup (h => h.MlaunchPath).Returns (mlaunchPath);
|
||||
harness.Setup (h => h.XcodeRoot).Returns (sdkPath);
|
||||
harness
|
||||
.Setup (h => h.ExecuteXcodeCommandAsync ("simctl", It.Is<string []> (args => args[0] == "create"), executionLog.Object, TimeSpan.FromMinutes (1)))
|
||||
.Setup (h => h.ExecuteXcodeCommandAsync ("simctl", It.Is<string []> (args => args [0] == "create"), executionLog.Object, TimeSpan.FromMinutes (1)))
|
||||
.ReturnsAsync (new ProcessExecutionResult () { ExitCode = 0 });
|
||||
|
||||
// moq It.Is is not working as nicelly as we would like it, we capture data and use asserts
|
||||
|
@ -159,12 +158,12 @@ namespace Xharness.Tests.Hardware.Tests {
|
|||
|
||||
// we get the temp file that was passed as the args, and write our sample xml, which will be parsed to get the devices :)
|
||||
var tempPath = args.Where (a => a is ListSimulatorsArgument).First ().AsCommandLineArgument ();
|
||||
tempPath = tempPath.Substring(tempPath.IndexOf('=') + 1);
|
||||
tempPath = tempPath.Substring (tempPath.IndexOf ('=') + 1).Replace ("\"", string.Empty);
|
||||
|
||||
CopySampleData (tempPath);
|
||||
return Task.FromResult (new ProcessExecutionResult { ExitCode = 0, TimedOut = false });
|
||||
});
|
||||
|
||||
|
||||
await simulators.LoadAsync (executionLog.Object);
|
||||
var sims = await simulators.FindAsync (target, executionLog.Object, false, false);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче