Skip to content

Commit

Permalink
Merge branch 'main' into bump-corepack
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 authored Dec 20, 2024
2 parents 5f35e1c + 1cb627b commit a56e1ed
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected static Task TestUpdate(
{
return useSolution
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [(projectFilePath, projectContents)], projectFilesExpected: [(projectFilePath, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager)
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile: (projectFilePath, projectContents), expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager);
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile: (projectFilePath, projectContents), expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, additionalChecks: null, packages: packages, experimentsManager: experimentsManager);
}

protected static Task TestUpdate(
Expand All @@ -65,7 +65,7 @@ protected static Task TestUpdate(
{
return useSolution
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [projectFile], projectFilesExpected: [(projectFile.Path, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager)
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile, expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager);
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile, expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, additionalChecks: null, packages: packages, experimentsManager: experimentsManager);
}

protected static Task TestNoChangeforProject(
Expand Down Expand Up @@ -101,6 +101,7 @@ protected static Task TestUpdateForProject(
bool isTransitive = false,
TestFile[]? additionalFiles = null,
TestFile[]? additionalFilesExpected = null,
Action<string>? additionalChecks = null,
MockNuGetPackage[]? packages = null,
ExperimentsManager? experimentsManager = null,
string projectFilePath = "test-project.csproj",
Expand All @@ -114,6 +115,7 @@ protected static Task TestUpdateForProject(
isTransitive,
additionalFiles,
additionalFilesExpected,
additionalChecks,
packages,
experimentsManager,
expectedResult);
Expand All @@ -127,6 +129,7 @@ protected static async Task TestUpdateForProject(
bool isTransitive = false,
TestFile[]? additionalFiles = null,
TestFile[]? additionalFilesExpected = null,
Action<string>? additionalChecks = null,
MockNuGetPackage[]? packages = null,
ExperimentsManager? experimentsManager = null,
ExpectedUpdateOperationResult? expectedResult = null)
Expand Down Expand Up @@ -156,6 +159,17 @@ protected static async Task TestUpdateForProject(
{
ValidateUpdateOperationResult(expectedResult, actualResult!);
}

if (additionalChecks is not null)
{
var sourcesDirectory = temporaryDirectory;
if (placeFilesInSrc)
{
sourcesDirectory = Path.Combine(temporaryDirectory, "src");
}

additionalChecks(sourcesDirectory);
}
});

var expectedResultFiles = additionalFilesExpected.Prepend((projectFilePath, expectedProjectContents)).ToArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
using Xunit;

namespace NuGetUpdater.Core.Test.Update;

public partial class UpdateWorkerTests
{
public class LockFile : UpdateWorkerTestBase
{
[Fact]
public async Task UpdateSingleDependency()
{
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"),
],
// initial
projectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
""",
additionalFiles:
[
("packages.lock.json", "{}")
],
// expected
expectedProjectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="2.0.0" />
</ItemGroup>
</Project>
""",
additionalChecks: path =>
{
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json"));
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents);
}
);
}

[Fact]
public async Task UpdateSingleDependency_CentralPackageManagement()
{
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"),
],
// initial
projectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" />
</ItemGroup>
</Project>
""",
additionalFiles:
[
("packages.lock.json", "{}"),
("Directory.Packages.props", """
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
""")
],
// expected
expectedProjectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" />
</ItemGroup>
</Project>
""",
additionalFilesExpected:
[
("Directory.Packages.props", """
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Some.Package" Version="2.0.0" />
</ItemGroup>
</Project>
""")
],
additionalChecks: path =>
{
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json"));
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents);
}
);
}

[Fact]
public async Task UpdateSingleDependency_WindowsSpecific()
{
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"),
],
// initial
projectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
""",
additionalFiles:
[
("packages.lock.json", "{}")
],
// expected
expectedProjectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="2.0.0" />
</ItemGroup>
</Project>
""",
additionalChecks: path =>
{
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json"));
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents);
}
);
}

[Fact]
public async Task UpdateSingleDependency_CentralPackageManagement_WindowsSpecific()
{
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0",
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"),
],
// initial
projectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" />
</ItemGroup>
</Project>
""",
additionalFiles:
[
("packages.lock.json", "{}"),
("Directory.Packages.props", """
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
""")
],
// expected
expectedProjectContents: $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" />
</ItemGroup>
</Project>
""",
additionalFilesExpected:
[
("Directory.Packages.props", """
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Some.Package" Version="2.0.0" />
</ItemGroup>
</Project>
""")
],
additionalChecks: path =>
{
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json"));
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents);
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static async Task UpdateLockFileAsync(
var projectDirectory = Path.GetDirectoryName(projectPath)!;
await MSBuildHelper.HandleGlobalJsonAsync(projectDirectory, repoRootPath, experimentsManager, async () =>
{
var (exitCode, stdout, stderr) = await ProcessEx.RunDotnetWithoutMSBuildEnvironmentVariablesAsync(["restore", "--force-evaluate", projectPath], projectDirectory, experimentsManager);
var (exitCode, stdout, stderr) = await ProcessEx.RunDotnetWithoutMSBuildEnvironmentVariablesAsync(["restore", "--force-evaluate", "-p:EnableWindowsTargeting=true", projectPath], projectDirectory, experimentsManager);
if (exitCode != 0)
{
logger.Error($" Lock file update failed.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
Expand Down

0 comments on commit a56e1ed

Please sign in to comment.