Skip to content

Commit cb0cd91

Browse files
authored
Merge pull request #33819 from JuliaLang/sf/repl_realpath
Fix `realpath()` assumptions in REPL test suite
2 parents f196d3f + baa6efd commit cb0cd91

File tree

2 files changed

+42
-43
lines changed

2 files changed

+42
-43
lines changed

base/client.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,9 @@ function repl_cmd(cmd, out)
4949
if !haskey(ENV, "OLDPWD")
5050
error("cd: OLDPWD not set")
5151
end
52-
cd(ENV["OLDPWD"])
53-
else
54-
@static if !Sys.iswindows()
55-
# TODO: this is a rather expensive way to copy a string, remove?
56-
# If it's intended to simulate `cd`, it should instead be doing
57-
# more nearly `cd $dir && printf %s \$PWD` (with appropriate quoting),
58-
# since shell `cd` does more than just `echo` the result.
59-
dir = read(`$shell -c "printf '%s' $(shell_escape_posixly(dir))"`, String)
60-
end
61-
cd(dir)
52+
dir = ENV["OLDPWD"]
6253
end
54+
cd(dir)
6355
else
6456
cd()
6557
end

stdlib/REPL/test/repl.jl

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,45 +107,52 @@ fake_repl() do stdin_write, stdout_read, repl
107107
# Test cd feature in shell mode.
108108
origpwd = pwd()
109109
mktempdir() do tmpdir
110-
# Test `cd`'ing to an absolute path
111-
write(stdin_write, ";")
112-
readuntil(stdout_read, "shell> ")
113-
write(stdin_write, "cd $(escape_string(tmpdir))\n")
114-
readuntil(stdout_read, "cd $(escape_string(tmpdir))")
115-
readuntil(stdout_read, realpath(tmpdir))
116-
readuntil(stdout_read, "\n")
117-
readuntil(stdout_read, "\n")
118-
@test pwd() == realpath(tmpdir)
119-
120-
# Test using `cd` to move to the home directory
121-
write(stdin_write, ";")
122-
readuntil(stdout_read, "shell> ")
123-
write(stdin_write, "cd\n")
124-
readuntil(stdout_read, realpath(homedir()))
125-
readuntil(stdout_read, "\n")
126-
readuntil(stdout_read, "\n")
127-
@test pwd() == realpath(homedir())
110+
try
111+
samefile = Base.Filesystem.samefile
112+
tmpdir_pwd = cd(pwd, tmpdir)
113+
homedir_pwd = cd(pwd, homedir())
128114

129-
# Test using `-` to jump backward to tmpdir
130-
write(stdin_write, ";")
131-
readuntil(stdout_read, "shell> ")
132-
write(stdin_write, "cd -\n")
133-
readuntil(stdout_read, tmpdir)
134-
readuntil(stdout_read, "\n")
135-
readuntil(stdout_read, "\n")
136-
@test pwd() == realpath(tmpdir)
137-
138-
# Test using `~` in `cd` commands
139-
if !Sys.iswindows()
115+
# Test `cd`'ing to an absolute path
140116
write(stdin_write, ";")
141117
readuntil(stdout_read, "shell> ")
142-
write(stdin_write, "cd ~\n")
143-
readuntil(stdout_read, realpath(homedir()))
118+
write(stdin_write, "cd $(escape_string(tmpdir))\n")
119+
readuntil(stdout_read, "cd $(escape_string(tmpdir))")
120+
readuntil(stdout_read, tmpdir_pwd)
121+
readuntil(stdout_read, "\n")
144122
readuntil(stdout_read, "\n")
123+
@test samefile(".", tmpdir)
124+
125+
# Test using `cd` to move to the home directory
126+
write(stdin_write, ";")
127+
readuntil(stdout_read, "shell> ")
128+
write(stdin_write, "cd\n")
129+
readuntil(stdout_read, homedir_pwd)
145130
readuntil(stdout_read, "\n")
146-
@test pwd() == realpath(homedir())
131+
readuntil(stdout_read, "\n")
132+
@test samefile(".", homedir_pwd)
133+
134+
# Test using `-` to jump backward to tmpdir
135+
write(stdin_write, ";")
136+
readuntil(stdout_read, "shell> ")
137+
write(stdin_write, "cd -\n")
138+
readuntil(stdout_read, tmpdir_pwd)
139+
readuntil(stdout_read, "\n")
140+
readuntil(stdout_read, "\n")
141+
@test samefile(".", tmpdir)
142+
143+
# Test using `~` (Base.expanduser) in `cd` commands
144+
if !Sys.iswindows()
145+
write(stdin_write, ";")
146+
readuntil(stdout_read, "shell> ")
147+
write(stdin_write, "cd ~\n")
148+
readuntil(stdout_read, homedir_pwd)
149+
readuntil(stdout_read, "\n")
150+
readuntil(stdout_read, "\n")
151+
@test samefile(".", homedir_pwd)
152+
end
153+
finally
154+
cd(origpwd)
147155
end
148-
cd(origpwd)
149156
end
150157

151158
# issue #20482

0 commit comments

Comments
 (0)