I’m stuck on Stage #RA6.
I’ve tried to reproduce what the tester says manually running my program but I haven’t had any luck.
Here are my logs:
[tester::#RA6] Running tests for Stage #RA6 (Navigation - The cd builtin: Absolute paths)
[tester::#RA6] Running ./your_program.sh
[your-program] $ cd /tmp/apple/strawberry/mango
[tester::#RA6] Output does not match expected value.
[tester::#RA6] Expected: "$ pwd"
[tester::#RA6] Received: "pwd"
[your-program] pwd
[your-program] $ /tmp/apple/strawberry/mango
[your-program] $
[tester::#RA6] Assertion failed.
[tester::#RA6] Test failed
And here’s a snippet of my code:
fun main() {
val shellState = ShellState(
currentDirectory = File(System.getProperty("user.dir")).canonicalFile,
environmentVariables = mutableMapOf(
EnvVar.PATH to (System.getenv("PATH") ?: ""),
EnvVar.HOME to (System.getProperty("user.home") ?: "/")
)
)
do {
print("$ ")
val userInput = readln()
val splitUserInput = userInput.split(" ")
val command = splitUserInput[0]
val args = if (splitUserInput.size > 1) splitUserInput.subList(1, splitUserInput.size) else emptyList()
val builtin = BuiltinCommand.fromCommand(command)
if (builtin != null) {
handleBuiltinCommand(builtin, args, shellState)
} else {
executeExternalCommand(command, args, shellState)
}
} while (true)
}
fun changeDirectory(shellState: ShellState, newPath: String) {
val targetDirectory = if (newPath.startsWith("/")) {
File(newPath)
} else {
File(shellState.currentDirectory, newPath)
}
if (targetDirectory.exists() && targetDirectory.isDirectory) {
shellState.currentDirectory = targetDirectory.canonicalFile
} else {
println("cd: $newPath: No such file or directory: $newPath")
}
}