gopath_test.vim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. fun! Test_Detect_Gopath() abort
  2. let l:gopath = $GOPATH
  3. try
  4. let g:go_autodetect_gopath = 1
  5. let l:tmp = go#util#tempdir("pathdetect")
  6. let l:tmp2 = go#util#tempdir("pathdetect-nogodep")
  7. call mkdir(l:tmp . '/subdir', 'p')
  8. call mkdir(l:tmp . '/Godeps/_workspace', 'p')
  9. exe ':e ' . l:tmp . '/a.go'
  10. call assert_equal(l:tmp . '/Godeps/_workspace:' . l:gopath, $GOPATH)
  11. exe ':e ' . l:tmp . '/not-a-go-file'
  12. call assert_equal(l:gopath, $GOPATH)
  13. exe ':e ' . l:tmp . '/subdir/a.go'
  14. call assert_equal(l:tmp . '/Godeps/_workspace:' . l:gopath, $GOPATH)
  15. exec ':e ' . l:tmp2 . '/a.go'
  16. call assert_equal(l:gopath, $GOPATH)
  17. finally
  18. let g:go_autodetect_gopath = 0
  19. call delete(l:tmp, 'rf')
  20. call delete(l:tmp2, 'rf')
  21. endtry
  22. endfun
  23. fun! Test_Detect_Gopath_disabled() abort
  24. let l:gopath = $GOPATH
  25. try
  26. let g:go_autodetect_gopath = 0
  27. let l:tmp = go#util#tempdir("pathdetect")
  28. let l:tmp2 = go#util#tempdir("pathdetect-nogodep")
  29. call mkdir(l:tmp . '/subdir', 'p')
  30. call mkdir(l:tmp . '/Godeps/_workspace', 'p')
  31. exe ':e ' . l:tmp . '/a.go'
  32. call assert_equal(l:gopath, $GOPATH)
  33. exe ':e ' . l:tmp . '/not-a-go-file'
  34. call assert_equal(l:gopath, $GOPATH)
  35. exe ':e ' . l:tmp . '/subdir/a.go'
  36. call assert_equal(l:gopath, $GOPATH)
  37. exec ':e ' . l:tmp2 . '/a.go'
  38. call assert_equal(l:gopath, $GOPATH)
  39. finally
  40. let g:go_autodetect_gopath = 0
  41. call delete(l:tmp, 'rf')
  42. call delete(l:tmp2, 'rf')
  43. endtry
  44. endfun