Skip to content

Commit 21422b8

Browse files
authored
Rider plugin bugfixes (#1967)
[fix] Sdk check fix, timeout fix, publish arch fix
1 parent 9a2a1fe commit 21422b8

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

utbot-rider/src/dotnet/UtBot/UtBot/GenerateUnitTestElementProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using JetBrains.ReSharper.Psi.CSharp;
77
using JetBrains.ReSharper.Psi.Resolve;
88
using JetBrains.ReSharper.Psi.Tree;
9-
using JetBrains.Util;
109

1110
namespace UtBot;
1211

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

2019
public bool IsValidValue(string value) =>
21-
value.IsNullOrEmpty() || (int.TryParse(value, out var intValue) && intValue > 0);
20+
int.TryParse(value, out var intValue) && intValue > 0;
2221

2322
public string ID => Id;
2423

utbot-rider/src/dotnet/UtBot/UtBot/UnitTestBuilder.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,18 @@ protected override void Process(CSharpGeneratorContext context, IProgressIndicat
6868
_notifications.Refresh();
6969

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

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

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

8180
if (!_dotNetVersionUtils.CanRunVSharp)
8281
{
83-
_notifications.ShowError($"At least .NET {DotNetVersionUtils.MinCompatibleSdkMajor} runtime is required for UnitTestBot.NET");
82+
_notifications.ShowError($"At least .NET {DotNetVersionUtils.MinCompatibleSdkMajor} SDK is required for UnitTestBot.NET");
8483
return;
8584
}
8685

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

123-
124-
125122
_shellLocks.Tasks.StartNew(_lifetime, Scheduling.FreeThreaded, () =>
126123
{
127124
try
@@ -241,12 +238,12 @@ private void Generate(IBackgroundProgressIndicator progressIndicator, IProject p
241238
var intervalMs = intervalS > 0 ? intervalS * 1000 : 500;
242239
using var methodProgressTimer = new Timer(intervalMs);
243240
var i = 0;
244-
methodProgressTimer.Elapsed += (_, _) =>
241+
void ChangeMethodName()
245242
{
246243
progressIndicator.Header.SetValue(methodNames[i]);
247244
i = (i + 1) % methodNames.Length;
248-
};
249-
245+
}
246+
methodProgressTimer.Elapsed += (_, _) => ChangeMethodName();
250247
_logger.Catch(() =>
251248
{
252249
var name = VSharpMain.VSharpProcessName;
@@ -257,8 +254,11 @@ private void Generate(IBackgroundProgressIndicator progressIndicator, IProject p
257254
var projectCsprojPath = project.ProjectFileLocation.FullPath;
258255
var args = new GenerateArguments(assemblyPath, projectCsprojPath, solutionFilePath, descriptors,
259256
timeout, testProjectFramework.FrameworkMoniker.Name);
257+
var vSharpTimeout = TimeSpan.FromSeconds(timeout);
258+
var rpcTimeout = new RpcTimeouts(vSharpTimeout + TimeSpan.FromSeconds(1), vSharpTimeout + TimeSpan.FromSeconds(30));
259+
ChangeMethodName();
260260
methodProgressTimer.Start();
261-
var result = proc.VSharpModel?.Generate.Sync(args, RpcTimeouts.Maximal);
261+
var result = proc.VSharpModel?.Generate.Sync(args, rpcTimeout);
262262
methodProgressTimer.Stop();
263263
_logger.Info("Result acquired");
264264
if (result is { GeneratedProjectPath: not null })

utbot-rider/src/dotnet/UtBot/UtBot/Utils/DotNetVersionUtils.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@ public TestProjectTargetFramework GetTestProjectFramework(IProject project)
7878
return new(defaultTfm, true);
7979
}
8080

81-
// TODO: is there a case when --list-runtimes is not available, but runtime is installed?
8281
private static bool GetCanRunVSharp(string workingDir)
8382
{
8483
var sdksInfo = RunProcess(new ProcessStartInfo
8584
{
8685
FileName = "dotnet",
87-
Arguments = "--list-runtimes",
86+
Arguments = "--list-sdks",
8887
WorkingDirectory = workingDir
8988
});
9089

@@ -93,7 +92,7 @@ private static bool GetCanRunVSharp(string workingDir)
9392
return false;
9493
}
9594

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

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

103102
for (var i = 0; i < matches.Count; ++i)
104103
{
105-
if (matches[i].Groups[1].Value == "AspNetCore")
106-
{
107-
continue;
108-
}
109-
110-
if (!int.TryParse(matches[i].Groups[2].Value, out var majorVersion))
104+
if (!int.TryParse(matches[i].Groups[1].Value, out var majorVersion))
111105
{
112106
continue;
113107
}

utbot-rider/src/dotnet/UtBot/UtBot/Utils/Notifications.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public void ShowError(
6060
bool closeAfterExecution = true,
6161
UserNotificationCommand command = null)
6262
{
63-
_logger.Error(message: body);
64-
6563
ShowNotification(
6664
NotificationSeverity.CRITICAL,
6765
Title,

utbot-rider/src/dotnet/UtBot/UtBot/Utils/ProjectPublisher.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void PublishSync(IProject project, IProjectConfiguration config, VirtualF
3030
var name = $"Publish::{project.Name}";
3131
Directory.CreateDirectory(outputDir.FullPath);
3232
var projectName = project.ProjectFileLocation.Name;
33-
var rid = RuntimeInformation.RuntimeIdentifier;
33+
var architecture = GetArchitecture();
3434
var tfm = config.TargetFrameworkId.TryGetShortIdentifier();
3535
var command = config.TargetFrameworkId.IsNetFramework ? "build" : "publish";
3636

@@ -43,7 +43,7 @@ public void PublishSync(IProject project, IProjectConfiguration config, VirtualF
4343
{
4444
FileName = "dotnet",
4545
Arguments =
46-
$"{command} \"{projectName}\" --sc -c {config.Name} -r {rid} -o {outputDir.FullPath} -f {tfm}",
46+
$"{command} \"{projectName}\" --sc -c {config.Name} -a {architecture} -o {outputDir.FullPath} -f {tfm}",
4747
WorkingDirectory = project.ProjectFileLocation.Directory.FullPath,
4848
RedirectStandardError = true,
4949
RedirectStandardOutput = true
@@ -80,4 +80,19 @@ void Schedule(SingleThreadScheduler scheduler)
8080
publishLifetimeDef.Terminate();
8181
}
8282
}
83+
84+
private string GetArchitecture()
85+
{
86+
var arch = RuntimeInformation.OSArchitecture;
87+
return arch switch
88+
{
89+
Architecture.X86 => "x86",
90+
Architecture.X64 => "x64",
91+
Architecture.Arm => "arm",
92+
Architecture.Arm64 => "arm64",
93+
Architecture.Wasm or Architecture.S390x =>
94+
throw new InvalidOperationException($"Unsupported architecture: {arch}"),
95+
_ => throw new ArgumentOutOfRangeException()
96+
};
97+
}
8398
}

0 commit comments

Comments
 (0)