Skip to content

Commit edeaaa0

Browse files
committed
C#: Address copilots review comments.
1 parent d0737eb commit edeaaa0

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/PackagesConfigRestorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private bool TryRestoreNugetPackage(string packagesConfig)
216216
var exitCode = pi.ReadOutput(out _, onOut, onError);
217217
if (exitCode != 0)
218218
{
219-
logger.LogError($"Command {pi.FileName} {pi.Arguments} failed with exit code {exitCode}");
219+
logger.LogError($"Command {pi.FileName} {string.Join(" ", pi.ArgumentList)} failed with exit code {exitCode}");
220220
return false;
221221
}
222222
else

csharp/extractor/Semmle.Extraction.Tests/DotNet.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public bool RunCommand(List<string> args, string? workingDirectory, out IList<st
4646
return RunCommand(args, out output, silent);
4747
}
4848

49-
public string GetLastArgs() => string.Join(" ", lastArgs);
49+
public List<string> GetLastArgs() => lastArgs;
5050
}
5151

5252
public class DotNetTests
@@ -83,7 +83,7 @@ public void TestDotnetInfo()
8383

8484
// Verify
8585
var lastArgs = dotnetCliInvoker.GetLastArgs();
86-
Assert.Equal("--info", lastArgs);
86+
Assert.Equal(["--info"], lastArgs);
8787
}
8888

8989
[Fact]
@@ -119,7 +119,7 @@ public void TestDotnetRestoreProjectToDirectory1()
119119

120120
// Verify
121121
var lastArgs = dotnetCliInvoker.GetLastArgs();
122-
Assert.Equal("restore --no-dependencies myproject.csproj --packages mypackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
122+
Assert.Equal(["restore", "--no-dependencies", "myproject.csproj", "--packages", "mypackages", "/p:DisableImplicitNuGetFallbackFolder=true", "--verbosity", "normal"], lastArgs);
123123
}
124124

125125
[Fact]
@@ -134,7 +134,7 @@ public void TestDotnetRestoreProjectToDirectory2()
134134

135135
// Verify
136136
var lastArgs = dotnetCliInvoker.GetLastArgs();
137-
Assert.Equal("restore --no-dependencies myproject.csproj --packages mypackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
137+
Assert.Equal(["restore", "--no-dependencies", "myproject.csproj", "--packages", "mypackages", "/p:DisableImplicitNuGetFallbackFolder=true", "--verbosity", "normal"], lastArgs);
138138
Assert.Equal(2, res.AssetsFilePaths.Count());
139139
Assert.Contains("/path/to/project.assets.json", res.AssetsFilePaths);
140140
Assert.Contains("/path/to/project2.assets.json", res.AssetsFilePaths);
@@ -152,7 +152,7 @@ public void TestDotnetRestoreProjectToDirectory3()
152152

153153
// Verify
154154
var lastArgs = dotnetCliInvoker.GetLastArgs();
155-
Assert.Equal("restore --no-dependencies myproject.csproj --packages mypackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --force", lastArgs);
155+
Assert.Equal(["restore", "--no-dependencies", "myproject.csproj", "--packages", "mypackages", "/p:DisableImplicitNuGetFallbackFolder=true", "--verbosity", "normal", "--force"], lastArgs);
156156
Assert.Equal(2, res.AssetsFilePaths.Count());
157157
Assert.Contains("/path/to/project.assets.json", res.AssetsFilePaths);
158158
Assert.Contains("/path/to/project2.assets.json", res.AssetsFilePaths);
@@ -170,7 +170,7 @@ public void TestDotnetRestoreSolutionToDirectory1()
170170

171171
// Verify
172172
var lastArgs = dotnetCliInvoker.GetLastArgs();
173-
Assert.Equal("restore --no-dependencies mysolution.sln --packages mypackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
173+
Assert.Equal(["restore", "--no-dependencies", "mysolution.sln", "--packages", "mypackages", "/p:DisableImplicitNuGetFallbackFolder=true", "--verbosity", "normal"], lastArgs);
174174
Assert.Equal(2, res.RestoredProjects.Count());
175175
Assert.Contains("/path/to/project.csproj", res.RestoredProjects);
176176
Assert.Contains("/path/to/project2.csproj", res.RestoredProjects);
@@ -192,7 +192,7 @@ public void TestDotnetRestoreSolutionToDirectory2()
192192

193193
// Verify
194194
var lastArgs = dotnetCliInvoker.GetLastArgs();
195-
Assert.Equal("restore --no-dependencies mysolution.sln --packages mypackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal", lastArgs);
195+
Assert.Equal(["restore", "--no-dependencies", "mysolution.sln", "--packages", "mypackages", "/p:DisableImplicitNuGetFallbackFolder=true", "--verbosity", "normal"], lastArgs);
196196
Assert.Empty(res.RestoredProjects);
197197
Assert.Empty(res.AssetsFilePaths);
198198
}
@@ -209,7 +209,7 @@ public void TestDotnetNew()
209209

210210
// Verify
211211
var lastArgs = dotnetCliInvoker.GetLastArgs();
212-
Assert.Equal("new console --no-restore --output myfolder", lastArgs);
212+
Assert.Equal(["new", "console", "--no-restore", "--output", "myfolder"], lastArgs);
213213
}
214214

