summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_import.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2024-04-20 18:31:21 +0200
committerChristian Brabandt <cb@256bit.org>2024-04-20 18:31:21 +0200
commitf135fa28e481b2eba73baf52b08d24add5c4fe8b (patch)
tree646542a459b5b3876845570b7a7c77c7a18783ea /src/testdir/test_vim9_import.vim
parent8927c9b720135610a1193999d29be76927b05ab3 (diff)
patch 9.1.0359: MS-Windows: relative import in a script sourced from a buffer doesn't workv9.1.0359
Problem: MS-Windows: Relative import in a script sourced from a buffer doesn't work (Ernie Rael) Solution: Set a filename, so that we are not trying to use script-relative filename (Yegappan Lakshmanan) When a script is sourced from a buffer, the file name is set to ":source buffer=". In MS-Windows, the ":" is a path separator character (used after a drive letter). This results in the code trying to use the ":" prefix to import the script on MS-Windows. To fix this, when importing a script from a script sourced from a buffer with nofile, don't use a script relative path name. fixes #14588 closes: #14603 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/testdir/test_vim9_import.vim')
-rw-r--r--src/testdir/test_vim9_import.vim42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim
index b7902f10c0..78383ee79b 100644
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -1140,13 +1140,9 @@ def Test_autoload_import_relative()
v9.CheckScriptFailure(lines, 'E484:')
enddef
+" autoload relative, access from compiled function.
+" Github issues: #14565, #14579
def Test_autoload_import_relative_compiled_buffer()
- if !has('unix')
- # temporary, until it's discovered why the test fails on Windows.
- CheckUnix
- return
- endif
- # autoload relative, access from compiled function. #14565, #14579
var lines =<< trim END
vim9script
@@ -1168,6 +1164,40 @@ def Test_autoload_import_relative_compiled_buffer()
new
setline(1, lines)
:source
+ # source one more time to detect issues with clearing the script state and
+ # variables
+ :source
+ :bw!
+enddef
+
+" Test for relative import when sourcing a buffer in another directory
+def Test_autoload_import_relative_from_buffer_in_dir()
+ mkdir('Ximportrelative/dir1/dir2', 'pR')
+ var lines =<< trim END
+ vim9script
+
+ export def F1(): string
+ return 'InFile.vim'
+ enddef
+ END
+ writefile(lines, 'Ximportrelative/dir1/dir2/Ximport.vim')
+ lines =<< trim END
+ vim9script
+
+ import autoload './Ximport.vim' as xfile
+
+ def F(): string
+ return xfile.F1()
+ enddef
+ assert_equal('InFile.vim', F())
+ END
+ writefile(lines, 'Ximportrelative/dir1/dir2/Xrelative.vim')
+
+ split Ximportrelative/dir1/dir2/Xrelative.vim
+ :source
+ # source one more time to detect issues with clearing the script state and
+ # variables
+ :source
:bw!
enddef