Skip to content

Commit 28cafa2

Browse files
authored
Add option to request preview version for nanoCLR (#310)
***NO_CI***
1 parent d8439af commit 28cafa2

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

poc/TestOfTestFramework/nano.runsettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
<CLRVersion></CLRVersion><!--Specify the nanoCLR version to use. If not specified, the latest available will be used. -->
1414
<PathToLocalCLRInstance></PathToLocalCLRInstance><!--Specify the path to a local nanoCLR instance. If not specified, the default one installed with nanoclr CLR witll be used. -->
1515
<RunnerExtraArguments></RunnerExtraArguments><!--Specify extra arguments to pass to the test runner. -->
16+
<UsePreviewClr>False</UsePreviewClr><!--Set to true to use the preview version of the nanoCLR. -->
1617
</nanoFrameworkAdapter>
1718
</RunSettings>

poc/TestOfTestFrameworkByReference/nano.runsettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<Logging>None</Logging>
1515
<IsRealHardware>False</IsRealHardware>
1616
<RunnerExtraArguments></RunnerExtraArguments><!--Specify extra arguments to pass to the test runner. -->
17+
<UsePreviewClr>False</UsePreviewClr><!--Set to true to use the preview version of the nanoCLR. -->
1718
</nanoFrameworkAdapter>
1819
</RunSettings>

source/TestAdapter/Executor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ private async Task<List<TestResult>> RunTestOnEmulatorAsync(
670670
{
671671
NanoCLRHelper.UpdateNanoCLRInstance(
672672
_settings.CLRVersion,
673+
_settings.UsePreviewClr,
673674
_logger);
674675
}
675676

source/TestAdapter/NanoCLRHelper.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,15 @@ public static bool InstallNanoClr(LogMessenger logger)
163163
return NanoClrIsInstalled;
164164
}
165165

166+
/// <summary>
167+
/// Update the nanoCLR instance.
168+
/// </summary>
169+
/// <param name="clrVersion">Specific version to use.</param>
170+
/// <param name="usePreview"><see langword="true"/> to use preview version, <see langword="false"/> to use stable version.</param>
171+
/// <param name="logger">The logger to use to log messages.</param>
166172
public static void UpdateNanoCLRInstance(
167173
string clrVersion,
174+
bool usePreview,
168175
LogMessenger logger)
169176
{
170177
logger.LogMessage(
@@ -173,17 +180,26 @@ public static void UpdateNanoCLRInstance(
173180

174181
string arguments = "instance --update";
175182

176-
if (!string.IsNullOrEmpty(clrVersion))
183+
// use preview parameter has precedence over the version
184+
if (usePreview)
185+
{
186+
arguments += " --preview";
187+
}
188+
else
177189
{
178-
arguments += $" --clrversion {clrVersion}";
190+
// if no preview, check if we have a version to use
191+
if (!string.IsNullOrEmpty(clrVersion))
192+
{
193+
arguments += $" --version {clrVersion}";
194+
}
179195
}
180196

181197
Command cmd = Cli.Wrap("nanoclr")
182198
.WithArguments(arguments)
183199
.WithValidation(CommandResultValidation.None);
184200

185201
// setup cancellation token with a timeout of 1 minute
186-
using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
202+
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
187203
{
188204
BufferedCommandResult cliResult = cmd.ExecuteBufferedAsync(cts.Token).Task.Result;
189205

source/TestAdapter/Settings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public class Settings
3131
/// </summary>
3232
public string CLRVersion { get; set; } = string.Empty;
3333

34+
/// <summary>
35+
/// <see langword="true"/> to use a preview version of the nanoCLR instance.
36+
/// </summary>
37+
/// <remarks>
38+
/// Set to <see langword="false"/>, or don't set the property, to use the latest stable version.
39+
/// </remarks>
40+
public bool UsePreviewClr { get; set; } = false;
41+
3442
/// <summary>
3543
/// Level of logging for Unit Test execution.
3644
/// </summary>
@@ -90,6 +98,12 @@ public static Settings Extract(XmlNode node)
9098
{
9199
settings.RunnerExtraArguments = runnerExtraArguments.Value;
92100
}
101+
102+
XmlNode usePreviewClr = node.SelectSingleNode(nameof(UsePreviewClr))?.FirstChild;
103+
if (usePreviewClr != null && usePreviewClr.NodeType == XmlNodeType.Text)
104+
{
105+
settings.UsePreviewClr = usePreviewClr.Value.Equals("true", StringComparison.CurrentCultureIgnoreCase);
106+
}
93107
}
94108

95109
return settings;

0 commit comments

Comments
 (0)