Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 1 | " Tests for exiting Vim. |
| 2 | |
| 3 | source shared.vim |
Bram Moolenaar | ca0c1ca | 2022-02-22 12:08:07 +0000 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 5 | |
| 6 | func Test_exiting() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 7 | let after =<< trim [CODE] |
| 8 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 9 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 10 | quit |
| 11 | [CODE] |
| 12 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 13 | if RunVim([], after, '') |
| 14 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 15 | endif |
| 16 | call delete('Xtestout') |
| 17 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 18 | let after =<< trim [CODE] |
| 19 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 20 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 21 | help |
| 22 | wincmd w |
| 23 | quit |
| 24 | [CODE] |
| 25 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 26 | if RunVim([], after, '') |
| 27 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 28 | endif |
| 29 | call delete('Xtestout') |
| 30 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 31 | let after =<< trim [CODE] |
| 32 | au QuitPre * call writefile(["QuitPre"], "Xtestout") |
| 33 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 34 | split |
| 35 | new |
| 36 | qall |
| 37 | [CODE] |
| 38 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 39 | if RunVim([], after, '') |
| 40 | call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) |
| 41 | endif |
| 42 | call delete('Xtestout') |
| 43 | |
Bram Moolenaar | 34ba06b | 2019-10-20 22:27:10 +0200 | [diff] [blame] | 44 | " ExitPre autocommand splits the window, so that it's no longer the last one. |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 45 | let after =<< trim [CODE] |
| 46 | au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") |
| 47 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 48 | augroup nasty |
| 49 | au ExitPre * split |
| 50 | augroup END |
| 51 | quit |
| 52 | augroup nasty |
| 53 | au! ExitPre |
| 54 | augroup END |
| 55 | quit |
| 56 | [CODE] |
| 57 | |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 58 | if RunVim([], after, '') |
| 59 | call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], |
| 60 | \ readfile('Xtestout')) |
| 61 | endif |
| 62 | call delete('Xtestout') |
Bram Moolenaar | 34ba06b | 2019-10-20 22:27:10 +0200 | [diff] [blame] | 63 | |
| 64 | " ExitPre autocommand splits and closes the window, so that there is still |
| 65 | " one window but it's a different one. |
| 66 | let after =<< trim [CODE] |
| 67 | au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") |
| 68 | au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") |
| 69 | augroup nasty |
| 70 | au ExitPre * split | only |
| 71 | augroup END |
| 72 | quit |
| 73 | augroup nasty |
| 74 | au! ExitPre |
| 75 | augroup END |
| 76 | quit |
| 77 | [CODE] |
| 78 | |
| 79 | if RunVim([], after, '') |
| 80 | call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], |
| 81 | \ readfile('Xtestout')) |
| 82 | endif |
| 83 | call delete('Xtestout') |
Bram Moolenaar | 12a96de | 2018-03-11 14:44:18 +0100 | [diff] [blame] | 84 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 85 | |
Bram Moolenaar | f0068c5 | 2020-11-30 17:42:10 +0100 | [diff] [blame] | 86 | " Test for getting the Vim exit code from v:exiting |
| 87 | func Test_exit_code() |
| 88 | call assert_equal(v:null, v:exiting) |
| 89 | |
| 90 | let before =<< trim [CODE] |
| 91 | au QuitPre * call writefile(['qp = ' .. v:exiting], 'Xtestout', 'a') |
| 92 | au ExitPre * call writefile(['ep = ' .. v:exiting], 'Xtestout', 'a') |
| 93 | au VimLeavePre * call writefile(['lp = ' .. v:exiting], 'Xtestout', 'a') |
| 94 | au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout', 'a') |
| 95 | [CODE] |
| 96 | |
| 97 | if RunVim(before, ['quit'], '') |
| 98 | call assert_equal(['qp = v:null', 'ep = v:null', 'lp = 0', 'l = 0'], readfile('Xtestout')) |
| 99 | endif |
| 100 | call delete('Xtestout') |
| 101 | |
| 102 | if RunVim(before, ['cquit'], '') |
| 103 | call assert_equal(['lp = 1', 'l = 1'], readfile('Xtestout')) |
| 104 | endif |
| 105 | call delete('Xtestout') |
| 106 | |
| 107 | if RunVim(before, ['cquit 4'], '') |
| 108 | call assert_equal(['lp = 4', 'l = 4'], readfile('Xtestout')) |
| 109 | endif |
| 110 | call delete('Xtestout') |
| 111 | endfunc |
| 112 | |
Bram Moolenaar | ca0c1ca | 2022-02-22 12:08:07 +0000 | [diff] [blame] | 113 | func Test_exit_error_reading_input() |
| 114 | CheckNotGui |
Bram Moolenaar | 29a9e69 | 2022-02-22 18:48:11 +0000 | [diff] [blame] | 115 | CheckNotMSWindows |
Bram Moolenaar | 68eab67 | 2022-02-22 17:42:48 +0000 | [diff] [blame] | 116 | " The early exit causes memory not to be freed somehow |
| 117 | CheckNotAsan |
Bram Moolenaar | cf801d4 | 2022-06-21 18:34:42 +0100 | [diff] [blame] | 118 | CheckNotValgrind |
Bram Moolenaar | ca0c1ca | 2022-02-22 12:08:07 +0000 | [diff] [blame] | 119 | |
Bram Moolenaar | 68eab67 | 2022-02-22 17:42:48 +0000 | [diff] [blame] | 120 | call writefile([":au VimLeave * call writefile(['l = ' .. v:exiting], 'Xtestout')", ":tabnew", "q:"], 'Xscript', 'b') |
Bram Moolenaar | ca0c1ca | 2022-02-22 12:08:07 +0000 | [diff] [blame] | 121 | |
Bram Moolenaar | 68eab67 | 2022-02-22 17:42:48 +0000 | [diff] [blame] | 122 | if RunVim([], [], '<Xscript') |
zeertzjq | 6a8b136 | 2022-02-23 12:23:08 +0000 | [diff] [blame] | 123 | call assert_equal(1, v:shell_error) |
Bram Moolenaar | ca0c1ca | 2022-02-22 12:08:07 +0000 | [diff] [blame] | 124 | call assert_equal(['l = 1'], readfile('Xtestout')) |
| 125 | endif |
| 126 | call delete('Xscript') |
| 127 | call delete('Xtestout') |
| 128 | endfun |
| 129 | |
| 130 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 131 | " vim: shiftwidth=2 sts=2 expandtab |