diff --git a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy index a64646f4..4c08b2b3 100644 --- a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy +++ b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy @@ -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()