Mercurial > vim
annotate src/testdir/test_expand_func.vim @ 21493:7449921216bc v8.2.1297
patch 8.2.1297: when a test fails it's often not easy to see where
Commit: https://github.com/vim/vim/commit/a5d0423fa16f18b4576a2a07e50034e489587a7d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 26 15:37:02 2020 +0200
patch 8.2.1297: when a test fails it's often not easy to see where
Problem: When a test fails it's often not easy to see what the call stack
is.
Solution: Add more entries from the call stack in the exception message.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 26 Jul 2020 15:45:04 +0200 |
parents | 546bdeef35f1 |
children | 5daca8504c63 |
rev | line source |
---|---|
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Tests for expand() |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 let s:sfile = expand('<sfile>') |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 let s:slnum = str2nr(expand('<slnum>')) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 let s:sflnum = str2nr(expand('<sflnum>')) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 func s:expand_sfile() |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 return expand('<sfile>') |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 endfunc |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 func s:expand_slnum() |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 return str2nr(expand('<slnum>')) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 endfunc |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 func s:expand_sflnum() |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 return str2nr(expand('<sflnum>')) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 endfunc |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
19 " This test depends on the location in the test file, put it first. |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
20 func Test_expand_sflnum() |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
21 call assert_equal(5, s:sflnum) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
22 call assert_equal(22, str2nr(expand('<sflnum>'))) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
23 |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
24 " Line-continuation |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
25 call assert_equal( |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
26 \ 25, |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
27 \ str2nr(expand('<sflnum>'))) |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 " Call in script-local function |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
30 call assert_equal(16, s:expand_sflnum()) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
31 |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
32 " Call in command |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
33 command Flnum echo expand('<sflnum>') |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
34 call assert_equal(34, str2nr(trim(execute('Flnum')))) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
35 delcommand Flnum |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
36 endfunc |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
37 |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
38 func Test_expand_sfile_and_stack() |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
39 call assert_match('test_expand_func\.vim$', s:sfile) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
40 let expected = 'script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$' |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
41 call assert_match(expected , expand('<sfile>')) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
42 call assert_match(expected , expand('<stack>')) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
43 |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
44 " Call in script-local function |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
45 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack\[7\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile()) |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 " Call in command |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 command Sfile echo expand('<sfile>') |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
49 call assert_match('script .*testdir/runtest.vim\[\d\+\]\.\.function RunTheTest\[\d\+\]\.\.Test_expand_sfile_and_stack$', trim(execute('Sfile'))) |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 delcommand Sfile |
21493
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
51 |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
52 " Use <stack> from sourced script. |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
53 let lines =<< trim END |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
54 let g:stack_value = expand('<stack>') |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
55 END |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
56 call writefile(lines, 'Xstack') |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
57 source Xstack |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
58 call assert_match('\<Xstack$', g:stack_value) |
7449921216bc
patch 8.2.1297: when a test fails it's often not easy to see where
Bram Moolenaar <Bram@vim.org>
parents:
19783
diff
changeset
|
59 call delete('Xstack') |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 endfunc |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 func Test_expand_slnum() |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 call assert_equal(4, s:slnum) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 call assert_equal(2, str2nr(expand('<slnum>'))) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 " Line-continuation |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 call assert_equal( |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 \ 5, |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 \ str2nr(expand('<slnum>'))) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
70 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
71 " Call in script-local function |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 call assert_equal(1, s:expand_slnum()) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 " Call in command |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 command Slnum echo expand('<slnum>') |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 call assert_equal(14, str2nr(trim(execute('Slnum')))) |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 delcommand Slnum |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 endfunc |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 |
16668
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
80 func Test_expand() |
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
81 new |
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
82 call assert_equal("", expand('%:S')) |
17849
73ddc462979d
patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
16668
diff
changeset
|
83 call assert_equal('3', '<slnum>'->expand()) |
16668
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
84 call assert_equal(['4'], expand('<slnum>', v:false, v:true)) |
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
85 " Don't add any line above this, otherwise <slnum> will change. |
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
86 quit |
81be817c9d9a
patch 8.1.1336: some eval functionality is not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
87 endfunc |
19603
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
88 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
89 " Test for 'wildignore' with expand() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
90 func Test_expand_wildignore() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
91 set wildignore=*.vim |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
92 call assert_equal('', expand('test_expand_func.vim')) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
93 call assert_equal('', expand('test_expand_func.vim', 0)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
94 call assert_equal([], expand('test_expand_func.vim', 0, 1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
95 call assert_equal('test_expand_func.vim', expand('test_expand_func.vim', 1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
96 call assert_equal(['test_expand_func.vim'], |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
97 \ expand('test_expand_func.vim', 1, 1)) |
19783
546bdeef35f1
patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
19603
diff
changeset
|
98 call assert_fails("call expand('*', [])", 'E745:') |
19603
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
99 set wildignore& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
100 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
101 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
17849
diff
changeset
|
102 " vim: shiftwidth=2 sts=2 expandtab |