Skip to content

Commit

Permalink
allegro#662 add test to reproduce useHighestVersion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
duschata committed Jan 11, 2024
1 parent 3b9c860 commit f96230b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package pl.allegro.tech.build.axion.release
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner


class BaseIntegrationTest extends RepositoryBasedTest {

File buildFile() {
return new FileTreeBuilder(temporaryFolder).file("build.gradle","")
}

File newFile(String name) {
return new FileTreeBuilder(temporaryFolder).file(name,"")
File newFile(String name, String contents = "") {
return new FileTreeBuilder(temporaryFolder).file(name, contents)
}

void buildFile(String contents) {
Expand All @@ -23,6 +24,11 @@ class BaseIntegrationTest extends RepositoryBasedTest {
"""
project.version = scmVersion.version
scmVersion {
release {
useHighestVersion = true
}
}
""")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.allegro.tech.build.axion.release

import org.eclipse.jgit.api.Git
import org.gradle.testkit.runner.TaskOutcome

import static pl.allegro.tech.build.axion.release.TagPrefixConf.*
Expand Down Expand Up @@ -132,6 +133,37 @@ class HighestVersionIntegrationTest extends BaseIntegrationTest {
result.task(":currentVersion").outcome == TaskOutcome.SUCCESS
}

def "should return tag with highest version if an unmerged branch tags a higher version and useHighestVersion is set to true"() {
given:
buildFile('')
newFile(".gitignore", ".gradle")

Git git = repository.getJgitRepository();
git.add().addFilepattern('.').call()
git.commit().setMessage("init").call()
runGradle('release', '-Prelease.version=1.0.0', '-Prelease.localOnly', '-Prelease.disableChecks')


git.checkout().setCreateBranch(true).setName("unmergedBranch").call()
newFile("changeUnmergedBranch")
git.add().addFilepattern('.').call()
git.commit().setMessage("commit after unmergedBranch has changed").call()
runGradle('release', '-Prelease.version=1.1.0', '-Prelease.localOnly', '-Prelease.disableChecks')

git.checkout().setName("master").call()
newFile("changeMasterBranch")
git.add().addFilepattern('.').call()
git.commit().setMessage("commit after master has changed").call()

when:
def result = runGradle('currentVersion')

then:
result.output.contains('1.1.1-SNAPSHOT') // what we really get is 1.0.1-SNAPSHOT
result.task(":currentVersion").outcome == TaskOutcome.SUCCESS
}


def "should return alpha tag if useHighestVersion is set to true"() {
given:
buildFile('')
Expand Down

0 comments on commit f96230b

Please sign in to comment.