Skip to content

Instantly share code, notes, and snippets.

@h-east
Last active November 15, 2015 13:53
Show Gist options
  • Save h-east/6019b1c8b3a84a67d547 to your computer and use it in GitHub Desktop.
Save h-east/6019b1c8b3a84a67d547 to your computer and use it in GitHub Desktop.
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -1914,6 +1914,7 @@
test_erasebackword \
test_eval \
test_fixeol \
+ test_getcwd \
test_increment \
test_insertcount \
test_listchars \
diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak
--- a/src/testdir/Make_amiga.mak
+++ b/src/testdir/Make_amiga.mak
@@ -50,6 +50,7 @@
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
+ test_getcwd.out \
test_increment.out \
test_insertcount.out \
test_listchars.out \
@@ -206,6 +207,7 @@
test_eval.out: test_eval.in
test_increment.out: test_increment.in
test_fixeol.out: test_fixeol.in
+test_getcwd.out: test_getcwd.in
test_insertcount.out: test_insertcount.in
test_listchars.out: test_listchars.in
test_listlbr.out: test_listlbr.in
diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak
--- a/src/testdir/Make_dos.mak
+++ b/src/testdir/Make_dos.mak
@@ -49,6 +49,7 @@
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
+ test_getcwd.out \
test_increment.out \
test_insertcount.out \
test_listchars.out \
diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak
--- a/src/testdir/Make_ming.mak
+++ b/src/testdir/Make_ming.mak
@@ -71,6 +71,7 @@
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
+ test_getcwd.out \
test_increment.out \
test_insertcount.out \
test_listchars.out \
diff --git a/src/testdir/Make_os2.mak b/src/testdir/Make_os2.mak
--- a/src/testdir/Make_os2.mak
+++ b/src/testdir/Make_os2.mak
@@ -51,6 +51,7 @@
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
+ test_getcwd.out \
test_increment.out \
test_insertcount.out \
test_listchars.out \
diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms
--- a/src/testdir/Make_vms.mms
+++ b/src/testdir/Make_vms.mms
@@ -155,7 +155,7 @@
.ENDIF
.IFDEF WANT_UNIX
-SCRIPT_UNIX = test10.out test12.out test17.out test25.out test27.out test49.out test73.out
+SCRIPT_UNIX = test10.out test12.out test17.out test25.out test27.out test49.out test73.out test_getcwd.out
.ENDIF
.IFDEF WANT_WIN
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -47,6 +47,7 @@
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
+ test_getcwd.out \
test_increment.out \
test_insertcount.out \
test_listchars.out \
diff --git a/src/testdir/test_getcwd.in b/src/testdir/test_getcwd.in
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_getcwd.in
@@ -0,0 +1,101 @@
+Tests for getcwd(), haslocaldir(), and :lcd vim: set ft=vim :
+
+STARTTEST
+:so small.vim
+:" Do all test in a separate window to avoid E211 when we recursively
+:" delete the Xtopdir directory during cleanup
+:"
+:" This will cause a few errors, do it silently.
+:set visualbell
+:set nocp viminfo+=nviminfo
+:"
+:function! DeleteDirectory(dir)
+: if has("win16") || has("win32") || has("win64") || has("dos16") || has("dos32")
+: exec "silent !rmdir /Q /S " . a:dir
+: else
+: exec "silent !rm -rf " . a:dir
+: endif
+:endfun
+:"
+:function! GetCwdInfo(win, tab)
+: let tab_changed = 0
+: let mod = ":t"
+: if a:tab > 0 && a:tab != tabpagenr()
+: let tab_changed = 1
+: exec "tabnext " . a:tab
+: endif
+: let bufname = fnamemodify(bufname(winbufnr(a:win)), mod)
+: if tab_changed
+: tabprevious
+: endif
+: if a:win == 0 && a:tab == 0
+: let dirname = fnamemodify(getcwd(), mod)
+: let lflag = haslocaldir()
+: elseif a:tab == 0
+: let dirname = fnamemodify(getcwd(a:win), mod)
+: let lflag = haslocaldir(a:win)
+: else
+: let dirname = fnamemodify(getcwd(a:win, a:tab), mod)
+: let lflag = haslocaldir(a:win, a:tab)
+: endif
+: return bufname . ' ' . dirname . ' ' . lflag
+:endfunction
+:" On windows a stale "Xtopdir" directory may exist, remove it so that
+:" we start from a clean state.
+:call DeleteDirectory("Xtopdir")
+:let r=[]
+:new
+:let cwd=getcwd()
+:let test_out = cwd . '/test.out'
+:call mkdir('Xtopdir')
+:cd Xtopdir
+:call mkdir('Xdir1')
+:call mkdir('Xdir2')
+:call mkdir('Xdir3')
+:new a
+:new b
+:new c
+:3wincmd w
+:lcd Xdir1
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir3
+:call add(r, GetCwdInfo(0, 0))
+:call add(r, GetCwdInfo(bufwinnr("a"), 0))
+:call add(r, GetCwdInfo(bufwinnr("b"), 0))
+:call add(r, GetCwdInfo(bufwinnr("c"), 0))
+:wincmd W
+:call add(r, GetCwdInfo(bufwinnr("a"), tabpagenr()))
+:call add(r, GetCwdInfo(bufwinnr("b"), tabpagenr()))
+:call add(r, GetCwdInfo(bufwinnr("c"), tabpagenr()))
+:"
+:tabnew x
+:new y
+:new z
+:3wincmd w
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir2
+:call add(r, GetCwdInfo(0, 0))
+:wincmd W
+:lcd Xdir3
+:call add(r, GetCwdInfo(0, 0))
+:call add(r, GetCwdInfo(bufwinnr("x"), 0))
+:call add(r, GetCwdInfo(bufwinnr("y"), 0))
+:call add(r, GetCwdInfo(bufwinnr("z"), 0))
+:let tp_nr = tabpagenr()
+:tabrewind
+:call add(r, GetCwdInfo(3, tp_nr))
+:call add(r, GetCwdInfo(2, tp_nr))
+:call add(r, GetCwdInfo(1, tp_nr))
+:"
+:call writefile(r, test_out, "a")
+:q
+:exec "cd " . cwd
+:call DeleteDirectory("Xtopdir")
+:qa!
+ENDTEST
+
+
diff --git a/src/testdir/test_getcwd.ok b/src/testdir/test_getcwd.ok
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_getcwd.ok
@@ -0,0 +1,18 @@
+a Xdir1 1
+b Xtopdir 0
+c Xdir3 1
+a Xdir1 1
+b Xtopdir 0
+c Xdir3 1
+a Xdir1 1
+b Xtopdir 0
+c Xdir3 1
+x Xtopdir 0
+y Xdir2 1
+z Xdir3 1
+x Xtopdir 0
+y Xdir2 1
+z Xdir3 1
+x Xtopdir 0
+y Xdir2 1
+z Xdir3 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment