From 6bdb9ec73cd3065e1b5680686d622be54dce453c Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Thu, 12 Jan 2023 16:42:58 -0600 Subject: [PATCH] (#1174)(#1610) Add tests for packing with leading zeros These tests are to ensure that the version normalization on pack with the new NuGet assemblies is consistent into the future. There were already tests for removing semver v2 build metadata and that four part versions still work. This adds tests to ensure that leading zeros are removed, and that a zero in the fourth part of the version will be trimmed down to three parts. https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#normalized-version-numbers --- .../scenarios/PackScenarios.cs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs index 77ca4c232..dbc30675e 100644 --- a/src/chocolatey.tests.integration/scenarios/PackScenarios.cs +++ b/src/chocolatey.tests.integration/scenarios/PackScenarios.cs @@ -307,6 +307,100 @@ protected override string GetNuspecContent() } } + [Categories.SemVer20] + public class when_packaging_with_four_part_version_with_trailing_zero : ScenariosBase + { + private string _originalVersion = "0.1.0.0"; + protected override string ExpectedNuspecVersion => "0.1.0"; + protected override string ExpectedSubDirectory => "PackageOutput"; + + public override void Because() + { + MockLogger.reset(); + Service.pack_run(Configuration); + } + + protected override string GetNuspecContent() + { + return NuspecContentWithFormatableVersion.format_with(_originalVersion); + } + } + + [Categories.SemVer20] + public class when_packaging_with_leading_zeros_four_part : ScenariosBase + { + private string _originalVersion = "01.02.03.04"; + protected override string ExpectedNuspecVersion => "1.2.3.4"; + protected override string ExpectedSubDirectory => "PackageOutput"; + + public override void Because() + { + MockLogger.reset(); + Service.pack_run(Configuration); + } + + protected override string GetNuspecContent() + { + return NuspecContentWithFormatableVersion.format_with(_originalVersion); + } + } + + public class when_packaging_with_leading_zeros_three_part : ScenariosBase + { + private string _originalVersion = "01.02.04"; + protected override string ExpectedNuspecVersion => "1.2.4"; + protected override string ExpectedSubDirectory => "PackageOutput"; + + public override void Because() + { + MockLogger.reset(); + Service.pack_run(Configuration); + } + + protected override string GetNuspecContent() + { + return NuspecContentWithFormatableVersion.format_with(_originalVersion); + } + } + + [Categories.SemVer20] + public class when_packaging_with_leading_zeros_two_part : ScenariosBase + { + private string _originalVersion = "01.02"; + protected override string ExpectedNuspecVersion => "1.2.0"; + protected override string ExpectedSubDirectory => "PackageOutput"; + + public override void Because() + { + MockLogger.reset(); + Service.pack_run(Configuration); + } + + protected override string GetNuspecContent() + { + return NuspecContentWithFormatableVersion.format_with(_originalVersion); + } + } + + [Categories.SemVer20] + public class when_packaging_with_multiple_leading_zeros : ScenariosBase + { + private string _originalVersion = "0001.0002.0003"; + protected override string ExpectedNuspecVersion => "1.2.3"; + protected override string ExpectedSubDirectory => "PackageOutput"; + + public override void Because() + { + MockLogger.reset(); + Service.pack_run(Configuration); + } + + protected override string GetNuspecContent() + { + return NuspecContentWithFormatableVersion.format_with(_originalVersion); + } + } + public class when_packing_with_properties : ScenariosBase { protected override string ExpectedNuspecVersion => "0.1.0"; @@ -758,5 +852,28 @@ public void should_throw_exception_on_icon_element() "; + + private const string NuspecContentWithFormatableVersion = @" + + + test-package + Test Package + {0} + package author + package owner + A brief summary + A big description + test admin + + http://apache.org/2 + false + + + + + + + +"; } }