thinca / vim-themis

A testing framework for Vim script.
zlib License
238 stars 34 forks source link

timer コールバックの呼び出し順番がひっくり返る #53

Closed lambdalisue closed 6 years ago

lambdalisue commented 6 years ago

以下のコードを themis 経由で呼ぶか普通に :source % で実行するかで aX の順番が変わります。

try
  let s:suite = themis#suite('timer test')
  let s:assert = themis#helper('assert')
catch
  let s:suite = {}
endtry

function! s:suite.test() abort
  let rs = []
  call timer_start(0, { -> add(rs, 'a1') })
  call timer_start(0, { -> add(rs, 'a2') })
  call timer_start(0, { -> add(rs, 'a3') })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b1') }) })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b2') }) })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b3') }) })
  sleep 100m
  call s:assert.equals(rs, ['a1', 'a2', 'a3', 'b1', 'b2', 'b3'])
endfunction

function! s:not_themis() abort
  let rs = []
  call timer_start(0, { -> add(rs, 'a1') })
  call timer_start(0, { -> add(rs, 'a2') })
  call timer_start(0, { -> add(rs, 'a3') })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b1') }) })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b2') }) })
  call timer_start(0, { -> timer_start(0, { -> add(rs, 'b3') }) })
  sleep 100m
  call themis#log(string(rs))
endfunction

call s:not_themis()
$ themis test.vim
['a3', 'a2', 'a1', 'b1', 'b2', 'b3']
1..1
not ok 1 - timer test test
# The equivalent values were expected, but it was not the case.
#
#     expected: ['a1', 'a2', 'a3', 'b1', 'b2', 'b3']
#          got: ['a3', 'a2', 'a1', 'b1', 'b2', 'b3']

# tests 1
# passes 0
# fails 1
:QuickRun

['a1', 'a2', 'a3', 'b1', 'b2', 'b3']
*** time: 0.14395 ***
lambdalisue commented 6 years ago

:QuickRun だとひっくり返らないのは Neovim だからだ!お騒がせしますた。