Mercurial > vim
comparison src/testdir/test_autocmd.vim @ 34790:1104d85c7dcc v9.1.0269
patch 9.1.0269: Test for TextChanged is still flaky with ASAN
Commit: https://github.com/vim/vim/commit/e9ff79a7c9affea970f50de2aa65f62080b55323
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri Apr 5 20:07:39 2024 +0200
patch 9.1.0269: Test for TextChanged is still flaky with ASAN
Problem: Test for TextChanged is still flaky with ASAN.
Solution: Don't index the result of readfile().
(zeertzjq)
It turns out that with ASAN the file may become empty during a write
even if it's non-empty both before and after the write, in which case
indexing the result of readfile() will error, so use join() instead.
Also don't delete the file halfway the test, just in case it may cause
errors on the next read.
closes: #14421
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 05 Apr 2024 20:15:06 +0200 |
parents | 3d063c753d40 |
children | f9b510d3ed32 |
comparison
equal
deleted
inserted
replaced
34789:7512fa13de08 | 34790:1104d85c7dcc |
---|---|
4493 let buf = term_start( | 4493 let buf = term_start( |
4494 \ GetVimCommandCleanTerm() .. '-n -S Xinit XTextChangedI2', | 4494 \ GetVimCommandCleanTerm() .. '-n -S Xinit XTextChangedI2', |
4495 \ {'term_rows': 10}) | 4495 \ {'term_rows': 10}) |
4496 call assert_equal('running', term_getstatus(buf)) | 4496 call assert_equal('running', term_getstatus(buf)) |
4497 call WaitForAssert({-> assert_true(filereadable('XTextChangedI3'))}) | 4497 call WaitForAssert({-> assert_true(filereadable('XTextChangedI3'))}) |
4498 defer delete('XTextChangedI3') | |
4498 call WaitForAssert({-> assert_equal([''], readfile('XTextChangedI3'))}) | 4499 call WaitForAssert({-> assert_equal([''], readfile('XTextChangedI3'))}) |
4499 | 4500 |
4500 " TextChanged should trigger if a mapping enters and leaves Insert mode. | 4501 " TextChanged should trigger if a mapping enters and leaves Insert mode. |
4501 call term_sendkeys(buf, "\<CR>") | 4502 call term_sendkeys(buf, "\<CR>") |
4502 call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')[0])}) | 4503 call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')->join("\n"))}) |
4503 | 4504 |
4504 call term_sendkeys(buf, "i") | 4505 call term_sendkeys(buf, "i") |
4505 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) | 4506 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) |
4506 call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')[0])}) | 4507 call WaitForAssert({-> assert_equal('N4,', readfile('XTextChangedI3')->join("\n"))}) |
4507 " TextChangedI should trigger if change is done in Insert mode. | 4508 " TextChangedI should trigger if change is done in Insert mode. |
4508 call term_sendkeys(buf, "f") | 4509 call term_sendkeys(buf, "f") |
4509 call WaitForAssert({-> assert_equal('N4,I5', readfile('XTextChangedI3')[0])}) | 4510 call WaitForAssert({-> assert_equal('N4,I5', readfile('XTextChangedI3')->join("\n"))}) |
4510 call term_sendkeys(buf, "o") | 4511 call term_sendkeys(buf, "o") |
4511 call WaitForAssert({-> assert_equal('N4,I6', readfile('XTextChangedI3')[0])}) | 4512 call WaitForAssert({-> assert_equal('N4,I6', readfile('XTextChangedI3')->join("\n"))}) |
4512 call term_sendkeys(buf, "o") | 4513 call term_sendkeys(buf, "o") |
4513 call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')[0])}) | 4514 call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')->join("\n"))}) |
4514 " TextChanged shouldn't trigger when leaving Insert mode and TextChangedI | 4515 " TextChanged shouldn't trigger when leaving Insert mode and TextChangedI |
4515 " has been triggered. | 4516 " has been triggered. |
4516 call term_sendkeys(buf, "\<Esc>") | 4517 call term_sendkeys(buf, "\<Esc>") |
4517 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) | 4518 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) |
4518 call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')[0])}) | 4519 call WaitForAssert({-> assert_equal('N4,I7', readfile('XTextChangedI3')->join("\n"))}) |
4519 | 4520 |
4520 " TextChanged should trigger if change is done in Normal mode. | 4521 " TextChanged should trigger if change is done in Normal mode. |
4521 call term_sendkeys(buf, "yyp") | 4522 call term_sendkeys(buf, "yyp") |
4522 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')[0])}) | 4523 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))}) |
4523 | 4524 |
4524 " TextChangedI shouldn't trigger if change isn't done in Insert mode. | 4525 " TextChangedI shouldn't trigger if change isn't done in Insert mode. |
4525 call term_sendkeys(buf, "i") | 4526 call term_sendkeys(buf, "i") |
4526 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) | 4527 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) |
4527 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')[0])}) | 4528 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))}) |
4528 call term_sendkeys(buf, "\<Esc>") | 4529 call term_sendkeys(buf, "\<Esc>") |
4529 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) | 4530 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) |
4530 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')[0])}) | 4531 call WaitForAssert({-> assert_equal('N8,I7', readfile('XTextChangedI3')->join("\n"))}) |
4531 | 4532 |
4532 " TextChangedI should trigger if change is a mix of Normal and Insert modes. | 4533 " TextChangedI should trigger if change is a mix of Normal and Insert modes. |
4533 func! s:validate_mixed_textchangedi(buf, keys) | 4534 func! s:validate_mixed_textchangedi(buf, keys) |
4534 let buf = a:buf | 4535 let buf = a:buf |
4535 call term_sendkeys(buf, "ifoo") | 4536 call term_sendkeys(buf, "ifoo") |
4536 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) | 4537 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) |
4537 call term_sendkeys(buf, "\<Esc>") | 4538 call term_sendkeys(buf, "\<Esc>") |
4538 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) | 4539 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) |
4539 call term_sendkeys(buf, ":let [g:autocmd_n, g:autocmd_i] = ['', '']\<CR>") | 4540 call term_sendkeys(buf, ":let [g:autocmd_n, g:autocmd_i] = ['', '']\<CR>") |
4540 call delete('XTextChangedI3') | 4541 call writefile([], 'XTextChangedI3') |
4541 call term_sendkeys(buf, a:keys) | 4542 call term_sendkeys(buf, a:keys) |
4542 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) | 4543 call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 10))}) |
4543 call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')[0])}) | 4544 call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')->join("\n"))}) |
4544 call term_sendkeys(buf, "\<Esc>") | 4545 call term_sendkeys(buf, "\<Esc>") |
4545 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) | 4546 call WaitForAssert({-> assert_notmatch('^-- INSERT --', term_getline(buf, 10))}) |
4546 call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')[0])}) | 4547 call WaitForAssert({-> assert_match('^,I\d\+', readfile('XTextChangedI3')->join("\n"))}) |
4547 endfunc | 4548 endfunc |
4548 | 4549 |
4549 call s:validate_mixed_textchangedi(buf, "o") | 4550 call s:validate_mixed_textchangedi(buf, "o") |
4550 call s:validate_mixed_textchangedi(buf, "O") | 4551 call s:validate_mixed_textchangedi(buf, "O") |
4551 call s:validate_mixed_textchangedi(buf, "ciw") | 4552 call s:validate_mixed_textchangedi(buf, "ciw") |
4554 call s:validate_mixed_textchangedi(buf, "s") | 4555 call s:validate_mixed_textchangedi(buf, "s") |
4555 call s:validate_mixed_textchangedi(buf, "S") | 4556 call s:validate_mixed_textchangedi(buf, "S") |
4556 | 4557 |
4557 " clean up | 4558 " clean up |
4558 bwipe! | 4559 bwipe! |
4559 call delete('XTextChangedI3') | |
4560 endfunc | 4560 endfunc |
4561 | 4561 |
4562 " Test that filetype detection still works when SwapExists autocommand sets | 4562 " Test that filetype detection still works when SwapExists autocommand sets |
4563 " filetype in another buffer. | 4563 " filetype in another buffer. |
4564 func Test_SwapExists_set_other_buf_filetype() | 4564 func Test_SwapExists_set_other_buf_filetype() |