annotate src/testdir/test_source.vim @ 19145:ea3ac1de7704 v8.2.0132

patch 8.2.0132: script may be re-used when deleting and creating a new one Commit: https://github.com/vim/vim/commit/ca33eb256eb910af05e8c9852bc9f716cece1f5c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 19 20:18:09 2020 +0100 patch 8.2.0132: script may be re-used when deleting and creating a new one Problem: Script may be re-used when deleting and creating a new one. Solution: When the inode matches, also check the file name.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jan 2020 20:30:04 +0100
parents 8d91579414b8
children 9efea787c3a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15442
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Tests for the :source command.
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 func Test_source_autocmd()
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 call writefile([
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 \ 'let did_source = 1',
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 \ ], 'Xsourced')
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 au SourcePre *source* let did_source_pre = 1
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 au SourcePost *source* let did_source_post = 1
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 source Xsourced
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 call assert_equal(g:did_source, 1)
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 call assert_equal(g:did_source_pre, 1)
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 call assert_equal(g:did_source_post, 1)
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 call delete('Xsourced')
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 au! SourcePre
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 au! SourcePost
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 unlet g:did_source
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 unlet g:did_source_pre
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 unlet g:did_source_post
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 endfunc
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 func Test_source_cmd()
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 au SourceCmd *source* let did_source = expand('<afile>')
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 au SourcePre *source* let did_source_pre = 2
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 au SourcePost *source* let did_source_post = 2
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 source Xsourced
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 call assert_equal(g:did_source, 'Xsourced')
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 call assert_false(exists('g:did_source_pre'))
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 call assert_equal(g:did_source_post, 2)
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 au! SourceCmd
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 au! SourcePre
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 au! SourcePost
3e2e1608efa4 patch 8.1.0729: there is a SourcePre autocommand event but not a SourcePost
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 endfunc
16726
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
39
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
40 func Test_source_sandbox()
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
41 new
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
42 call writefile(["Ohello\<Esc>"], 'Xsourcehello')
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
43 source! Xsourcehello | echo
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
44 call assert_equal('hello', getline(1))
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
45 call assert_fails('sandbox source! Xsourcehello', 'E48:')
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
46 bwipe!
16920
8d91579414b8 patch 8.1.1461: tests do not run or are not reliable on some systems
Bram Moolenaar <Bram@vim.org>
parents: 16726
diff changeset
47 call delete('Xsourcehello')
16726
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
48 endfunc
19145
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
49
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
50 " When deleting a file and immediately creating a new one the inode may be
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
51 " recycled. Vim should not recognize it as the same script.
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
52 func Test_different_script()
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
53 call ch_logfile('logfile', 'w')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
54 call writefile(['let s:var = "asdf"'], 'XoneScript')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
55 source XoneScript
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
56 call delete('XoneScript')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
57 call writefile(['let g:var = s:var'], 'XtwoScript')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
58 call assert_fails('source XtwoScript', 'E121:')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
59 call delete('XtwoScript')
ea3ac1de7704 patch 8.2.0132: script may be re-used when deleting and creating a new one
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
60 endfunc