Use utf-8 encoding for child Vim in Test_terminal_dumpwrite_composing - #2847
Use utf-8 encoding for child Vim in Test_terminal_dumpwrite_composing#2847jamessan wants to merge 1 commit into
Conversation
The test is relying on the child Vim process to display the composed characters a certain way in order to test term_dumpwrite(). However, if the tests aren't running in a locale that defaults the child Vim's 'encoding' to utf-8, then the text will look different than expected (e.g. "a~@ e~B o~H"). Forcing the child Vim to use encoding=utf-8, just like the main Vim is doing, fixes the issue.
Codecov Report
@@ Coverage Diff @@
## master #2847 +/- ##
==========================================
- Coverage 75.4% 75.39% -0.01%
==========================================
Files 92 92
Lines 134738 134738
==========================================
- Hits 101593 101592 -1
- Misses 33145 33146 +1
Continue to review full report at Codecov.
|
|
As an aside, it wasn't very easy to see why this failed from a test log perspective. While I was trying to figure this out (since it was only replicating in automated builds), I used the following patch to get more information: diff --git i/src/testdir/test_terminal.vim w/src/testdir/test_terminal.vim
index 1b87895ac..bf31de9de 100644
--- i/src/testdir/test_terminal.vim
+++ w/src/testdir/test_terminal.vim
@@ -1026,7 +1026,11 @@ func Test_terminal_dumpwrite_composing()
let text = " a\u0300 e\u0302 o\u0308"
call writefile([text], 'Xcomposing')
let buf = RunVimInTerminal('Xcomposing', {})
- call WaitFor({-> term_getline(buf, 1) =~ text})
+ try
+ call WaitFor({-> term_getline(buf, 1) =~ text})
+ catch /WaitFor/
+ call assert_match(text, term_getline(buf, 1))
+ endtry
call term_dumpwrite(buf, 'Xdump')
let dumpline = readfile('Xdump')[0]
call assert_match('|à| |ê| |ö', dumpline)However, doing that everywhere is a lot of repetition. If the diff --git i/src/testdir/shared.vim w/src/testdir/shared.vim
index 6c3f8a4e6..6c8ac1f7b 100644
--- i/src/testdir/shared.vim
+++ w/src/testdir/shared.vim
@@ -132,7 +132,9 @@ func WaitFor(expr, ...)
else
let Test = {-> eval(a:expr) }
endif
+ let errors = copy(v:errors)
for i in range(timeout / 10)
+ let v:errors = errors
if Test()
if has('reltime')
return float2nr(reltimefloat(reltime(start)) * 1000)
diff --git i/src/testdir/test_terminal.vim w/src/testdir/test_terminal.vim
index 1b87895ac..e1aba9508 100644
--- i/src/testdir/test_terminal.vim
+++ w/src/testdir/test_terminal.vim
@@ -1026,7 +1026,7 @@ func Test_terminal_dumpwrite_composing()
let text = " a\u0300 e\u0302 o\u0308"
call writefile([text], 'Xcomposing')
let buf = RunVimInTerminal('Xcomposing', {})
- call WaitFor({-> term_getline(buf, 1) =~ text})
+ call WaitFor({-> assert_match(text, term_getline(buf, 1))})
call term_dumpwrite(buf, 'Xdump')
let dumpline = readfile('Xdump')[0]
call assert_match('|à| |ê| |ö', dumpline) |
|
James McCoy wrote:
As an aside, it wasn't very easy to see _why_ this failed from a test
log perspective. While I was trying to figure this out (since it was
only replicating in automated builds), I used the following patch to
get more information:
```diff
diff --git i/src/testdir/test_terminal.vim w/src/testdir/test_terminal.vim
index 1b87895ac..bf31de9de 100644
--- i/src/testdir/test_terminal.vim
+++ w/src/testdir/test_terminal.vim
@@ -1026,7 +1026,11 @@ func Test_terminal_dumpwrite_composing()
let text = " a\u0300 e\u0302 o\u0308"
call writefile([text], 'Xcomposing')
let buf = RunVimInTerminal('Xcomposing', {})
- call WaitFor({-> term_getline(buf, 1) =~ text})
+ try
+ call WaitFor({-> term_getline(buf, 1) =~ text})
+ catch /WaitFor/
+ call assert_match(text, term_getline(buf, 1))
+ endtry
call term_dumpwrite(buf, 'Xdump')
let dumpline = readfile('Xdump')[0]
call assert_match('|à| |ê| |ö', dumpline)
```
However, doing that everywhere is a lot of repetition. If the
`assert_*` functions returned distinct values when the assert passes
or fails, then it would be possible to directly use that in the
`WaitFor`. Something like:
```diff
diff --git i/src/testdir/shared.vim w/src/testdir/shared.vim
index 6c3f8a4e6..6c8ac1f7b 100644
--- i/src/testdir/shared.vim
+++ w/src/testdir/shared.vim
@@ -132,7 +132,11 @@ func WaitFor(expr, ...)
else
let Test = {-> eval(a:expr) }
endif
+ let errors = copy(v:errors)
for i in range(timeout / 10)
+ if v:errors != errors:
+ let v:errors = errors
+ endif
if Test()
if has('reltime')
return float2nr(reltimefloat(reltime(start)) * 1000)
diff --git i/src/testdir/test_terminal.vim w/src/testdir/test_terminal.vim
index 1b87895ac..e1aba9508 100644
--- i/src/testdir/test_terminal.vim
+++ w/src/testdir/test_terminal.vim
@@ -1026,7 +1026,7 @@ func Test_terminal_dumpwrite_composing()
let text = " a\u0300 e\u0302 o\u0308"
call writefile([text], 'Xcomposing')
let buf = RunVimInTerminal('Xcomposing', {})
- call WaitFor({-> term_getline(buf, 1) =~ text})
+ call WaitFor({-> assert_match(text, term_getline(buf, 1))})
call term_dumpwrite(buf, 'Xdump')
let dumpline = readfile('Xdump')[0]
call assert_match('|à| |ê| |ö', dumpline)
```
Ignoring an error from the function might hide a mistake.
The assert functions are not really setup for just checking. Would
require some "try but don't throw" argument, which doesn't make it
simpler.
We could add WaitForMatch(function, pattern), that would cover the most
common cases.
Or an argument to WaitFor() to not throw an exception but return, so the
assert can be after it (like we had earlier).
…--
Facepalm statement #6: "Estland is a fantasy place, just like Middle Earth and
Madagaskar"
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
The whole point of WaitFor is that the condition is expected to fail initially, so there's currently no reason to use an assert function inside. Anything that's using
The assert functions don't throw. They simply add to
There are currently a lot of calls that look like: call WaitFor({-> check condition})
" Use an assert_*() to check the same conditionThis code is useless because It would be more convenient to allow Given the above, I think letting |
|
James McCoy wrote:
> Ignoring an error from the function might hide a mistake.
The whole point of WaitFor is that the condition is _expected_ to fail
initially, so there's currently no reason to use an assert function
inside. Anything that's using `assert_*` inside of a `WaitFor()`
right now would be causing false positive test failures.
> The assert functions are not really setup for just checking. Would require some "try but don't throw" argument, which doesn't make it simpler.
The assert functions don't throw. They simply add to `v:errors` when
they fail. Enhancing them to return whether they succeed or fail
would help in this case.
> Or an argument to WaitFor() to not throw an exception but return, so the assert can be after it (like we had earlier).
There are currently a lot of calls that look like:
```vim
call WaitFor({-> check condition})
" Use an assert_*() to check the same condition
```
This code is useless because `WaitFor()` throws. The following assert
would never be called, which means we lose diagnostic information.
That's a leftover from when WaitFor() didn't throw an exception. These
should be removed.
It would be more convenient to allow `WaitFor()` to use `assert_*` so
it can actually report whatever caused the condition to fail, instead
of repeating checks.
Given the above, I think letting `assert_*()`'s return value return
whether the condition was true or not would be the simplest solution
and allow us to make `WaitFor()` more useful.
Hmm, OK. Some extra work is done to add an item to v:errors, which we
would then remove again. But that's not so bad.
An alternative would be to add an argument to the assert_ functions to
only check and not add to v:errors, but these functions already have
various arguments, thus that's not making it simpler.
We can make it so that when the assert_ function fails it always adds
exactly one entry to v:errors and returns non-zero.
…--
Microsoft's definition of a boolean: TRUE, FALSE, MAYBE
"Embrace and extend"...?
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
I wrote:
James McCoy wrote:
> > Ignoring an error from the function might hide a mistake.
>
> The whole point of WaitFor is that the condition is _expected_ to fail
> initially, so there's currently no reason to use an assert function
> inside. Anything that's using `assert_*` inside of a `WaitFor()`
> right now would be causing false positive test failures.
>
> > The assert functions are not really setup for just checking. Would require some "try but don't throw" argument, which doesn't make it simpler.
>
> The assert functions don't throw. They simply add to `v:errors` when
> they fail. Enhancing them to return whether they succeed or fail
> would help in this case.
>
> > Or an argument to WaitFor() to not throw an exception but return, so the assert can be after it (like we had earlier).
>
> There are currently a lot of calls that look like:
>
> ```vim
> call WaitFor({-> check condition})
> " Use an assert_*() to check the same condition
> ```
>
> This code is useless because `WaitFor()` throws. The following assert
> would never be called, which means we lose diagnostic information.
That's a leftover from when WaitFor() didn't throw an exception. These
should be removed.
> It would be more convenient to allow `WaitFor()` to use `assert_*` so
> it can actually report whatever caused the condition to fail, instead
> of repeating checks.
>
> Given the above, I think letting `assert_*()`'s return value return
> whether the condition was true or not would be the simplest solution
> and allow us to make `WaitFor()` more useful.
Hmm, OK. Some extra work is done to add an item to v:errors, which we
would then remove again. But that's not so bad.
An alternative would be to add an argument to the assert_ functions to
only check and not add to v:errors, but these functions already have
various arguments, thus that's not making it simpler.
We can make it so that when the assert_ function fails it always adds
exactly one entry to v:errors and returns non-zero.
With patch 8.0.1771 I made it work this way. I changed about half the
uses of WaitFor(). Does this look OK?
…--
GALAHAD turns back. We see from his POV the lovely ZOOT standing by him
smiling enchantingly and a number of equally delectable GIRLIES draped
around in the seductively poulticed room. They look at him smilingly and
wave.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
I'll test it out. Do you have any comment on the original issue in this PR? :) I know I side-tracked the discussion a little bit with the WaitFor stuff. |
|
James McCoy wrote:
> With patch 8.0.1771 I made it work this way. I changed about half the uses of WaitFor(). Does this look OK?
I'll test it out. Do you have any comment on the original issue in this PR? :) I know I side-tracked the discussion a little bit with the WaitFor stuff.
It's near the top of the todo list now.
May I'll finish the WaitFor change, otherwise I'll forget.
…--
TALL KNIGHT OF NI: Ni!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
…ding'
Problem: Test fails because Vim in a terminal uses wrong 'encoding'.
Solution: Set encoding in the test where it matters. (James McCoy,
closes vim#2847)
The test is relying on the child Vim process to display the composed
characters a certain way in order to test term_dumpwrite(). However, if
the tests aren't running in a locale that defaults the child Vim's
'encoding' to utf-8, then the text will look different than expected
(e.g.
a~@ e~B o~H).Forcing the child Vim to use encoding=utf-8, just like the main Vim is
doing, fixes the issue.