-
Notifications
You must be signed in to change notification settings - Fork 12
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
[JENKINS-51594] Test behavior of snapshots vs. RCs, JEP-229 #6
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
508e1df
[JENKINS-51594] Snapshots should sort as newer than RCs.
jglick 0ba9e12
Failing to reproduce a problem hinted at by @JKrag in https://gitter.…
jglick 0d14306
Precise link.
jglick 3edc207
Merge branch 'master' into snapshots-JENKINS-51594
jglick 52dd0b7
Merge branch 'master' of https://github.com/jenkinsci/lib-version-num…
jglick 7812e25
Also testing JEP-229 backport possibilities
jglick 048f899
Revert behavior change, and just run tests for now
jglick 2b5eb31
Snapshots do not in fact sort well without patches
jglick 0071313
What about changelist.format=%d.v%s?
jglick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,14 +23,25 @@ | |
*/ | ||
package hudson.util; | ||
|
||
import junit.framework.TestCase; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.apache.maven.artifact.versioning.ComparableVersion; | ||
import org.hamcrest.CoreMatchers; | ||
import static org.junit.Assert.*; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ErrorCollector; | ||
import org.jvnet.hudson.test.Issue; | ||
|
||
/** | ||
* @author Xavier Le Vourch | ||
*/ | ||
public class VersionNumberTest extends TestCase { | ||
public class VersionNumberTest { | ||
|
||
@Rule | ||
public ErrorCollector errors = new ErrorCollector(); | ||
|
||
public void testIsNewerThan() { | ||
@Test | ||
public void isNewerThan() { | ||
assertTrue(new VersionNumber("2.0.*").isNewerThan(new VersionNumber("2.0"))); | ||
assertTrue(new VersionNumber("2.1-SNAPSHOT").isNewerThan(new VersionNumber("2.0.*"))); | ||
assertTrue(new VersionNumber("2.1").isNewerThan(new VersionNumber("2.1-SNAPSHOT"))); | ||
|
@@ -44,23 +55,36 @@ public void testIsNewerThan() { | |
// which makes more sense than before | ||
assertTrue(new VersionNumber("2.0.0").equals(new VersionNumber("2.0"))); | ||
} | ||
|
||
@Issue("https://gitter.im/jenkinsci/configuration-as-code-plugin?at=5b4f2fc455a7e23c014da2af") | ||
@Test | ||
public void alpha() { | ||
assertTrue(new VersionNumber("2.0").isNewerThan(new VersionNumber("2.0-alpha-1"))); | ||
assertTrue(new VersionNumber("2.0-alpha-1").isNewerThan(new VersionNumber("2.0-alpha-1-rc9999.abc123def456"))); | ||
} | ||
|
||
public void testEarlyAccess() { | ||
@Test | ||
public void earlyAccess() { | ||
assertTrue(new VersionNumber("2.0.ea2").isNewerThan(new VersionNumber("2.0.ea1"))); | ||
assertTrue(new VersionNumber("2.0.ea1").isNewerThan(new VersionNumber("2.0.ea"))); | ||
assertEquals(new VersionNumber("2.0.ea"), new VersionNumber("2.0.ea0")); | ||
} | ||
|
||
public void testSnapshots() { | ||
@Test | ||
public void snapshots() { | ||
assertTrue(new VersionNumber("1.12").isNewerThan(new VersionNumber("1.12-SNAPSHOT (private-08/24/2008 12:13-hudson)"))); | ||
assertTrue(new VersionNumber("1.12-SNAPSHOT (private-08/24/2008 12:13-hudson)").isNewerThan(new VersionNumber("1.11"))); | ||
assertTrue(new VersionNumber("1.12-SNAPSHOT (private-08/24/2008 12:13-hudson)").equals(new VersionNumber("1.12-SNAPSHOT"))); | ||
// This is changed from the old impl because snapshots are no longer a "magic" number | ||
assertFalse(new VersionNumber("1.12-SNAPSHOT").equals(new VersionNumber("1.11.*"))); | ||
assertTrue(new VersionNumber("1.11.*").isNewerThan(new VersionNumber("1.11.9"))); | ||
/* TODO the reverse: | ||
assertTrue(new VersionNumber("1.12-SNAPSHOT").isNewerThan(new VersionNumber("1.12-rc9999.abc123def456"))); | ||
*/ | ||
} | ||
|
||
public void testTimestamps() { | ||
@Test | ||
public void timestamps() { | ||
assertTrue(new VersionNumber("2.0.3-20170207.105042-1").isNewerThan(new VersionNumber("2.0.2"))); | ||
assertTrue(new VersionNumber("2.0.3").isNewerThan(new VersionNumber("2.0.3-20170207.105042-1"))); | ||
assertTrue(new VersionNumber("2.0.3-20170207.105042-1").equals(new VersionNumber("2.0.3-SNAPSHOT"))); | ||
|
@@ -72,7 +96,8 @@ public void testTimestamps() { | |
assertFalse(new VersionNumber("2.0.3-20170207.105042-1").isOlderThan(new VersionNumber("2.0.3-SNAPSHOT"))); | ||
} | ||
|
||
public void testDigit() { | ||
@Test | ||
public void digit() { | ||
assertEquals(32, new VersionNumber("2.32.3.1-SNAPSHOT").getDigitAt(1)); | ||
assertEquals(3, new VersionNumber("2.32.3.1-SNAPSHOT").getDigitAt(2)); | ||
assertEquals(1, new VersionNumber("2.32.3.1-SNAPSHOT").getDigitAt(3)); | ||
|
@@ -88,6 +113,28 @@ public void testDigit() { | |
assertEquals(-1, new VersionNumber("").getDigitAt(0)); | ||
} | ||
|
||
private void assertOrderAlsoInMaven(String... versions) { | ||
errors.checkThat("Maven order is correct", Stream.of(versions).map(ComparableVersion::new).sorted().map(ComparableVersion::toString).collect(Collectors.toList()), CoreMatchers.is(Arrays.asList(versions))); | ||
errors.checkThat("Jenkins order is correct", Stream.of(versions).map(VersionNumber::new).sorted().map(VersionNumber::toString).collect(Collectors.toList()), CoreMatchers.is(Arrays.asList(versions))); | ||
} | ||
|
||
@Ignore("TODO still pretty divergent: …was <[2.0.ea, 2.0.0, 2.0, 2.0.1-alpha-1, 2.0.1-SNAPSHOT, 2.0.*, 2.0.0.99, 2.0.1-alpha-1-rc9999.abc123def456, 2.0.1-rc9999.abc123def456, 2.0.1]>") | ||
@Issue("JENKINS-51594") | ||
@Test | ||
public void mavenComparison() { | ||
assertOrderAlsoInMaven("2.0.0", "2.0", "2.0.*", "2.0.ea", "2.0.0.99", "2.0.1-alpha-1-rc9999.abc123def456", "2.0.1-alpha-1", "2.0.1-rc9999.abc123def456", "2.0.1-SNAPSHOT", "2.0.1"); | ||
} | ||
|
||
@Issue("JEP-229") | ||
@Test | ||
public void backportJep229() { | ||
// Maven considers 99.1.abcd1234abcd to sort before 99.1234deadbeef so we cannot simply use 99. as the branch prefix. | ||
// Nor can we use 99.1234deadbeef. as the prefix because Maven would compare 5 and 10 lexicographically. | ||
// 100._. seems to work but is not intuitive. | ||
// Using changelist.format=%d.v%s behaves better, apparently because then the hash is never treated like a number. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
assertOrderAlsoInMaven("99.v1234deadbeef", "99.5.vabcd1234abcd", "99.10.vabcd1234abcd", "100.vdead9876beef"); | ||
} | ||
|
||
public void testOrEqualTo() { | ||
assertTrue(new VersionNumber("1.8").isNewerThanOrEqualTo(new VersionNumber("1.8"))); | ||
assertTrue(new VersionNumber("1.9").isNewerThanOrEqualTo(new VersionNumber("1.8"))); | ||
|
@@ -97,4 +144,5 @@ public void testOrEqualTo() { | |
assertTrue(new VersionNumber("1.7").isOlderThanOrEqualTo(new VersionNumber("1.8"))); | ||
assertTrue(new VersionNumber("1").isOlderThanOrEqualTo(new VersionNumber("1.8"))); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just so far off that I did not see how to rescue it. 2.0.1 < 2.0??