Skip to content

Commit

Permalink
Merge pull request #33819 from JuliaLang/sf/repl_realpath
Browse files Browse the repository at this point in the history
Fix `realpath()` assumptions in REPL test suite
  • Loading branch information
staticfloat authored Nov 14, 2019
2 parents f196d3f + baa6efd commit cb0cd91
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
12 changes: 2 additions & 10 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ function repl_cmd(cmd, out)
if !haskey(ENV, "OLDPWD")
error("cd: OLDPWD not set")
end
cd(ENV["OLDPWD"])
else
@static if !Sys.iswindows()
# TODO: this is a rather expensive way to copy a string, remove?
# If it's intended to simulate `cd`, it should instead be doing
# more nearly `cd $dir && printf %s \$PWD` (with appropriate quoting),
# since shell `cd` does more than just `echo` the result.
dir = read(`$shell -c "printf '%s' $(shell_escape_posixly(dir))"`, String)
end
cd(dir)
dir = ENV["OLDPWD"]
end
cd(dir)
else
cd()
end
Expand Down
73 changes: 40 additions & 33 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,52 @@ fake_repl() do stdin_write, stdout_read, repl
# Test cd feature in shell mode.
origpwd = pwd()
mktempdir() do tmpdir
# Test `cd`'ing to an absolute path
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd $(escape_string(tmpdir))\n")
readuntil(stdout_read, "cd $(escape_string(tmpdir))")
readuntil(stdout_read, realpath(tmpdir))
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test pwd() == realpath(tmpdir)

# Test using `cd` to move to the home directory
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd\n")
readuntil(stdout_read, realpath(homedir()))
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test pwd() == realpath(homedir())
try
samefile = Base.Filesystem.samefile
tmpdir_pwd = cd(pwd, tmpdir)
homedir_pwd = cd(pwd, homedir())

# Test using `-` to jump backward to tmpdir
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd -\n")
readuntil(stdout_read, tmpdir)
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test pwd() == realpath(tmpdir)

# Test using `~` in `cd` commands
if !Sys.iswindows()
# Test `cd`'ing to an absolute path
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd ~\n")
readuntil(stdout_read, realpath(homedir()))
write(stdin_write, "cd $(escape_string(tmpdir))\n")
readuntil(stdout_read, "cd $(escape_string(tmpdir))")
readuntil(stdout_read, tmpdir_pwd)
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test samefile(".", tmpdir)

# Test using `cd` to move to the home directory
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd\n")
readuntil(stdout_read, homedir_pwd)
readuntil(stdout_read, "\n")
@test pwd() == realpath(homedir())
readuntil(stdout_read, "\n")
@test samefile(".", homedir_pwd)

# Test using `-` to jump backward to tmpdir
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd -\n")
readuntil(stdout_read, tmpdir_pwd)
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test samefile(".", tmpdir)

# Test using `~` (Base.expanduser) in `cd` commands
if !Sys.iswindows()
write(stdin_write, ";")
readuntil(stdout_read, "shell> ")
write(stdin_write, "cd ~\n")
readuntil(stdout_read, homedir_pwd)
readuntil(stdout_read, "\n")
readuntil(stdout_read, "\n")
@test samefile(".", homedir_pwd)
end
finally
cd(origpwd)
end
cd(origpwd)
end

# issue #20482
Expand Down

0 comments on commit cb0cd91

Please sign in to comment.