neovim/neovim — pull request #1287 by fwalch (2014-10-13 13:23:31+00:00)
Title: [RFC] Add legacy test conversion script.

I originally wanted to post this as a comment to #1286, but I suppose even if all legacy tests are converted at some point, new ones will be added because of upstream patches. Therefore it might be helpful to have this in the repository.

The output is not indented etc, but it can serve as a starting point for a proper spec.

`./scripts/legacy2luatest.sh src/nvim/testdir/test1.in test/functional/legacy` (written to `test/functional/legacy/test1_spec.lua`):
```lua
-- First a simple test to check if the test script works.
-- If Vim was not compiled with the +eval feature, the small.vim script will be
-- set to copy the test.ok file to test.out, so that it looks like the test
-- succeeded. Otherwise an empty small.vim is written. small.vim is sourced by
-- tests that require the +eval feature or other features that are missing in the
-- small version.
-- If Vim was not compiled with the +windows feature, the tiny.vim script will be
-- set like small.vim above. tiny.vim is sourced by tests that require the
-- +windows feature or other features that are missing in the tiny version.
-- If Vim was not compiled with the +multi_byte feature, the mbyte.vim script will
-- be set like small.vim above. mbyte.vim is sourced by tests that require the
-- +multi_byte feature.
-- Similar logic is applied to the +mzscheme feature, using mzscheme.vim.
-- Similar logic is applied to the +lua feature, using lua.vim.

local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect

describe('test1', function()
setup(clear)

it('is working', function()
-- If columns or lines are too small, create wrongtermsize.
-- (Some tests will fail. When columns and/or lines are small)
feed(':if &lines < 24 || &columns < 80 | sp another | w! wrongtermsize | qa! | endif')

-- Write a single line to test.out to check if testing works at all.
feed(':%d')
feed('athis is a test^[:w! test.out')
-- Create small.vim and tiny.vim empty, create mbyte.vim to skip the test.
feed('0D:w! small.vim')
feed(':w! tiny.vim')
feed('ae! test.ok')
feed('w! test.out')
feed('qa!')
feed('^[:w! mbyte.vim')
feed(':w! mzscheme.vim')
feed(':w! lua.vim')

-- If +multi_byte feature supported, make mbyte.vim empty.
feed(':if has("multi_byte") | sp another | w! mbyte.vim | q | endif')

-- If +mzscheme feature supported, make mzscheme.vim empty.
feed(':if has("mzscheme") | sp another | w! mzscheme.vim | q | endif')

-- If +lua feature supported, make lua.vim empty.
feed(':if has("lua") | sp another | w! lua.vim | q | endif')

-- If +eval feature supported quit here, leaving tiny.vim and small.vim empty.
-- Otherwise write small.vim to skip the test.
feed(':if 1 | q! | endif')
feed(':w! small.vim')
-- If +windows feature not supported :sp will fail and tiny.vim will be
-- written to skip the test.
feed(':sp another')
feed(':wq! tiny.vim')
feed(':qa!')

-- The buffer should now contain:
expect([[this is a test]])
end)
end)
```