Skip to content

Add option to request preview version for nanoCLR #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
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
1 change: 1 addition & 0 deletions poc/TestOfTestFramework/nano.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<CLRVersion></CLRVersion><!--Specify the nanoCLR version to use. If not specified, the latest available will be used. -->
<PathToLocalCLRInstance></PathToLocalCLRInstance><!--Specify the path to a local nanoCLR instance. If not specified, the default one installed with nanoclr CLR witll be used. -->
<RunnerExtraArguments></RunnerExtraArguments><!--Specify extra arguments to pass to the test runner. -->
<UsePreviewClr>False</UsePreviewClr><!--Set to true to use the preview version of the nanoCLR. -->
</nanoFrameworkAdapter>
</RunSettings>
1 change: 1 addition & 0 deletions poc/TestOfTestFrameworkByReference/nano.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<Logging>None</Logging>
<IsRealHardware>False</IsRealHardware>
<RunnerExtraArguments></RunnerExtraArguments><!--Specify extra arguments to pass to the test runner. -->
<UsePreviewClr>False</UsePreviewClr><!--Set to true to use the preview version of the nanoCLR. -->
</nanoFrameworkAdapter>
</RunSettings>
1 change: 1 addition & 0 deletions source/TestAdapter/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ private async Task<List<TestResult>> RunTestOnEmulatorAsync(
{
NanoCLRHelper.UpdateNanoCLRInstance(
_settings.CLRVersion,
_settings.UsePreviewClr,
_logger);
}

Expand Down
22 changes: 19 additions & 3 deletions source/TestAdapter/NanoCLRHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,15 @@ public static bool InstallNanoClr(LogMessenger logger)
return NanoClrIsInstalled;
}

/// <summary>
/// Update the nanoCLR instance.
/// </summary>
/// <param name="clrVersion">Specific version to use.</param>
/// <param name="usePreview"><see langword="true"/> to use preview version, <see langword="false"/> to use stable version.</param>
/// <param name="logger">The logger to use to log messages.</param>
public static void UpdateNanoCLRInstance(
string clrVersion,
bool usePreview,
LogMessenger logger)
{
logger.LogMessage(
Expand All @@ -173,17 +180,26 @@ public static void UpdateNanoCLRInstance(

string arguments = "instance --update";

if (!string.IsNullOrEmpty(clrVersion))
// use preview parameter has precedence over the version
if (usePreview)
{
arguments += " --preview";
}
else
{
arguments += $" --clrversion {clrVersion}";
// if no preview, check if we have a version to use
if (!string.IsNullOrEmpty(clrVersion))
{
arguments += $" --version {clrVersion}";
}
}

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

// setup cancellation token with a timeout of 1 minute
using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMinutes(1)))
{
BufferedCommandResult cliResult = cmd.ExecuteBufferedAsync(cts.Token).Task.Result;

Expand Down
14 changes: 14 additions & 0 deletions source/TestAdapter/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class Settings
/// </summary>
public string CLRVersion { get; set; } = string.Empty;

/// <summary>
/// <see langword="true"/> to use a preview version of the nanoCLR instance.
/// </summary>
/// <remarks>
/// Set to <see langword="false"/>, or don't set the property, to use the latest stable version.
/// </remarks>
public bool UsePreviewClr { get; set; } = false;

/// <summary>
/// Level of logging for Unit Test execution.
/// </summary>
Expand Down Expand Up @@ -90,6 +98,12 @@ public static Settings Extract(XmlNode node)
{
settings.RunnerExtraArguments = runnerExtraArguments.Value;
}

XmlNode usePreviewClr = node.SelectSingleNode(nameof(UsePreviewClr))?.FirstChild;
if (usePreviewClr != null && usePreviewClr.NodeType == XmlNodeType.Text)
{
settings.UsePreviewClr = usePreviewClr.Value.Equals("true", StringComparison.CurrentCultureIgnoreCase);
}
}

return settings;
Expand Down