Skip to content

Rider plugin bugfixes #1967

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
Mar 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.Resolve;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.Util;

namespace UtBot;

Expand All @@ -18,7 +17,7 @@ internal class TimeoutGeneratorOption : IGeneratorOption
public IReadOnlyList<string> GetPossibleValues() => new string[] { };

public bool IsValidValue(string value) =>
value.IsNullOrEmpty() || (int.TryParse(value, out var intValue) && intValue > 0);
int.TryParse(value, out var intValue) && intValue > 0;

public string ID => Id;

Expand Down
20 changes: 10 additions & 10 deletions utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ protected override void Process(CSharpGeneratorContext context, IProgressIndicat
_notifications.Refresh();

var timeoutString = context.GetOption(TimeoutGeneratorOption.Id);
var timeout = -1;

if (!timeoutString.IsNullOrEmpty() && (!int.TryParse(timeoutString, out timeout) || timeout <= 0))
if (!int.TryParse(timeoutString, out var timeout) || timeout <= 0)
{
_notifications.ShowError("Invalid timeout value. Timeout should be an integer number greater than zero or left empty for no timeout");
_notifications.ShowError("Invalid timeout value. Timeout should be an integer number greater than zero");
return;
}

if (context.PsiModule.ContainingProjectModule is not IProject project) return;

if (!_dotNetVersionUtils.CanRunVSharp)
{
_notifications.ShowError($"At least .NET {DotNetVersionUtils.MinCompatibleSdkMajor} runtime is required for UnitTestBot.NET");
_notifications.ShowError($"At least .NET {DotNetVersionUtils.MinCompatibleSdkMajor} SDK is required for UnitTestBot.NET");
return;
}

Expand Down Expand Up @@ -120,8 +119,6 @@ protected override void Process(CSharpGeneratorContext context, IProgressIndicat
_backgroundProgressIndicatorManager.CreateIndicator(progressLifetimeDef.Lifetime, true, true,
"Generating unit tests");



_shellLocks.Tasks.StartNew(_lifetime, Scheduling.FreeThreaded, () =>
{
try
Expand Down Expand Up @@ -241,12 +238,12 @@ private void Generate(IBackgroundProgressIndicator progressIndicator, IProject p
var intervalMs = intervalS > 0 ? intervalS * 1000 : 500;
using var methodProgressTimer = new Timer(intervalMs);
var i = 0;
methodProgressTimer.Elapsed += (_, _) =>
void ChangeMethodName()
{
progressIndicator.Header.SetValue(methodNames[i]);
i = (i + 1) % methodNames.Length;
};

}
methodProgressTimer.Elapsed += (_, _) => ChangeMethodName();
_logger.Catch(() =>
{
var name = VSharpMain.VSharpProcessName;
Expand All @@ -257,8 +254,11 @@ private void Generate(IBackgroundProgressIndicator progressIndicator, IProject p
var projectCsprojPath = project.ProjectFileLocation.FullPath;
var args = new GenerateArguments(assemblyPath, projectCsprojPath, solutionFilePath, descriptors,
timeout, testProjectFramework.FrameworkMoniker.Name);
var vSharpTimeout = TimeSpan.FromSeconds(timeout);
var rpcTimeout = new RpcTimeouts(vSharpTimeout + TimeSpan.FromSeconds(1), vSharpTimeout + TimeSpan.FromSeconds(30));
ChangeMethodName();
methodProgressTimer.Start();
var result = proc.VSharpModel?.Generate.Sync(args, RpcTimeouts.Maximal);
var result = proc.VSharpModel?.Generate.Sync(args, rpcTimeout);
methodProgressTimer.Stop();
_logger.Info("Result acquired");
if (result is { GeneratedProjectPath: not null })
Expand Down
12 changes: 3 additions & 9 deletions utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public TestProjectTargetFramework GetTestProjectFramework(IProject project)
return new(defaultTfm, true);
}

// TODO: is there a case when --list-runtimes is not available, but runtime is installed?
private static bool GetCanRunVSharp(string workingDir)
{
var sdksInfo = RunProcess(new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "--list-runtimes",
Arguments = "--list-sdks",
WorkingDirectory = workingDir
});

Expand All @@ -93,7 +92,7 @@ private static bool GetCanRunVSharp(string workingDir)
return false;
}

var matches = Regex.Matches(sdksInfo, @"\.(\S+)\.App (\d+)\.(\d+)\.(\d+)");
var matches = Regex.Matches(sdksInfo, @"(\d+)\.(\d+)\.(\d+)");

if (matches.Count < 1)
{
Expand All @@ -102,12 +101,7 @@ private static bool GetCanRunVSharp(string workingDir)

for (var i = 0; i < matches.Count; ++i)
{
if (matches[i].Groups[1].Value == "AspNetCore")
{
continue;
}

if (!int.TryParse(matches[i].Groups[2].Value, out var majorVersion))
if (!int.TryParse(matches[i].Groups[1].Value, out var majorVersion))
{
continue;
}
Expand Down
2 changes: 0 additions & 2 deletions utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public void ShowError(
bool closeAfterExecution = true,
UserNotificationCommand command = null)
{
_logger.Error(message: body);

ShowNotification(
NotificationSeverity.CRITICAL,
Title,
Expand Down
19 changes: 17 additions & 2 deletions utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void PublishSync(IProject project, IProjectConfiguration config, VirtualF
var name = $"Publish::{project.Name}";
Directory.CreateDirectory(outputDir.FullPath);
var projectName = project.ProjectFileLocation.Name;
var rid = RuntimeInformation.RuntimeIdentifier;
var architecture = GetArchitecture();
var tfm = config.TargetFrameworkId.TryGetShortIdentifier();
var command = config.TargetFrameworkId.IsNetFramework ? "build" : "publish";

Expand All @@ -43,7 +43,7 @@ public void PublishSync(IProject project, IProjectConfiguration config, VirtualF
{
FileName = "dotnet",
Arguments =
$"{command} \"{projectName}\" --sc -c {config.Name} -r {rid} -o {outputDir.FullPath} -f {tfm}",
$"{command} \"{projectName}\" --sc -c {config.Name} -a {architecture} -o {outputDir.FullPath} -f {tfm}",
WorkingDirectory = project.ProjectFileLocation.Directory.FullPath,
RedirectStandardError = true,
RedirectStandardOutput = true
Expand Down Expand Up @@ -80,4 +80,19 @@ void Schedule(SingleThreadScheduler scheduler)
publishLifetimeDef.Terminate();
}
}

private string GetArchitecture()
{
var arch = RuntimeInformation.OSArchitecture;
return arch switch
{
Architecture.X86 => "x86",
Architecture.X64 => "x64",
Architecture.Arm => "arm",
Architecture.Arm64 => "arm64",
Architecture.Wasm or Architecture.S390x =>
throw new InvalidOperationException($"Unsupported architecture: {arch}"),
_ => throw new ArgumentOutOfRangeException()
};
}
}