Skip to content

Commit

Permalink
Fix the version comparation error for pre-releases in CodeGen tool
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Apr 30, 2024
1 parent f3c00df commit b508f46
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public static void ValidatePackageRefrences()

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 @@ private static IEnumerable<(string name, string version)>GetPackageReferences(st
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]
[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);
}
}

0 comments on commit b508f46

Please sign in to comment.