From da1edb862467ef88e6fd209c3bfbda791f23d702 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 20 Sep 2023 22:34:56 -0700 Subject: [PATCH] test: add rudimentary smoke tests to check for errors --- lua/github-theme/_test/util.lua | 21 +++++++++++++ test/github-theme/smoketest/startup_spec.lua | 33 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 lua/github-theme/_test/util.lua create mode 100644 test/github-theme/smoketest/startup_spec.lua diff --git a/lua/github-theme/_test/util.lua b/lua/github-theme/_test/util.lua new file mode 100644 index 00000000..8bc18690 --- /dev/null +++ b/lua/github-theme/_test/util.lua @@ -0,0 +1,21 @@ +local M = {} +local api = vim.api + +function M.await_VimEnter() + if vim.v.vim_did_enter == 0 then + local co = assert(coroutine.running(), 'test is not running in coroutine') + + api.nvim_create_autocmd('VimEnter', { + pattern = '*', + once = true, + nested = true, + callback = vim.schedule_wrap(function() + coroutine.resume(co) + end), + }) + + coroutine.yield() + end +end + +return M diff --git a/test/github-theme/smoketest/startup_spec.lua b/test/github-theme/smoketest/startup_spec.lua new file mode 100644 index 00000000..601d30d5 --- /dev/null +++ b/test/github-theme/smoketest/startup_spec.lua @@ -0,0 +1,33 @@ +local assert = require('luassert') +local t_util = require('github-theme._test.util') + +describe('(smoke test)', function() + describe('setting colorscheme during startup', function() + it('should not error', function() + assert.does_not_error(function() + vim.cmd('colorscheme github_dark_dimmed') + end) + + assert.is.equal('', vim.v.errmsg or '') + end) + end) + + describe('setting/switching colorscheme post-startup', function() + it('should not error', function() + t_util.await_VimEnter() + + for _, cs in ipairs({ + 'default', + 'github_dark_dimmed', + 'github_dark_dimmed', + 'github_light', + }) do + assert.does_not_error(function() + vim.cmd('colorscheme ' .. cs) + end) + + assert.is.equal('', vim.v.errmsg or '') + end + end) + end) +end)