Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tests/common/Touch.Unit/Touch.Client/Runner/HttpTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace MonoTouch.NUnit {
class HttpTextWriter : TextWriter {
public string HostName;
public string? HostName;
public int Port;

TaskCompletionSource<bool> finished = new TaskCompletionSource<bool> ();
Expand Down Expand Up @@ -52,7 +52,7 @@ Task<bool> SendData (NSUrl url, string uploadData)
var tcs = new TaskCompletionSource<bool> ();
var request = new NSMutableUrlRequest (url);
request.HttpMethod = "POST";
var rv = NSUrlSession.SharedSession.CreateUploadTask (request, NSData.FromString (uploadData), (NSData data, NSUrlResponse response, NSError error) => {
var rv = NSUrlSession.SharedSession.CreateUploadTask (request, NSData.FromString (uploadData), (NSData? data, NSUrlResponse? response, NSError? error) => {
if (error is not null) {
Console.WriteLine ("Failed to send data to {0}: {1}", url.AbsoluteString, error);
tcs.SetResult (false);
Expand All @@ -67,7 +67,12 @@ Task<bool> SendData (NSUrl url, string uploadData)

async Task SendData (string action, string uploadData)
{
if (string.IsNullOrEmpty (HostName))
throw new InvalidOperationException ("No host name specified.");

var url = NSUrl.FromString ("http://" + HostName + ":" + Port + "/" + action);
if (url is null)
throw new InvalidOperationException ("Failed to create the reporting url.");

int attempts_left = 10;
while (!await SendData (url, uploadData)) {
Expand Down Expand Up @@ -105,13 +110,14 @@ public override void Write (char value)
log.Append (value);
}

public override void Write (char [] buffer)
public override void Write (char []? buffer)
{
Console.Out.Write (buffer);
log.Append (buffer);
if (buffer is not null)
log.Append (buffer);
}

public override void WriteLine (string value)
public override void WriteLine (string? value)
{
Console.Out.WriteLine (value);
log.AppendLine (value);
Expand Down
2 changes: 1 addition & 1 deletion tests/common/Touch.Unit/Touch.Client/Runner/MacRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static async Task<bool> RunTestsAsync (TouchOptions options, Assembly [] assembl

await runner.RunAsync ();

return !runner.Result.IsFailure ();
return runner.Result is not null && !runner.Result.IsFailure ();
}

protected override void WriteDeviceInformation (TextWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public class NUnitOutputTextWriter : TextWriter {
StringBuilder extra_data = new StringBuilder ();
XmlMode mode;

public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter baseWriter, OutputWriter xmlWriter)
public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter? baseWriter, OutputWriter? xmlWriter)
: this (runner, baseWriter, xmlWriter, XmlMode.Default)
{
}

public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter baseWriter, OutputWriter xmlWriter, XmlMode xmlMode)
public NUnitOutputTextWriter (BaseTouchRunner runner, TextWriter? baseWriter, OutputWriter? xmlWriter, XmlMode xmlMode)
{
Runner = runner;
BaseWriter = baseWriter ?? Console.Out;
Expand All @@ -60,7 +60,7 @@ public override Encoding Encoding {

public BaseTouchRunner Runner { get; private set; }

public OutputWriter XmlOutputWriter { get; private set; }
public OutputWriter? XmlOutputWriter { get; private set; }

public override void Write (char value)
{
Expand All @@ -70,7 +70,7 @@ public override void Write (char value)
extra_data.Append (value);
}

public override void Write (string value)
public override void Write (string? value)
{
if (real_time_reporting)
BaseWriter.Write (value);
Expand All @@ -81,14 +81,16 @@ public override void Write (string value)
public override void Close ()
{
if (XmlOutputWriter is not null) {
var result = Runner.Result;
// now we want the XML report to write
real_time_reporting = true;
// write to a temporary string, because NUnit2XmlOutputWriter.WriteResultFile closes the stream,
// and we need to write more things to it.
var wrapped = mode == XmlMode.Wrapped;

if (!wrapped) {
XmlOutputWriter.WriteResultFile (Runner.Result, BaseWriter);
if (result is not null)
XmlOutputWriter.WriteResultFile (result, BaseWriter);
if (extra_data.Length > 0) {
BaseWriter.Write ("<!--");
extra_data.Replace ("--", "- - ");
Expand All @@ -100,7 +102,8 @@ public override void Close ()
BaseWriter.WriteLine ("<NUnitOutput>");

using (var textWriter = new StringWriter ()) {
XmlOutputWriter.WriteResultFile (Runner.Result, textWriter);
if (result is not null)
XmlOutputWriter.WriteResultFile (result, textWriter);
var str = textWriter.ToString ();
// Remove any xml declarations, since we're embedding this inside a different xml document.
if (str.StartsWith ("<?xml", StringComparison.Ordinal)) {
Expand Down
10 changes: 5 additions & 5 deletions tests/common/Touch.Unit/Touch.Client/Runner/TcpTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MonoTouch.NUnit {
public class TcpTextWriter : TextWriter {

private TcpClient client;
TcpListener server;
TcpListener? server;
private StreamWriter writer;

public TcpTextWriter (string hostName, int port, bool isTunnel = false)
Expand Down Expand Up @@ -50,7 +50,7 @@ public TcpTextWriter (string hostName, int port, bool isTunnel = false)
break;
}
} else {
client = new TcpClient (HostName, port);
client = new TcpClient (hostName, port);
}
writer = new StreamWriter (client.GetStream ());
} catch {
Expand All @@ -61,7 +61,7 @@ public TcpTextWriter (string hostName, int port, bool isTunnel = false)
}
}

public string HostName { get; private set; }
public string? HostName { get; private set; }

public int Port { get; private set; }

Expand Down Expand Up @@ -96,7 +96,7 @@ public override void Write (char value)
writer.Write (value);
}

public override void Write (char [] buffer)
public override void Write (char []? buffer)
{
writer.Write (buffer);
}
Expand All @@ -106,7 +106,7 @@ public override void Write (char [] buffer, int index, int count)
writer.Write (buffer, index, count);
}

public override void Write (string value)
public override void Write (string? value)
{
writer.Write (value);
}
Expand Down
20 changes: 12 additions & 8 deletions tests/common/Touch.Unit/Touch.Client/Runner/TestCaseElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ public TestCaseElement (TestMethod testCase, TouchRunner runner)
#if NUNITLITE_NUGET
Run ();
#else
var suite = (testCase.Parent as TestSuite);
var context = TestExecutionContext.CurrentContext;
context.TestObject = Reflect.Construct (testCase.Method.ReflectedType, null);
if (testCase.Parent is TestSuite suite) {
var context = TestExecutionContext.CurrentContext;
context.TestObject = Reflect.Construct (testCase.Method.ReflectedType, null);

suite.GetOneTimeSetUpCommand ().Execute (context);
Run ();
suite.GetOneTimeTearDownCommand ().Execute (context);
suite.GetOneTimeSetUpCommand ().Execute (context);
Run ();
suite.GetOneTimeTearDownCommand ().Execute (context);
} else {
Run ();
}
#endif

Runner.CloseWriter ();
Expand All @@ -66,7 +69,7 @@ public TestCaseElement (TestMethod testCase, TouchRunner runner)
}

public TestMethod TestCase {
get { return Test as TestMethod; }
get { return (TestMethod) Test; }
}

public void Run ()
Expand Down Expand Up @@ -108,7 +111,8 @@ public override void TestFinished ()
// we still need to update our current element
if (GetContainerTableView () is not null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
if (root is not null)
root.Reload (this, UITableViewRowAnimation.Fade);
}
tapped = false;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/common/Touch.Unit/Touch.Client/Runner/TestElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class TestElement : StyledMultilineElement {
static internal UIColor Orange = UIDevice.CurrentDevice.CheckSystemVersion (13, 0) ? UIColor.SystemOrange : UIColor.Orange;
static internal UIColor Red = UIDevice.CurrentDevice.CheckSystemVersion (13, 0) ? UIColor.SystemRed : UIColor.Red;

private TestResult result;
private TestResult? result;

public TestElement (ITest test, TouchRunner runner)
: base ("?", "?", UITableViewCellStyle.Subtitle)
Expand All @@ -58,7 +58,13 @@ public TestElement (ITest test, TouchRunner runner)
protected TouchRunner Runner { get; private set; }

public TestResult Result {
get { return result ?? new TestCaseResult (Test as TestMethod); }
get {
if (result is not null)
return result;
if (Test is TestMethod testMethod)
return new TestCaseResult (testMethod);
return new TestSuiteResult ((TestSuite) Test);
}
set { result = value; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public TestSuiteElement (TestSuite test, TouchRunner runner)
DetailColor = Orange;
var skip = test.Properties ["_SKIPREASON"];
if (skip.Count > 0)
Value = skip [0].ToString ();
Value = skip [0]?.ToString () ?? "No test was found inside this suite";
else
Value = "No test was found inside this suite";
}
}

public TestSuite Suite {
get { return Test as TestSuite; }
get { return (TestSuite) Test; }
}

public void Run ()
Expand Down Expand Up @@ -91,7 +91,8 @@ public override void TestFinished ()

if (GetContainerTableView () is not null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
if (root is not null)
root.Reload (this, UITableViewRowAnimation.Fade);
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions tests/common/Touch.Unit/Touch.Client/Runner/TouchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum XmlVersion {

public class TouchOptions {

static TouchOptions current;
static TouchOptions? current;
static public TouchOptions Current {
get {
if (current is null)
Expand All @@ -68,7 +68,9 @@ public TouchOptions (IList<string> arguments)
HostName = defaults.StringForKey ("network.host.name");
HostPort = (int) defaults.IntForKey ("network.host.port");
UseTcpTunnel = defaults.BoolForKey ("execution.usetcptunnel");
Transport = defaults.StringForKey ("network.transport");
var transport = defaults.StringForKey ("network.transport");
if (!string.IsNullOrEmpty (transport))
Transport = transport;
SortNames = defaults.BoolForKey ("display.sort");
LogFile = defaults.StringForKey ("log.file");
TestName = defaults.StringForKey ("test.name");
Expand All @@ -89,8 +91,9 @@ public TouchOptions (IList<string> arguments)
HostPort = i;
if (bool.TryParse (Environment.GetEnvironmentVariable ("NUNIT_SORTNAMES"), out b))
SortNames = b;
if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("NUNIT_TRANSPORT")))
Transport = Environment.GetEnvironmentVariable ("NUNIT_TRANSPORT");
var envTransport = Environment.GetEnvironmentVariable ("NUNIT_TRANSPORT");
if (!string.IsNullOrEmpty (envTransport))
Transport = envTransport;
if (bool.TryParse (Environment.GetEnvironmentVariable ("NUNIT_ENABLE_XML_OUTPUT"), out b))
EnableXml = b;
var xml_mode = Environment.GetEnvironmentVariable ("NUNIT_ENABLE_XML_MODE");
Expand All @@ -110,7 +113,7 @@ public TouchOptions (IList<string> arguments)
{ "hostport=", "HTTP/TCP port to connect to.", v => HostPort = int.Parse (v) },
{ "use-tcp-tunnel", "Use a TCP tunnel to connect to the host.", v => UseTcpTunnel = true },
{ "enablenetwork", "Enable the network reporter.", v => EnableNetwork = true },
{ "transport=", "Select transport method. Either TCP (default), HTTP or FILE.", v => Transport = v },
{ "transport=", "Select transport method. Either TCP (default), HTTP or FILE.", v => { if (v is not null) Transport = v; } },
{ "enablexml:", "Enable the xml reported.", v => EnableXml = string.IsNullOrEmpty (v) ? true : bool.Parse (v) },
{ "xmlmode=", "The xml mode.", v => XmlMode = (XmlMode) Enum.Parse (typeof (XmlMode), v, true) },
{ "xmlversion=", "The xml version.", v => XmlVersion = (XmlVersion) Enum.Parse (typeof (XmlVersion), v, true) },
Expand Down Expand Up @@ -138,7 +141,7 @@ public TouchOptions ()

public bool EnableXml { get; set; }

public string HostName { get; private set; }
public string? HostName { get; private set; }

public int HostPort { get; private set; }

Expand All @@ -150,15 +153,15 @@ public TouchOptions ()

public string Transport { get; set; } = "TCP";

public string LogFile { get; set; }
public string? LogFile { get; set; }

public bool ShowUseNetworkLogger {
get { return (EnableNetwork && !String.IsNullOrWhiteSpace (HostName) && (HostPort > 0)) || Transport == "FILE"; }
}

public bool SortNames { get; set; }

public string TestName { get; set; }
public string? TestName { get; set; }

#if !__MACOS__
public UIViewController GetViewController ()
Expand Down
Loading
Loading