Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the version comparation error for pre-releases in CodeGen tool #1088

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@

public static IEnumerable<string> GetProjects() => Directory.GetFiles(".", "*.csproj", SearchOption.AllDirectories);

/// <summary>
/// Trims the pre-release information from a version string
/// </summary>
internal static string TrimPreReleaseVersion(string version)
{
var parts = version.Split('-');
return parts[0];
}

private static IEnumerable<(string name, string version)>GetPackageReferences(string projectFilePath)
{
var csproj = new XmlDocument();
Expand All @@ -51,6 +60,7 @@
var version = packageReference.Attributes?["Version"]?.Value;
if (packageName is not null && version is not null)
{
packageName = TrimPreReleaseVersion(packageName);

Check warning on line 63 in src/HassModel/NetDaemon.HassModel.CodeGenerator/DependencyValidator.cs

View check run for this annotation

Codecov / codecov/patch

src/HassModel/NetDaemon.HassModel.CodeGenerator/DependencyValidator.cs#L63

Added line #L63 was not covered by tests
yield return (packageName, version);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NetDaemon.HassModel.CodeGenerator;

namespace NetDaemon.HassModel.Tests.CodeGenerator;

public class DependencyValidatorTests
{
// Test that pre-release versions are trimmed using the TrimPreReleaseVersion method using theory
[Theory]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would test this in context of the comparison. So a package version with suffix should match a Libray version without a version.

[InlineData("1.0.0-alpha", "1.0.0")]
[InlineData("24.17.0-alpha-2", "24.17.0")]
[InlineData("24.17.0", "24.17.0")]
public void TrimPreReleaseVersionShouldReturnCorrectVersion(string version, string expected)
{
// ARRANGE

// ACT
var result = DependencyValidator.TrimPreReleaseVersion(version);

// ASSERT
result.Should().Be(expected);
}
}
Loading