Skip to content

Commit

Permalink
(chocolatey#1174)(chocolatey#1610) Add tests for packing with leading…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
TheCakeIsNaOH committed Jan 12, 2023
1 parent 737b58c commit 6bdb9ec
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/chocolatey.tests.integration/scenarios/PackScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -758,5 +852,28 @@ public void should_throw_exception_on_icon_element()
<files>
</files>
</package>";

private const string NuspecContentWithFormatableVersion = @"<?xml version=""1.0"" encoding=""utf-8""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"">
<metadata>
<id>test-package</id>
<title>Test Package</title>
<version>{0}</version>
<authors>package author</authors>
<owners>package owner</owners>
<summary>A brief summary</summary>
<description>A big description</description>
<tags>test admin</tags>
<copyright></copyright>
<licenseUrl>http://apache.org/2</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes></releaseNotes>
<dependencies>
<dependency id=""chocolatey-core.extension"" />
</dependencies>
</metadata>
<files>
</files>
</package>";
}
}

0 comments on commit 6bdb9ec

Please sign in to comment.