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

Range condition with build numbers not working as expected #259

Open
lucas-scott-sybo opened this issue Feb 18, 2025 · 0 comments
Open

Range condition with build numbers not working as expected #259

lucas-scott-sybo opened this issue Feb 18, 2025 · 0 comments

Comments

@lucas-scott-sybo
Copy link

When using version.LessThanEqual and version.GreaterThanEqual I am able to construct a range comparison that works, but when using semver.NewConstraint with a range based constraint with build numbers, the same version fails the constraint.

go 1.23.2
version github.com/Masterminds/semver/v3 v3.3.1

example test cases to reproduce

package main_test

import (
	"fmt"
	"testing"

	"github.com/Masterminds/semver/v3"
)

// passes
func TestLib3(t *testing.T) {
	lower, err := semver.NewVersion("1.0.0")
	if err != nil {
		t.Fatalf("failed to parse lower bound")
	}

	upper, err := semver.NewVersion("2.0.0-beta+build123")
	if err != nil {
		t.Fatalf("failed to parse upper bound")
	}

	v, err := semver.NewVersion("2.0.0-beta+build123")
	if err != nil {
		fmt.Println("two")
		t.Fail()
	}

	match := lower.LessThanEqual(v) && upper.GreaterThanEqual(v) // success
	if !match {
		fmt.Println("three")
		t.Fail()
	}
}

// fails
func TestLib1(t *testing.T) {
	c, err := semver.NewConstraint("1.0.0 - 2.0.0-beta+build123")
	if err != nil {
		fmt.Println("one")
		t.Fail()
	}
	v, err := semver.NewVersion("2.0.0-beta+build123")
	if err != nil {
		fmt.Println("two")
		t.Fail()
	}
	if !c.Check(v) {
		fmt.Println("three") // fails here
		t.Fail()
	}
}

// fails
func TestLib2(t *testing.T) {
	c, err := semver.NewConstraint("1.0.0 - 2.0.0-beta+build123")
	if err != nil {
		fmt.Println("one")
		t.Fail()
	}
	v, err := semver.NewVersion("1.0.1-beta+build123")
	if err != nil {
		fmt.Println("two")
		t.Fail()
	}
	if !c.Check(v) {
		fmt.Println("three") // fails here
		t.Fail()
	}
}

// fails
func TestLib4(t *testing.T) {
	c, err := semver.NewConstraint(">= 1.0.0  <= 2.0.0-beta+build123")
	if err != nil {
		fmt.Println("one")
		t.Fail()
	}
	v, err := semver.NewVersion("1.0.1-beta+build123")
	if err != nil {
		fmt.Println("two")
		t.Fail()
	}
	if !c.Check(v) {
		fmt.Println("three") // fails here
		t.Fail()
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant