Mercurial > vim
comparison src/testdir/test_cd.vim @ 18568:26a04a556982 v8.1.2278
patch 8.1.2278: using "cd" with "exe" may fail
Commit: https://github.com/vim/vim/commit/3503d7c94a6c8c2a5ca1665d648d0cb81afcc863
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 9 20:10:17 2019 +0100
patch 8.1.2278: using "cd" with "exe" may fail
Problem: Using "cd" with "exe" may fail.
Solution: Use chdir() instead.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 09 Nov 2019 20:15:04 +0100 |
parents | 4935244c1128 |
children | 5bef1043abff |
comparison
equal
deleted
inserted
replaced
18567:ed3a8eb92f76 | 18568:26a04a556982 |
---|---|
7 | 7 |
8 func Test_cd_up_and_down() | 8 func Test_cd_up_and_down() |
9 let path = getcwd() | 9 let path = getcwd() |
10 cd .. | 10 cd .. |
11 call assert_notequal(path, getcwd()) | 11 call assert_notequal(path, getcwd()) |
12 exe 'cd ' . path | 12 exe 'cd ' .. fnameescape(path) |
13 call assert_equal(path, getcwd()) | 13 call assert_equal(path, getcwd()) |
14 endfunc | 14 endfunc |
15 | 15 |
16 func Test_cd_no_arg() | 16 func Test_cd_no_arg() |
17 if has('unix') | 17 if has('unix') |
18 " Test that cd without argument goes to $HOME directory on Unix systems. | 18 " Test that cd without argument goes to $HOME directory on Unix systems. |
19 let path = getcwd() | 19 let path = getcwd() |
20 cd | 20 cd |
21 call assert_equal($HOME, getcwd()) | 21 call assert_equal($HOME, getcwd()) |
22 call assert_notequal(path, getcwd()) | 22 call assert_notequal(path, getcwd()) |
23 exe 'cd ' . path | 23 exe 'cd ' .. fnameescape(path) |
24 call assert_equal(path, getcwd()) | 24 call assert_equal(path, getcwd()) |
25 else | 25 else |
26 " Test that cd without argument echoes cwd on non-Unix systems. | 26 " Test that cd without argument echoes cwd on non-Unix systems. |
27 call assert_match(getcwd(), execute('cd')) | 27 call assert_match(getcwd(), execute('cd')) |
28 endif | 28 endif |
56 cd! .. | 56 cd! .. |
57 call assert_notequal(path, getcwd()) | 57 call assert_notequal(path, getcwd()) |
58 | 58 |
59 " :cd should succeed when buffer has been written. | 59 " :cd should succeed when buffer has been written. |
60 w! | 60 w! |
61 exe 'cd ' . path | 61 exe 'cd ' .. fnameescape(path) |
62 call assert_equal(path, getcwd()) | 62 call assert_equal(path, getcwd()) |
63 | 63 |
64 call delete('Xfoo') | 64 call delete('Xfoo') |
65 set cpo& | 65 set cpo& |
66 bw! | 66 bw! |
101 call assert_fails("call chdir('dir-abcd')", 'E472:') | 101 call assert_fails("call chdir('dir-abcd')", 'E472:') |
102 silent! let d = chdir("dir_abcd") | 102 silent! let d = chdir("dir_abcd") |
103 call assert_equal("", d) | 103 call assert_equal("", d) |
104 | 104 |
105 only | tabonly | 105 only | tabonly |
106 exe 'cd ' . topdir | 106 call chdir(topdir) |
107 call delete('Xdir', 'rf') | 107 call delete('Xdir', 'rf') |
108 endfunc | 108 endfunc |