### Setup MiniTest with Default Configuration Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use this snippet to initialize the MiniTest module with its default configuration settings. This is the simplest way to get started. ```lua require('mini.test').setup() ``` -------------------------------- ### Install Standalone Plugin (Main Branch) with mini.deps Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the main development branch of the mini.test plugin using mini.deps. This method is for Neovim versions before 0.12. ```lua add('nvim-mini/mini.test') ``` -------------------------------- ### Setup MiniTest with Custom Configuration Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Initialize the MiniTest module with a custom configuration table. Replace `{}` with your specific configuration options. ```lua require('mini.test').setup({}) ``` -------------------------------- ### Install Standalone Plugin (Stable Branch) with lazy.nvim Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the stable release branch of the mini.test plugin using folke/lazy.nvim. Set version to '*' for the stable branch. ```lua { 'nvim-mini/mini.test', version = '*' }, ``` -------------------------------- ### Install Standalone Plugin (Main Branch) with vim.pack Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the main development branch of the mini.test plugin using vim.pack. Ensure you are using Neovim 0.12 or newer. ```lua vim.pack.add({ 'https://github.com/nvim-mini/mini.test' }) ``` -------------------------------- ### Install Standalone Plugin (Main Branch) with lazy.nvim Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the main development branch of the mini.test plugin using folke/lazy.nvim. Set version to false for the main branch. ```lua { 'nvim-mini/mini.test', version = false }, ``` -------------------------------- ### Install Standalone Plugin (Stable Branch) with mini.deps Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the stable release branch of the mini.test plugin using mini.deps. This method is for Neovim versions before 0.12. ```lua add({ source = 'nvim-mini/mini.test', checkout = 'stable' }) ``` -------------------------------- ### Initialize and Use a Child Neovim Process Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Demonstrates how to start, interact with, and stop a child Neovim process. This is useful for testing Neovim configurations and plugins in isolation. ```lua -- Initiate local child = MiniTest.new_child_neovim() child.start() -- Use API functions child.api.nvim_buf_set_lines(0, 0, -1, true, { 'Line inside child Neovim' }) -- Execute Lua code, Vimscript commands, etc. child.lua('_G.n = 0') child.cmd('au CursorMoved * lua _G.n = _G.n + 1') child.type_keys('l') print(child.lua_get('_G.n')) -- Should be 1 -- Use other `vim.xxx` Lua wrappers (executed inside child process) vim.b.aaa = 'current process' child.b.aaa = 'child process' print(child.lua_get('vim.b.aaa')) -- Should be 'child process' -- Always stop process after it is not needed child.stop() ``` -------------------------------- ### Start Child Neovim Process Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Starts a new Neovim process. It can be configured with custom arguments or default clean startup options. This function will fail if the child process is already running. ```lua child = MiniTest.new_child_neovim() -- Start default clean Neovim instance child.start() -- Start with custom 'init.lua' file child.start({ '-u', 'scripts/minimal_init.lua' }) ``` -------------------------------- ### child.start() Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Starts a child Neovim process and connects to it. This function is used to initiate a new Neovim instance for testing purposes. It accepts arguments for the executable and connection options. ```APIDOC ## child.start() ### Description Start child process and connect to it. Won't work if child is already running. ### Parameters - **args** (table) - Array with arguments for executable. Will be prepended with default arguments like `--clean`, `-n`, `--listen`, etc. - **opts** (table|nil) - Options table. Possible fields: - **nvim_executable** (string) - Name of Neovim executable. Default: |v:progpath|. - **connection_timeout** (number) - Stop trying to connect after this amount of milliseconds. Default: 5000. ### Usage ```lua child = MiniTest.new_child_neovim() -- Start default clean Neovim instance child.start() -- Start with custom 'init.lua' file child.start({ '-u', 'scripts/minimal_init.lua' }) ``` ``` -------------------------------- ### Install Standalone Plugin (Stable Branch) with vim.pack Source: https://github.com/nvim-mini/mini.test/blob/main/README.md Installs the stable release branch of the mini.test plugin using vim.pack. Ensure you are using Neovim 0.12 or newer. ```lua vim.pack.add({ { src = 'https://github.com/nvim-mini/mini.test', version = 'stable' }, }) ``` -------------------------------- ### Example Usage of MiniTest.expect.equality Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Demonstrates how to use MiniTest.expect.equality to assert the equality of two values. It shows a successful assertion and a failing one with a custom fail reason. Equality is checked using vim.deep_equal. ```lua local x = 1 + 1 MiniTest.expect.equality(x, 2) -- passes MiniTest.expect.equality(x, 1, { fail_reason = 'Not equal' }) -- fails ``` -------------------------------- ### Detailed Equality Checks with MiniTest.expect.equality Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Illustrates how MiniTest.expect.equality provides detailed failure reasons for different data types, including nested tables. It shows examples for comparing tables with differing elements and nested structures. ```lua local eq = MiniTest.expect.equality eq({ 1, 2 }, { 1, 3 }) -- Key branch is `2` eq({ 1, { 2 } }, { 1, 'c' }) -- Key branch is `2` ('c' is not a table) eq({ 1, { 2 } }, { 1, { 3 } }) -- Key branch is `2->1` ``` -------------------------------- ### Default MiniTest Configuration Source: https://github.com/nvim-mini/mini.test/blob/main/README.md This is the default configuration for MiniTest. It covers options for collecting test cases, such as emulating the 'busted' framework and specifying how to find test files. It also includes options for executing tests, like setting a reporter and controlling whether to stop on the first error. This configuration does not need to be explicitly passed to the `setup()` function as it will be used automatically. ```lua -- No need to copy this inside `setup()`. Will be used automatically. { -- Options for collection of test cases. See `:h MiniTest.collect()`. collect = { -- Temporarily emulate functions from 'busted' testing framework -- (`describe`, `it`, `before_each`, `after_each`, and more) emulate_busted = true, -- Function returning array of file paths to be collected. -- Default: all Lua files in 'tests' directory starting with 'test_'. find_files = function() return vim.fn.globpath('tests', '**/test_*.lua', true, true) end, -- Predicate function indicating if test case should be executed filter_cases = function(case) return true end, }, -- Options for execution of test cases. See `:h MiniTest.execute()`. execute = { -- Table with callable fields `start()`, `update()`, and `finish()` reporter = nil, -- Whether to stop execution after first error stop_on_error = false, }, -- Path (relative to current directory) to script which handles project -- specific test running script_path = 'scripts/minitest.lua', -- Whether to disable showing non-error feedback silent = false, } ``` -------------------------------- ### Get Screenshot from Child Neovim Process Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Retrieves the current screen content and attributes from a child Neovim process. It can optionally trigger a redraw before capturing the screen. The output can be converted to a string for comparison or storage. ```lua local screenshot = child.get_screenshot() -- Show character displayed row=3 and column=4 print(screenshot.text[3][4]) -- Convert to string tostring(screenshot) ``` -------------------------------- ### MiniTest.setup() Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Sets up the MiniTest module with optional configuration. This is the primary function to call to initialize MiniTest. ```APIDOC ## MiniTest.setup({config}) ### Description Module setup function. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **config** (table|nil) - Module config table. See |MiniTest.config|. ### Request Example ```lua require('mini.test').setup() -- OR require('mini.test').setup({}) ``` ### Response #### Success Response (200) - N/A (This is a setup function, not an endpoint returning data) #### Response Example - N/A ``` -------------------------------- ### API Redirection Tables Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Tables that act as convenience wrappers for corresponding `vim.*` tables, allowing interaction with Neovim's API and global variables. ```APIDOC ## `child.api` ### Description Redirection table for `vim.api`. Does not check for blocked state. ### Type `table` ## `child.api_notify` ### Description Similar to `child.api`, but uses `vim.rpcnotify()`. ### Type `table` ## `child.diagnostic` ### Description Redirection table for `vim.diagnostic`. ### Type `table` ## `child.fn` ### Description Redirection table for `vim.fn`. ### Type `table` ## `child.highlight` ### Description Redirection table for `vim.highlight`. ### Type `table` ## `child.hl` ### Description Redirection table for `vim.hl`. ### Type `table` ## `child.json` ### Description Redirection table for `vim.json`. ### Type `table` ## `child.loop` ### Description Redirection table for `vim.loop`. ### Type `table` ## `child.lsp` ### Description Redirection table for `vim.lsp`. ### Type `table` ## `child.mpack` ### Description Redirection table for `vim.mpack`. ### Type `table` ## `child.spell` ### Description Redirection table for `vim.spell`. ### Type `table` ## `child.treesitter` ### Description Redirection table for `vim.treesitter`. ### Type `table` ## `child.ui` ### Description Redirection table for `vim.ui`. Currently of no use because it requires sending functions through RPC, which is impossible at the moment. ### Type `table` ## `child.fs` ### Description Redirection table for `vim.fs`. ### Type `table` ## `child.g` ### Description Redirection table for `vim.g`. ### Type `table` ## `child.b` ### Description Redirection table for `vim.b`. ### Type `table` ## `child.w` ### Description Redirection table for `vim.w`. ### Type `table` ## `child.t` ### Description Redirection table for `vim.t`. ### Type `table` ## `child.v` ### Description Redirection table for `vim.v`. ### Type `table` ## `child.env` ### Description Redirection table for `vim.env`. ### Type `table` ## `child.o` ### Description Redirection table for `vim.o`. ### Type `table` ## `child.go` ### Description Redirection table for `vim.go`. ### Type `table` ## `child.bo` ### Description Redirection table for `vim.bo`. ### Type `table` ## `child.wo` ### Description Redirection table for `vim.wo`. ### Type `table` ``` -------------------------------- ### Compare a screenshot to a reference file Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.expect.reference_screenshot` to compare a given screenshot with a reference file. It can automatically create or update the reference file if it doesn't exist or if `force` is enabled. ```lua MiniTest.expect.reference_screenshot({screenshot}, {path}, {opts}) ``` -------------------------------- ### MiniTest.execute Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Executes a provided array of test cases with optional configuration for reporters and error handling. ```APIDOC ## MiniTest.execute ### Description Executes an array of test cases. This function manages the test execution flow, including starting and finishing reporters, and updating test case status. ### Method `MiniTest.execute({cases}, {opts})` ### Parameters #### Path Parameters - `cases` (table) - Required - Array of test cases to execute. - `opts` (table|nil) - Optional - Options controlling execution: - `reporter` (table|nil) - Table with optional `start`, `update`, `finish` callable fields. Defaults to a buffered reporter or stdout reporter based on usage. - `stop_on_error` (boolean|nil) - Optional - Whether to stop execution after the first error. Defaults to `false`. ### Response This function does not return anything directly. It updates the `cases` table in place with execution results. ``` -------------------------------- ### MiniTest.run Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Executes tests, with options to run project-specific scripts, collect cases, and execute them. ```APIDOC ## MiniTest.run(opts) ### Description Runs tests. It attempts to execute a project-specific script if provided and successful, then collects and executes test cases based on the options. ### Method `MiniTest.run` ### Parameters #### Path Parameters - **opts** (table|nil) - Optional - Options table with a structure similar to `MiniTest.config`. Absent values are inferred from `MiniTest.config`. ``` -------------------------------- ### Type Keys in Child Neovim Process Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Simulates typing keys into a child Neovim process, similar to `nvim_input()`. It supports optional delays between key groups and raises an error if the child process encounters an error during typing. Special keys like `` can be used directly. ```lua -- All of these type keys 'c', 'a', 'w' child.type_keys('caw') child.type_keys('c', 'a', 'w') child.type_keys('c', { 'a', 'w' }) -- Waits 5 ms after `c` and after 'w' child.type_keys(5, 'c', { 'a', 'w' }) -- Special keys can also be used child.type_keys('i', 'Hello world', '') ``` -------------------------------- ### Create a new test set Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use MiniTest.new_set() to create a new test set. Elements can be added using the T[name] = element syntax to preserve order. Options can be passed to customize behavior. ```lua T = MiniTest.new_set() T['works'] = function() MiniTest.expect.equality(1, 1) end T['nested'] = MiniTest.new_set({ hooks = { pre_case = function() _G.x = 1 end }, parametrize = { { 1 }, { 2 } }, n_retry = 2, }) T['nested']['works'] = function(x) MiniTest.expect.equality(_G.x, x) end ``` -------------------------------- ### MiniTest.expect.reference_screenshot Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Expect equality to a reference screenshot. Can optionally create or update the reference screenshot. ```APIDOC ## MiniTest.expect.reference_screenshot ### Description Expect equality to a reference screenshot. Can optionally create or update the reference screenshot. ### Method `MiniTest.expect.reference_screenshot({screenshot}, {path}, {opts})` ### Parameters #### Path Parameters - **{screenshot}** `(table|nil)` - Array with screenshot information. Usually an output of `child.get_screenshot()` (see |MiniTest-child-neovim-get_screenshot()|). If `nil`, expectation passed. - **{path}** `(string|nil)` - Path to reference screenshot. If `nil`, constructed automatically in directory `opts.directory` from current case info and total number of times it was called inside current case. If there is no file at `path`, it is created with content of `screenshot`. - **{opts}** `(table|nil)` - Options: - **force** `(boolean)` - whether to forcefully create reference screenshot. Temporary useful during test writing. Default: `false`. - **ignore_text** `(boolean|table)` - whether to ignore all or some text lines. If `true` - ignore all, if number array - ignore text of those lines, if `false` - do not ignore any. Default: `false`. - **ignore_attr** `(boolean|table)` - whether to ignore all or some attr lines. If `true` - ignore all, if number array - ignore attr of those lines, if `false` - do not ignore any. Default: `false`. - **directory** `(string)` - directory where automatically constructed `path` is located. Default: "tests/screenshots". - **fail_reason** `(string|function)` - reason for failing expectation. a function is called with expectation input and should return a string. Default: `nil` for default reason like "Failed expectation for ...". ### Response #### Success Response (200) - **(Implicit)** The expectation passes if the screenshot matches the reference or if a new reference is created/updated. #### Response Example (No explicit response body, success is indicated by lack of error) ``` -------------------------------- ### Default MiniTest Configuration Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt This table shows the default configuration options for the MiniTest module. It includes settings for collecting and executing test cases, as well as project-specific script paths and silent mode. ```lua MiniTest.config = { -- Options for collection of test cases. See ":h MiniTest.collect()". collect = { -- Temporarily emulate functions from 'busted' testing framework -- (`describe`, `it`, `before_each`, `after_each`, and more) emulate_busted = true, -- Function returning array of file paths to be collected. -- Default: all Lua files in 'tests' directory starting with 'test_'. find_files = function() return vim.fn.globpath('tests', '**/test_*.lua', true, true) end, -- Predicate function indicating if test case should be executed filter_cases = function(case) return true end, }, -- Options for execution of test cases. See ":h MiniTest.execute()". execute = { -- Table with callable fields `start()`, `update()`, and `finish()` reporter = nil, -- Whether to stop execution after first error stop_on_error = false, }, -- Path (relative to current directory) to script which handles project -- specific test running script_path = 'scripts/minitest.lua', -- Whether to disable showing non-error feedback silent = false, } ``` -------------------------------- ### child.type_keys() Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Simulates typing keys into the child Neovim process, similar to nvim_input(). It supports waiting between key entries and raises errors if typing results in an error within the child process. ```APIDOC ## child.type_keys() ### Description Basically a wrapper for |nvim_input()| applied inside child process. Differences: - Can wait after each group of characters. - Raises error if typing keys resulted into error in child process (i.e. its |v:errmsg| was updated). - Key `<` as a separate entry may not be escaped as ``. ### Parameters - **wait** (number|nil) - Number of milliseconds to wait after each entry. May be omitted, in which case no waiting is done. - **...** (string|table) - Separate entries for |nvim_input()|, after which `wait` will be applied. Can be either string or array of strings. ### Usage ```lua -- All of these type keys 'c', 'a', 'w' child.type_keys('caw') child.type_keys('c', 'a', 'w') child.type_keys('c', { 'a', 'w' }) -- Waits 5 ms after `c` and after 'w' child.type_keys(5, 'c', { 'a', 'w' }) -- Special keys can also be used child.type_keys('i', 'Hello world', '') ``` ``` -------------------------------- ### MiniTest.config Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Provides default configuration options for the MiniTest module, covering test case collection and execution. ```APIDOC ## MiniTest.config ### Description Defaults for module configuration. This table outlines the available options for customizing test collection and execution behavior. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None (This describes default configuration, not a request body) ### Defaults ```lua MiniTest.config = { -- Options for collection of test cases. See `:h MiniTest.collect()`. collect = { -- Temporarily emulate functions from 'busted' testing framework -- (`describe`, `it`, `before_each`, `after_each`, and more) emulate_busted = true, -- Function returning array of file paths to be collected. -- Default: all Lua files in 'tests' directory starting with 'test_'. find_files = function() return vim.fn.globpath('tests', '**/test_*.lua', true, true) end, -- Predicate function indicating if test case should be executed filter_cases = function(case) return true end, }, -- Options for execution of test cases. See `:h MiniTest.execute()`. execute = { -- Table with callable fields `start()`, `update()`, and `finish()` reporter = nil, -- Whether to stop execution after first error stop_on_error = false, }, -- Path (relative to current directory) to script which handles project -- specific test running script_path = 'scripts/minitest.lua', -- Whether to disable showing non-error feedback silent = false, } ``` ### Response #### Success Response (200) - N/A #### Response Example - N/A ``` -------------------------------- ### Code Execution Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Methods for executing Vimscript and Lua code within the child process. ```APIDOC ## `child.type_keys()` ### Description Emulates typing keys in the child process. This function does not check for a blocked state. ### Method `(function)` ## `child.cmd()` ### Description Executes Vimscript code from a string. This is a wrapper for `nvim_exec()` without capturing output. ### Method `(function)` ## `child.cmd_capture()` ### Description Executes Vimscript code from a string and captures its output. This is a wrapper for `nvim_exec()` with output capturing. ### Method `(function)` ## `child.lua()` ### Description Executes Lua code. This is a wrapper for `nvim_exec_lua()`. ### Method `(function)` ## `child.lua_notify()` ### Description Executes Lua code without waiting for output. ### Method `(function)` ## `child.lua_get()` ### Description Executes Lua code and returns the result. This is a wrapper for `nvim_exec_lua()` but prepends the string code with `return`. ### Method `(function)` ## `child.lua_func()` ### Description Executes a Lua function and returns its result. The function will be called with all extra parameters (second one and later). Note: usage of upvalues (data from outside function scope) is not allowed. ### Method `(function)` ``` -------------------------------- ### child.get_screenshot() Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Captures the current screen state of the child Neovim process, returning the text and attributes displayed. This is useful for visual verification and debugging. ```APIDOC ## child.get_screenshot() ### Description Compute what is displayed on (default TUI) screen and how it is displayed. This basically calls |screenstring()| and |screenattr()| for every visible cell. Notes: - To make output more portable and visually useful, outputs of `screenattr()` are coded with single character symbols. ### Parameters - **opts** (table|nil) - Options. Possible fields: - **redraw** (boolean) - Whether to call |:redraw| prior to computing screenshot. Default: `true`. ### Return - **(table|nil)** - Screenshot table with the following fields: - **text** - "2d array" (row-column) of single characters displayed at particular cells. - **attr** - "2d array" (row-column) of symbols representing how text is displayed. Returns `nil` if couldn't get a reasonable screenshot. ### Usage ```lua local screenshot = child.get_screenshot() -- Show character displayed row=3 and column=4 print(screenshot.text[3][4]) -- Convert to string tostring(screenshot) ``` ``` -------------------------------- ### MiniTest.collect Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Collects test cases from specified files, handling hierarchical test structures and applying filters. ```APIDOC ## MiniTest.collect(opts) ### Description Collects test cases from source files. It supports emulating Busted-style test definitions, combining test sets, converting hierarchical structures to sequential cases, and filtering. ### Method `MiniTest.collect` ### Parameters #### Path Parameters - **opts** (table) - Required - Options for collection, including `emulate_busted` (boolean), `find_files` (function returning array of file paths), `filter_cases` (function to filter cases). ``` -------------------------------- ### Process Status and Utilities Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Functions to check the status of the child process and perform utility actions. ```APIDOC ## `child.is_blocked()` ### Description Checks whether the child process is blocked. ### Method `(function)` ## `child.is_running()` ### Description Checks whether the child process is currently running. ### Method `(function)` ## `child.ensure_normal_mode()` ### Description Ensures the child process is in normal mode. ### Method `(function)` ## `child.get_screenshot()` ### Description Returns a table with two "2d arrays" representing the screen display and its appearance. It accepts an `opts` table argument for optional configuration. ### Method `(function)` ## `child.job` ### Description Information about the current job. If `nil`, the child process is not running. ### Type `table|nil` ``` -------------------------------- ### Process Control Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Functions to manage the lifecycle of the child Neovim process. ```APIDOC ## `child.start()` ### Description Starts a child Neovim process. ### Method `(function)` ## `child.stop()` ### Description Stops the current child Neovim process. ### Method `(function)` ## `child.restart()` ### Description Restarts the child Neovim process. It stops the current process if running and then starts a new one. It accepts the same arguments as `child.start()` and uses values from the most recent `start()` call as defaults. ### Method `(function)` ``` -------------------------------- ### MiniTest.run_file Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Runs tests within a specific file, acting as a wrapper around `MiniTest.run` with custom file collection options. ```APIDOC ## MiniTest.run_file(file, opts) ### Description Runs tests in a specified file. This function is a wrapper around `MiniTest.run` that allows for custom file collection. ### Method `MiniTest.run_file` ### Parameters #### Path Parameters - **file** (string|nil) - Optional - The path to the test file. Defaults to the current buffer's path. - **opts** (table|nil) - Optional - Options for `MiniTest.run`. ``` -------------------------------- ### MiniTest.expect.no_equality Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Expect no equality of two objects. Equality is tested via vim.deep_equal(). ```APIDOC ## MiniTest.expect.no_equality ### Description Expect no equality of two objects. Equality is tested via `vim.deep_equal()`. ### Method `MiniTest.expect.no_equality({left}, {right}, {opts})` ### Parameters #### Path Parameters - **{left}** `(any)` - First object. - **{right}** `(any)` - Second object. - **{opts}** `(table|nil)` - Options. Possible fields: - **fail_reason** `(string|function)` - reason for failing expectation. a function is called with expectation input and should return a string. Default: `nil` for default reason like "Failed expectation for ...". ### Response #### Success Response (200) - **(Implicit)** The expectation passes if no error is thrown. #### Response Example (No explicit response body, success is indicated by lack of error) ``` -------------------------------- ### Expect a function call to raise an error Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.expect.error` to verify that a function call results in an error. An optional pattern can be provided to match the error message. ```lua MiniTest.expect.error({f}, {pattern}, {opts}, {...}) ``` -------------------------------- ### MiniTest.run_at_location Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Runs test cases that cover a specific location (file and line number) in the code. ```APIDOC ## MiniTest.run_at_location(location, opts) ### Description Runs test case(s) that cover a given location (file and line number). This can potentially run multiple cases if they originate from parametrized tests. ### Method `MiniTest.run_at_location` ### Parameters #### Path Parameters - **location** (table|nil) - Optional - A table with `file` (string) and `line` (number) fields. Defaults to the current cursor position. - **opts** (table|nil) - Optional - Options for `MiniTest.run`. ``` -------------------------------- ### MiniTest.expect.equality Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Asserts that two objects are equal using a deep comparison, providing detailed failure reasons. ```APIDOC ## MiniTest.expect.equality ### Description Expects two objects to be equal. This function uses `vim.deep_equal` for comparison and attempts to provide detailed information about the cause of inequality, such as type differences, string lengths, or key branches in tables where values differ. ### Method `MiniTest.expect.equality({left}, {right}, {opts})` ### Parameters #### Path Parameters - `left` - Required - The first object to compare. - `right` - Required - The second object to compare. - `opts` (table|nil) - Optional - Options for expectation: - `fail_reason` (string|nil) - Optional - A custom reason to provide if the expectation fails. ### Response - Returns `true` if the expectation is met. - Throws an informative error if the expectation fails. ``` -------------------------------- ### MiniTest.add_note Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Adds a note to the currently executing test case. The note is appended to the `exec.notes` field of the current case. ```APIDOC ## MiniTest.add_note(msg) ### Description Adds a string message to the notes of the currently executing test case. ### Method `MiniTest.add_note` ### Parameters #### Path Parameters - **msg** (string) - Required - The note message to add. ``` -------------------------------- ### MiniTest.finally Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Registers a callable function or table to be executed after the current callable finishes, regardless of success or failure. ```APIDOC ## MiniTest.finally(f) ### Description Registers a function or table to be executed after the current test callable completes. ### Method `MiniTest.finally` ### Parameters #### Path Parameters - **f** (function|table) - Required - The callable to execute after the current callable finishes. ``` -------------------------------- ### Create a New Test Set Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.new_set` to create a test set, which defines a hierarchical test organization. This function allows customization of test collection and execution through options like `hooks`, `parametrize`, and `data`. ```lua `MiniTest.new_set`({opts}, {tbl}) ``` -------------------------------- ### MiniTest.stop Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Stops the current test execution, with options to control the closure of child Neovim processes. ```APIDOC ## MiniTest.stop ### Description Stops the ongoing test execution. This function can be configured to close associated child Neovim processes. ### Method `MiniTest.stop({opts})` ### Parameters #### Path Parameters - `opts` (table|nil) - Optional - Options controlling the stop behavior: - `close_all_child_neovim` (boolean|nil) - Optional - Whether to close all child Neovim processes. Defaults to `true`. ### Response This function does not return anything. ``` -------------------------------- ### MiniTest.new_set() Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Creates a new test set, which defines a hierarchical organization of tests. ```APIDOC ## MiniTest.new_set({opts}, {tbl}) ### Description Create a test set. Test set is one of the two fundamental data structures. It is a table that defines hierarchical test organization as opposed to sequential organization with |MiniTest-test-case|. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **opts** (table) - Set options allow customization of test collection and execution. - `hooks` - table with elements that will be called without arguments at predefined stages of test execution. - `parametrize` - array defining different arguments with which main test actions will be called. - `data` - table with user data that will be forwarded to cases. - **tbl** (table) - The table defining the test set structure. ### Request Example ```lua -- Example usage would depend on the specific structure of opts and tbl -- require('mini.test').new_set({ hooks = {...} }, { ... }) ``` ### Response #### Success Response (200) - Returns a table representing the new test set. #### Response Example - N/A ``` -------------------------------- ### Create a custom expectation function Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.new_expectation` to create custom expectation functions. This is a helper for building reusable assertion logic similar to built-in MiniTest expectations. ```lua MiniTest.new_expectation({subject}, {predicate}, {fail_context}) ``` -------------------------------- ### Create a Truthy Expectation Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Defines a custom expectation that checks if a value is truthy. It includes a custom formatter for the output. ```lua local expect_truthy = MiniTest.new_expectation( 'truthy', function(x) return x end, function(x) return 'Object: ' .. vim.inspect(x) end ) ``` -------------------------------- ### MiniTest.expect.error Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Expect function call to raise error. The error message can be optionally matched against a pattern. ```APIDOC ## MiniTest.expect.error ### Description Expect function call to raise error. The error message can be optionally matched against a pattern. ### Method `MiniTest.expect.error({f}, {pattern}, {opts}, {...})` ### Parameters #### Path Parameters - **{f}** `(function)` - Function to be tested for raising error. - **{pattern}** `(string|nil)` - Pattern which error message should match. Use `nil` or empty string to not test for pattern matching. - **{opts}** `(table|nil)` - Options. Possible fields: - **fail_reason** `(string|function)` - reason for failing expectation. a function is called with expectation input and should return a string. Default: `nil` for default reason like "Failed expectation for ...". ### Response #### Success Response (200) - **(Implicit)** The expectation passes if the function call raises an error that matches the pattern (if provided). #### Response Example (No explicit response body, success is indicated by lack of error) ``` -------------------------------- ### MiniTest.new_expectation Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Create a new expectation function, useful for writing custom expectations. ```APIDOC ## MiniTest.new_expectation ### Description Create a new expectation function, useful for writing custom expectations with behavior similar to other methods of |MiniTest.expect|. ### Method `MiniTest.new_expectation({subject}, {predicate}, {fail_context})` ### Parameters #### Path Parameters - **{subject}** `(string|function|table)` - Subject of expectation. If callable, called with expectation input arguments to produce string value. - **{predicate}** `(function|table)` - Predicate callable. Called with expectation input arguments. Output `false` or `nil` means failed expectation. - **{fail_context}** `(string|function|table)` - Information about fail. If callable, called with expectation input arguments to produce string value. ### Return - **(function)** Expectation function. ### Response #### Success Response (200) - **(function)** A new expectation function is returned. #### Response Example (No explicit response body, the return value is the function itself) ``` -------------------------------- ### Check for deep equality of two objects Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.expect.eq` to assert that two objects are deeply equal. This function utilizes `vim.deep_equal` for comparison. ```lua -- Key branch is either `1->1->"a"` or `1->1->"b"` eq({ { { a = 1 } } }, { { { b = 2 } } }) ``` -------------------------------- ### MiniTest.is_executing Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Checks if the MiniTest framework is currently executing tests. ```APIDOC ## MiniTest.is_executing ### Description Determines whether the MiniTest framework is in the process of running tests. ### Method `MiniTest.is_executing()` ### Response #### Success Response (boolean) - `true` if tests are currently executing, `false` otherwise. ``` -------------------------------- ### Assert no equality between two objects Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.expect.no_equality` to assert that two objects are not deeply equal. This function also relies on `vim.deep_equal` for comparison. ```lua MiniTest.expect.no_equality({left}, {right}, {opts}) ``` -------------------------------- ### MiniTest.expect.no_error Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Expect function call to not raise error. ```APIDOC ## MiniTest.expect.no_error ### Description Expect function call to not raise error. ### Method `MiniTest.expect.no_error({f}, {opts}, {...})` ### Parameters #### Path Parameters - **{f}** `(function)` - Function to be tested for not raising error. - **{opts}** `(table|nil)` - Options. Possible fields: - **fail_reason** `(string|function)` - reason for failing expectation. a function is called with expectation input and should return a string. Default: `nil` for default reason like "Failed expectation for ...". ### Response #### Success Response (200) - **(Implicit)** The expectation passes if the function call does not raise an error. #### Response Example (No explicit response body, success is indicated by lack of error) ``` -------------------------------- ### Expect a function call to not raise an error Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use `MiniTest.expect.no_error` to assert that a function call does not produce an error. This is useful for testing code that should execute without exceptions. ```lua MiniTest.expect.no_error({f}, {opts}, {...}) ``` -------------------------------- ### Skip current test case Source: https://github.com/nvim-mini/mini.test/blob/main/doc/mini-test.txt Use MiniTest.skip() to stop the execution of the current test case and add a message to its notes. This function is specifically handled when called within a test case or a 'pre_case' hook. ```lua MiniTest.skip("Skipping this test") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.