diff --git a/utbot-rider/src/dotnet/UtBot/UtBot/GenerateUnitTestElementProvider.cs b/utbot-rider/src/dotnet/UtBot/UtBot/GenerateUnitTestElementProvider.cs index 2e142c64e5..c9ca0341e7 100644 --- a/utbot-rider/src/dotnet/UtBot/UtBot/GenerateUnitTestElementProvider.cs +++ b/utbot-rider/src/dotnet/UtBot/UtBot/GenerateUnitTestElementProvider.cs @@ -6,7 +6,6 @@ using JetBrains.ReSharper.Psi.CSharp; using JetBrains.ReSharper.Psi.Resolve; using JetBrains.ReSharper.Psi.Tree; -using JetBrains.Util; namespace UtBot; @@ -18,7 +17,7 @@ internal class TimeoutGeneratorOption : IGeneratorOption public IReadOnlyList 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; diff --git a/utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs b/utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs index 2fd99e8aec..ad1e5e3e34 100644 --- a/utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs +++ b/utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs @@ -68,11 +68,10 @@ 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; } @@ -80,7 +79,7 @@ protected override void Process(CSharpGeneratorContext context, IProgressIndicat 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; } @@ -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 @@ -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; @@ -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 }) diff --git a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs index 8ec763639a..280109dd98 100644 --- a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs +++ b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs @@ -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 }); @@ -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) { @@ -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; } diff --git a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs index 2bf85ec75a..140f9d5eac 100644 --- a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs +++ b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs @@ -60,8 +60,6 @@ public void ShowError( bool closeAfterExecution = true, UserNotificationCommand command = null) { - _logger.Error(message: body); - ShowNotification( NotificationSeverity.CRITICAL, Title, diff --git a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs index 7db642b604..1fc91aefde 100644 --- a/utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs +++ b/utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs @@ -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"; @@ -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 @@ -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() + }; + } }