Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Commit

Permalink
Fix STAGE_FLOAT to check if normal changed
Browse files Browse the repository at this point in the history
Fixes #210 by ensuring that the nearest any's normal is the same
as being inferred by the current build. If it is, then continue
checking precedence of preRelease, otherwise just use the float
stage on its own.
  • Loading branch information
ajoberstar committed Sep 18, 2016
1 parent 9872de2 commit f6cc4c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ final class Strategies {
* to the nearest any's pre-release.
*/
static final PartialSemVerStrategy STAGE_FLOAT = closure { state ->
def nearestPreRelease = state.nearestVersion.any.preReleaseVersion
if (nearestPreRelease != null && nearestPreRelease > state.stageFromProp) {
state.copyWith(inferredPreRelease: "${nearestPreRelease}.${state.stageFromProp}")
def sameNormal = state.inferredNormal == state.nearestVersion.any.normalVersion
def nearestAnyPreRelease = state.nearestVersion.any.preReleaseVersion
if (sameNormal && nearestAnyPreRelease != null && nearestAnyPreRelease > state.stageFromProp) {
state.copyWith(inferredPreRelease: "${nearestAnyPreRelease}.${state.stageFromProp}")
} else {
state.copyWith(inferredPreRelease: state.stageFromProp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,20 @@ class StrategiesSpec extends Specification {
given:
def initialState = new SemVerStrategyState(
stageFromProp: 'boom',
inferredNormal: '1.1.0',
inferredPreRelease: 'other',
nearestVersion: new NearestVersion(any: Version.valueOf(nearest)))
nearestVersion: new NearestVersion(
normal: Version.valueOf('1.0.0'),
any: Version.valueOf(nearest)))
expect:
Strategies.PreRelease.STAGE_FLOAT.infer(initialState) == initialState.copyWith(inferredPreRelease: expected)
where:
nearest | expected
'1.0.0' | 'boom'
'1.0.0-and.1' | 'boom'
'1.0.0-cat.1' | 'cat.1.boom'
'1.0.0-cat.something.else' | 'cat.something.else.boom'
'1.0.1-cat.something.else' | 'boom'
'1.1.0-and.1' | 'boom'
'1.1.0-cat.1' | 'cat.1.boom'
'1.1.0-cat.something.else' | 'cat.something.else.boom'
}

def 'PreRelease.COUNT_INCREMENTED will increment the nearest any\'s pre release or set to 1 if not found'() {
Expand Down

0 comments on commit f6cc4c5

Please sign in to comment.