Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit a145cac

Browse files
[Xml] Allow to specify the xml formatter to be used in a run. (#55)
Allow to pass ether from command line of env vars the xml format to use.
1 parent d22825a commit a145cac

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

NUnitLite/TouchRunner/TouchOptions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public enum XmlMode {
4141
Wrapped = 1,
4242
}
4343

44+
public enum XmlVersion {
45+
NUnitV2 = 0,
46+
NUnitV3 = 1,
47+
}
48+
4449
public class TouchOptions {
4550

4651
static public TouchOptions Current = new TouchOptions ();
@@ -79,6 +84,9 @@ public TouchOptions ()
7984
var xml_mode = Environment.GetEnvironmentVariable ("NUNIT_ENABLE_XML_MODE");
8085
if (!string.IsNullOrEmpty (xml_mode))
8186
XmlMode = (XmlMode) Enum.Parse (typeof (XmlMode), xml_mode, true);
87+
var xml_version = Environment.GetEnvironmentVariable ("NUNIT_XML_VERSION");
88+
if (!string.IsNullOrEmpty (xml_version))
89+
XmlVersion = (XmlVersion)Enum.Parse (typeof (XmlVersion), xml_version, true);
8290
if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("NUNIT_LOG_FILE")))
8391
LogFile = Environment.GetEnvironmentVariable ("NUNIT_LOG_FILE");
8492

@@ -91,6 +99,7 @@ public TouchOptions ()
9199
{ "transport=", "Select transport method. Either TCP (default), HTTP or FILE.", v => Transport = v },
92100
{ "enablexml", "Enable the xml reported.", v => EnableXml = false },
93101
{ "xmlmode", "The xml mode.", v => XmlMode = (XmlMode) Enum.Parse (typeof (XmlMode), v, false) },
102+
{ "xmlversion", "The xml version.", v => XmlVersion = (XmlVersion) Enum.Parse (typeof (XmlVersion), v, false) },
94103
{ "logfile=", "A path where output will be saved.", v => LogFile = v },
95104
};
96105

@@ -105,6 +114,8 @@ public TouchOptions ()
105114

106115
public XmlMode XmlMode { get; set; }
107116

117+
public XmlVersion XmlVersion { get; set; } = XmlVersion.NUnitV2;
118+
108119
public bool EnableXml { get; set; }
109120

110121
public string HostName { get; private set; }

NUnitLite/TouchRunner/TouchRunner.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,17 @@ public bool OpenWriter (string message)
276276
break;
277277
}
278278
if (options.EnableXml) {
279+
NUnitLite.Runner.OutputWriter formatter;
280+
switch (options.XmlVersion) {
281+
case XmlVersion.NUnitV3:
282+
formatter = new NUnitLite.Runner.NUnit3XmlOutputWriter (DateTime.UtcNow);
283+
break;
284+
default:
285+
formatter = new NUnitLite.Runner.NUnit2XmlOutputWriter (DateTime.UtcNow);
286+
break;
287+
}
279288
Writer = new NUnitOutputTextWriter (
280-
this, defaultWriter, new NUnitLite.Runner.NUnit2XmlOutputWriter (DateTime.UtcNow), options.XmlMode);
289+
this, defaultWriter, formatter, options.XmlMode);
281290
} else {
282291
Writer = defaultWriter;
283292
}

0 commit comments

Comments
 (0)