Skip to content

Commit

Permalink
feat(tests): added support for Quick framework + optimized refreshing…
Browse files Browse the repository at this point in the history
… test results (#111)
  • Loading branch information
wojciech-kulik authored Mar 25, 2024
1 parent cba6ead commit 4ebfd0a
Show file tree
Hide file tree
Showing 15 changed files with 573 additions and 55 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ It provides all essential actions for development, including building, launching
- [x] [nvim-dap] integration to let you easily build, run, and debug apps.
- [x] [nvim-dap-ui] integration to show app logs in the console window.
- [x] [lualine.nvim] integration to show selected device, test plan, and other project settings.
- [x] [Quick] integration to show test results for tests written using [Quick] framework.
- [x] Auto-detection of the target membership for new files.
- [x] Picker with all available plugin actions.
- [x] Highly customizable (many config options, auto commands, highlights, and user commands).
Expand Down Expand Up @@ -58,6 +59,7 @@ https://github.com/wojciech-kulik/xcodebuild.nvim/assets/3128467/ed7d2d2e-eaa4-4
- [nui.nvim] to present floating code coverage report.
- [nvim-tree] or [oil.nvim] to visually manage your project files.
- [nvim-dap] and [nvim-dap-ui] to debug apps.
- [nvim-treesitter] + Swift parser to show test results for tests written using [Quick] framework.

##### External tools

Expand Down Expand Up @@ -104,6 +106,7 @@ return {
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-tree.lua", -- (optional) to manage project files
"stevearc/oil.nvim", -- (optional) to manage project files
"nvim-treesitter/nvim-treesitter", -- (optional) for Quick tests support (required Swift parser)
},
config = function()
require("xcodebuild").setup({
Expand Down Expand Up @@ -363,7 +366,6 @@ vim.keymap.set("n", "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", { desc = "Sh
failure_sign = "", -- failed test icon
show_test_duration = true, -- show each test duration next to its declaration
show_diagnostics = true, -- add test failures to diagnostics
file_pattern = "*Tests.swift", -- test diagnostics will be loaded in files matching this pattern (if available)
},
quickfix = {
show_errors_on_quickfixlist = true, -- add build/test errors to quickfix list
Expand Down Expand Up @@ -419,6 +421,9 @@ vim.keymap.set("n", "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", { desc = "Sh
return true
end,
},
quick = { -- integration with Swift test framework: github.com/Quick/Quick
enabled = true, -- enable Quick tests support (requires Swift parser for nvim-treesitter)
},
},
highlights = {
-- you can override here any highlight group used by this plugin
Expand Down Expand Up @@ -829,6 +834,7 @@ and run `xcode-build-server config` again.
[oil.nvim]: https://github.com/stevearc/oil.nvim
[nvim-dap]: https://github.com/mfussenegger/nvim-dap
[nvim-dap-ui]: https://github.com/rcarriga/nvim-dap-ui
[nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter
[nui.nvim]: https://github.com/MunifTanjim/nui.nvim
[telescope.nvim]: https://github.com/nvim-telescope/telescope.nvim
[neovim]: https://neovim.io
Expand All @@ -846,5 +852,6 @@ and run `xcode-build-server config` again.
[tips-and-tricks]: https://github.com/wojciech-kulik/xcodebuild.nvim/discussions/categories/tips-tricks
[ios-guide]: https://wojciechkulik.pl/ios/the-complete-guide-to-ios-macos-development-in-neovim
[ios-dev-starter-nvim]: https://github.com/wojciech-kulik/ios-dev-starter-nvim
[swift-snapshot-testing]: https://github.com/pointfreeco/swift-snapshot-testing
[test-file-search]: https://github.com/wojciech-kulik/xcodebuild.nvim/discussions/41
[swift-snapshot-testing]: https://github.com/pointfreeco/swift-snapshot-testing
[Quick]: https://github.com/Quick/Quick
113 changes: 105 additions & 8 deletions doc/xcodebuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Remote Debugger Integration ·········· |xcodebuild.integrations.remote
LSP Integration ·································· |xcodebuild.integrations.lsp|
nvim-tree Integration ······················ |xcodebuild.integrations.nvim_tree|
oil.nvim Integration ························ |xcodebuild.integrations.oil-nvim|
Quick Test Framework Integration ··············· |xcodebuild.integrations.quick|
xcode-build-server Integration ···· |xcodebuild.integrations.xcode-build-server|
Pickers ················································ |xcodebuild.ui.pickers|
Helpers ··················································· |xcodebuild.helpers|
Expand Down Expand Up @@ -125,7 +126,6 @@ M.setup({options}) *xcodebuild.setup*
failure_sign = "✖", -- failed test icon
show_test_duration = true, -- show each test duration next to its declaration
show_diagnostics = true, -- add test failures to diagnostics
file_pattern = "*Tests.swift", -- test diagnostics will be loaded in files matching this pattern (if available)
},
quickfix = {
show_errors_on_quickfixlist = true, -- add build/test errors to quickfix list
Expand Down Expand Up @@ -181,6 +181,9 @@ M.setup({options}) *xcodebuild.setup*
return true
end,
},
quick = { -- integration with Swift test framework: github.com/Quick/Quick
enabled = true, -- enable Quick tests support (requires Swift parser for nvim-treesitter)
},
},
highlights = {
-- you can override here any highlight group used by this plugin
Expand Down Expand Up @@ -213,6 +216,7 @@ Features *xcodebuild.features*
- `nvim-dap` integration to let you easily build, run, and debug apps.
- `nvim-dap-ui` integration to show app logs in the console window.
- `lualine.nvim` integration to show selected device, test plan,
- `Quick` integration to show test results for tests written using `Quick` framework.
and other project settings.
- Auto-detection of the target membership for new files.
- Picker with all available plugin actions.
Expand Down Expand Up @@ -250,7 +254,8 @@ Neovim environment
- `telescope.nvim` to present pickers.
- `nui.nvim` to present floating code coverage report.
- `nvim-tree` or `oil.nvim` to visually manage your project files.
- `nvim-dap` and nvim-dap-ui to debug apps.
- `nvim-dap` and `nvim-dap-ui` to debug apps.
- `nvim-treesitter` + Swift parser to show test results for tests written using `Quick` framework.

External tools
- `xcbeautify` to format Xcode logs (you can set a different tool or disable formatting in the config).
Expand Down Expand Up @@ -2537,10 +2542,6 @@ Test Diagnostics *xcodebuild.tests.diagnostics*

This module is responsible for handling diagnostics and marks for test files.

M.setup() *xcodebuild.tests.diagnostics.setup*
Set up highlights for tests.


*xcodebuild.tests.diagnostics.refresh_test_buffer*
M.refresh_test_buffer({bufnr}, {report})
Refreshes the diagnostics and marks for the given buffer.
Expand All @@ -2553,9 +2554,25 @@ M.refresh_test_buffer({bufnr}, {report})
|xcodebuild.xcode_logs.parser.ParsedReport|


*xcodebuild.tests.diagnostics.refresh_test_buffer_by_name*
M.refresh_test_buffer_by_name({name}, {report})
Refreshes diagnostics and marks for the test buffer with the given name.

It implements a debounce mechanism to avoid refreshing
the same buffer multiple times.The window is 1 second.

Note: this function will affect the buffer after 1 second.
To refresh the buffer instantly use `refresh_test_buffer`.


Parameters: ~
{name} (string)
{report} (ParsedReport)


*xcodebuild.tests.diagnostics.refresh_all_test_buffers*
M.refresh_all_test_buffers({report})
Refreshes the diagnostics and marks for all test buffers.
Refreshes diagnostics and marks for all test buffers.

Parameters: ~
{report} (ParsedReport)
Expand All @@ -2564,6 +2581,18 @@ M.refresh_all_test_buffers({report})
|xcodebuild.xcode_logs.parser.ParsedReport|


M.clear() *xcodebuild.tests.diagnostics.clear*
Clears marks and diagnostics.


M.clear_marks() *xcodebuild.tests.diagnostics.clear_marks*
Clears marks.


M.setup() *xcodebuild.tests.diagnostics.setup*
Set up highlights for tests.


==============================================================================
Test Enumeration Parser *xcodebuild.tests.enumeration_parser*

Expand Down Expand Up @@ -3429,6 +3458,72 @@ M.setup() *xcodebuild.integrations.oil-nvim.setup*
|xcodebuild.project-manager|


==============================================================================
Quick Test Framework Integration *xcodebuild.integrations.quick*

This module is responsible for parsing tests written using `Quick` framework.

It provides functions to get a list of `Quick` tests and their locations.

Note: it requires the Swift parser to be installed (using `nvim-treesitter`).

See: https://github.com/Quick/Quick


QuickTest *xcodebuild.integrations.quick.QuickTest*

Fields: ~
{id} (string) test id (matching xcodebuild test name)
{row} (number) 1-based row number


*xcodebuild.integrations.quick.find_quick_tests*
M.find_quick_tests({bufnr})
Returns a list of tests and their locations.

The result is a table where keys are test ids and values are `QuickTest` objects.

Each test represents a single test case (e.g. `it` block).


Parameters: ~
{bufnr} (number)

Returns: ~
(table<string,QuickTest>|nil)


*xcodebuild.integrations.quick.contains_quick_tests*
M.contains_quick_tests({bufnr})
Returns whether the given buffer contains Quick tests.

It checks if the buffer contains a subclass of `QuickSpec` or
if there is `import Quick`.

Parameters: ~
{bufnr} (number)

Returns: ~
(boolean)


*xcodebuild.integrations.quick.is_swift_parser_installed*
M.is_swift_parser_installed()
Returns whether the Swift parser is installed.

It caches the result for future calls.

Returns: ~
(boolean)


M.is_enabled() *xcodebuild.integrations.quick.is_enabled*
Returns whether the Quick integration is enabled.

Returns: ~
(boolean)


==============================================================================
xcode-build-server Integration *xcodebuild.integrations.xcode-build-server*

Expand Down Expand Up @@ -3651,7 +3746,7 @@ M.is_not_empty({table}) *xcodebuild.util.is_not_empty*

M.get_buffers({opts}) *xcodebuild.util.get_buffers*
Gets all buffers in the current neovim instance.
If `opts.returnNotLoaded` is true, it will
If {opts.returnNotLoaded} is true, it will
return all buffers, including the ones that are not loaded.

Parameters: ~
Expand Down Expand Up @@ -3695,6 +3790,7 @@ M.get_buf_by_filename({filename}, {opts})

M.get_buf_by_name({name}) *xcodebuild.util.get_buf_by_name*
Gets a buffer by its name.
Returns also buffers that are not loaded.

Parameters: ~
{name} (string)
Expand All @@ -3705,6 +3801,7 @@ M.get_buf_by_name({name}) *xcodebuild.util.get_buf_by_name*

M.get_buf_by_filetype({filetype}) *xcodebuild.util.get_buf_by_filetype*
Gets a buffer by its filetype.
Returns also buffers that are not loaded.

Parameters: ~
{filetype} (string)
Expand Down
16 changes: 13 additions & 3 deletions lua/xcodebuild/core/autocmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ function M.setup()
if config.marks.show_diagnostics or config.marks.show_signs then
vim.api.nvim_create_autocmd({ "BufReadPost" }, {
group = autogroup,
pattern = config.marks.file_pattern,
pattern = "*.swift",
callback = function(ev)
if projectConfig.is_project_configured() then
diagnostics.refresh_test_buffer(ev.buf, appdata.report)
if projectConfig.is_project_configured() and appdata.report and appdata.report.tests then
local filepath = vim.api.nvim_buf_get_name(ev.buf)

-- refresh diagnostics if the file is in the report
for _, testClass in pairs(appdata.report.tests) do
for _, test in ipairs(testClass) do
if test.filepath == filepath then
diagnostics.refresh_test_buffer(ev.buf, appdata.report)
break
end
end
end
end
end,
})
Expand Down
4 changes: 3 additions & 1 deletion lua/xcodebuild/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ local defaults = {
failure_sign = "", -- failed test icon
show_test_duration = true, -- show each test duration next to its declaration
show_diagnostics = true, -- add test failures to diagnostics
file_pattern = "*Tests.swift", -- test diagnostics will be loaded in files matching this pattern (if available)
},
quickfix = {
show_errors_on_quickfixlist = true, -- add build/test errors to quickfix list
Expand Down Expand Up @@ -120,6 +119,9 @@ local defaults = {
return true
end,
},
quick = { -- integration with Swift test framework: github.com/Quick/Quick
enabled = true, -- enable Quick tests support (requires Swift parser for nvim-treesitter)
},
},
highlights = {
-- you can override here any highlight group used by this plugin
Expand Down
1 change: 1 addition & 0 deletions lua/xcodebuild/docs/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
--- - `nvim-dap` integration to let you easily build, run, and debug apps.
--- - `nvim-dap-ui` integration to show app logs in the console window.
--- - `lualine.nvim` integration to show selected device, test plan,
--- - `Quick` integration to show test results for tests written using `Quick` framework.
--- and other project settings.
--- - Auto-detection of the target membership for new files.
--- - Picker with all available plugin actions.
Expand Down
3 changes: 2 additions & 1 deletion lua/xcodebuild/docs/requirements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
--- - `telescope.nvim` to present pickers.
--- - `nui.nvim` to present floating code coverage report.
--- - `nvim-tree` or `oil.nvim` to visually manage your project files.
--- - `nvim-dap` and nvim-dap-ui to debug apps.
--- - `nvim-dap` and `nvim-dap-ui` to debug apps.
--- - `nvim-treesitter` + Swift parser to show test results for tests written using `Quick` framework.
---
---External tools
--- - `xcbeautify` to format Xcode logs (you can set a different tool or disable formatting in the config).
Expand Down
25 changes: 22 additions & 3 deletions lua/xcodebuild/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local required_dependencies = {
},
}

local required_plugins = {
local plugins = {
{
name = "telescope.nvim",
lib = "telescope",
Expand Down Expand Up @@ -87,6 +87,12 @@ local required_plugins = {
optional = true,
info = "(Optional to present debugger UI)",
},
{
name = "nvim-treesitter",
lib = "nvim-treesitter",
optional = true,
info = "(Optional to present results for tests written using Quick framework)",
},
}

---@param binary string
Expand Down Expand Up @@ -148,7 +154,7 @@ local function check_debugger()
end

local function check_plugins()
for _, plugin in ipairs(required_plugins) do
for _, plugin in ipairs(plugins) do
if plugin_installed(plugin.lib) then
ok(plugin.name .. " installed.")
else
Expand Down Expand Up @@ -311,6 +317,18 @@ local function check_plugin_commit()
end
end

local function check_swift_parser()
local quick = require("xcodebuild.integrations.quick")

if quick.is_swift_parser_installed() then
ok("nvim-treesitter: Swift parser installed.")
else
warn(
"nvim-treesitter: Swift parser not installed. It is required to present results for tests written using Quick framework."
)
end
end

local M = {}

M.check = function()
Expand All @@ -320,8 +338,9 @@ M.check = function()
start("Checking OS")
check_os()

start("Checking required plugins")
start("Checking plugins")
check_plugins()
check_swift_parser()

start("Checking required dependencies")
check_xcodebuild_version()
Expand Down
4 changes: 3 additions & 1 deletion lua/xcodebuild/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ end
--- failure_sign = "✖", -- failed test icon
--- show_test_duration = true, -- show each test duration next to its declaration
--- show_diagnostics = true, -- add test failures to diagnostics
--- file_pattern = "*Tests.swift", -- test diagnostics will be loaded in files matching this pattern (if available)
--- },
--- quickfix = {
--- show_errors_on_quickfixlist = true, -- add build/test errors to quickfix list
Expand Down Expand Up @@ -200,6 +199,9 @@ end
--- return true
--- end,
--- },
--- quick = { -- integration with Swift test framework: github.com/Quick/Quick
--- enabled = true, -- enable Quick tests support (requires Swift parser for nvim-treesitter)
--- },
--- },
--- highlights = {
--- -- you can override here any highlight group used by this plugin
Expand Down
Loading

0 comments on commit 4ebfd0a

Please sign in to comment.