我正在爲Vim開發一個插件,我想在啓動時測試它的行爲,當用戶編輯文件e.t.c.如何將密鑰輸入到終端進行單元測試
要做到這一點,我想要啓動一個終端,並向它提供鍵。 我正在考慮從python腳本中完成所有操作。有沒有辦法做到這一點?
在僞蟒蛇可能是這個樣子:
#start a terminal. Here konsole
konsole = os.system('konsole --width=200 --height=150')
#start vim in that terminal
konsole.feed_keys("vim\n")
#run the vim function to be tested
konsole.feed_keys(":let my_list = MyVimFunction()\n")
#save the return value to the file system
konsole.feed_keys(":writefile(my_list, '/tmp/result')\n")
#load result into python
with open('/tmp/result', 'r') as myfile:
data = myfile.read()
#validate the result
assertEqual('expect result', data)
非常有用的答案。我已經接受了這個答案,因爲這更接近我決定要做的事情。 我把我所有的測試代碼放在一個.vimrc文件中,我將它複製到一個tempdir中。 然後我開始像這樣的vim: 'cd $ tmpdir && HOME =。 vim -X' 然後,我開始在vim8-timer上進行實際測試,因此在插件加載完成後。 – XPlatformer
謝謝,快樂測試;從一開始就係統地做這件事具有不可否認的好處!你的方法聽起來不錯;如果你不想依賴Vim版本8,你也可以使用':autocmd VimEnter * call StartTests()'來觸發它們。 –
與autocmd的絕妙主意,但劇本無論如何需要vim8 :-) – XPlatformer