215215
[Fact]
@@ -224,7 +224,7 @@ public void TestDotnetAddPackage()
224224

225225
// Verify
226226
var lastArgs = dotnetCliInvoker.GetLastArgs();
227-
Assert.Equal("add myfolder package mypackage --no-restore", lastArgs);
227+
Assert.Equal(["add", "myfolder", "package", "mypackage", "--no-restore"], lastArgs);
228228
}
229229

230230
[Fact]
@@ -239,7 +239,7 @@ public void TestDotnetGetListedRuntimes1()
239239

240240
// Verify
241241
var lastArgs = dotnetCliInvoker.GetLastArgs();
242-
Assert.Equal("--list-runtimes", lastArgs);
242+
Assert.Equal(["--list-runtimes"], lastArgs);
243243
Assert.Equal(2, runtimes.Count);
244244
Assert.Contains("Microsoft.AspNetCore.App 7.0.2 [/path/dotnet/shared/Microsoft.AspNetCore.App]", runtimes);
245245
Assert.Contains("Microsoft.NETCore.App 7.0.2 [/path/dotnet/shared/Microsoft.NETCore.App]", runtimes);
@@ -258,7 +258,7 @@ public void TestDotnetGetListedRuntimes2()
258258

259259
// Verify
260260
var lastArgs = dotnetCliInvoker.GetLastArgs();
261-
Assert.Equal("--list-runtimes", lastArgs);
261+
Assert.Equal(["--list-runtimes"], lastArgs);
262262
Assert.Empty(runtimes);
263263
}
264264

@@ -274,7 +274,7 @@ public void TestDotnetExec()
274274

275275
// Verify
276276
var lastArgs = dotnetCliInvoker.GetLastArgs();
277-
Assert.Equal("exec myarg1 myarg2", lastArgs);
277+
Assert.Equal(["exec", "myarg1", "myarg2"], lastArgs);
278278
}
279279

280280
[Fact]
@@ -289,7 +289,7 @@ public void TestNugetFeeds()
289289

290290
// Verify
291291
var lastArgs = dotnetCliInvoker.GetLastArgs();
292-
Assert.Equal("nuget list source --format Short --configfile abc", lastArgs);
292+
Assert.Equal(["nuget", "list", "source", "--format", "Short", "--configfile", "abc"], lastArgs);
293293
}
294294

295295
[Fact]
@@ -304,7 +304,7 @@ public void TestNugetFeedsFromFolder()
304304

305305
// Verify
306306
var lastArgs = dotnetCliInvoker.GetLastArgs();
307-
Assert.Equal("nuget list source --format Short", lastArgs);
307+
Assert.Equal(["nuget", "list", "source", "--format", "Short"], lastArgs);
308308
Assert.Equal("abc", dotnetCliInvoker.WorkingDirectory);
309309
}
310310
}

0 commit comments

Comments
 (0)