annotate src/testdir/test_source.vim @ 16726:fbab59a5ee6b v8.1.1365

patch 8.1.1365: source command doesn't check for the sandbox commit https://github.com/vim/vim/commit/53575521406739cf20bbe4e384d88e7dca11f040 Author: Bram Moolenaar <Bram@vim.org> Date: Wed May 22 22:38:25 2019 +0200 patch 8.1.1365: source command doesn't check for the sandbox Problem: Source command doesn't check for the sandbox. (Armin Razmjou) Solution: Check for the sandbox when sourcing a file.
author Bram Moolenaar <Bram@vim.org>
date Wed, 22 May 2019 22:45:05 +0200
parents 3e2e1608efa4
children 8d91579414b8
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!
fbab59a5ee6b patch 8.1.1365: source command doesn't check for the sandbox
Bram Moolenaar <Bram@vim.org>
parents: 15442
diff changeset
47 endfunc