add test for reinitializing after reset PATH

This commit is contained in:
Dylan Cali
2015-10-10 10:56:53 -05:00
committed by Marco Vermeulen
parent 3bd5333835
commit b83c551995

View File

@@ -88,6 +88,74 @@ class InitialisationSpec extends Specification {
missingCandidates.isEmpty()
}
void "should reinitialize candidates in PATH if necessary"() {
given: 'a working sdkman installation with many candidates'
def allCandidates = [
"asciidoctorj",
"crash",
"gaiden",
"glide",
"gradle",
"grails",
"griffon",
"groovy",
"groovyserv",
"jbake",
"jbossforge",
"lazybones",
"springboot",
"vertx"
]
bash = SdkManBashEnvBuilder
.create(sdkmanBaseDir)
.withAvailableCandidates(allCandidates)
.withCandidates(allCandidates)
.withCurlStub(curlStub)
.withVersionToken("x.y.z")
.build()
and:
allCandidates.forEach {
def current = Paths.get("$sdkmanDotDir/$it/current")
def targetFilename = "$sdkmanDotDir/$it/xxx"
new File(targetFilename).createNewFile()
def target = Paths.get(targetFilename)
Files.createSymbolicLink(current, target)
}
bash.start()
bash.execute("source $bootstrap")
bash.resetOutput()
when: 're-sourcing bootstrap after resetting PATH'
// reset path and re-init
def origPath = bash.env.grep { it =~ /^PATH=/ }
bash.execute(origPath)
bash.execute("source $bootstrap")
bash.execute('echo $PATH')
def pathParts = bash.output.split(':')
def pathElementMatcher = ~/$sdkmanDotDir\/([^\/]+)\/.*/
def includedCandidates = pathParts
.collect { it.replace("\n", "")}
.collect { it =~ pathElementMatcher }
.findAll { it }
.collect { it[0][1] }
.sort()
println("Available: $allCandidates")
println("Included : $includedCandidates")
and:
def missingCandidates = allCandidates - includedCandidates
then:
missingCandidates.isEmpty()
}
void cleanup(){
println bash.output
bash.stop()