|
1 |
| -local ok, nio = pcall(require, 'nio') |
2 |
| -if not ok then |
3 |
| - nio = require('neotest.async') |
4 |
| -end |
5 |
| -local lib = require('neotest.lib') |
6 |
| -local Path = require('plenary.path') |
7 |
| -local logger = require('neotest.logging') |
8 |
| -local treesitter_hs = require('neotest-haskell.treesitter') |
9 |
| - |
10 | 1 | local runner = {}
|
11 | 2 |
|
12 | 3 | ---Check if the given directory contains a file matching a list of patterns.
|
13 | 4 | ---@param directory string The directory to check for.
|
14 | 5 | ---@param patterns string[] The patterns to check for.
|
15 | 6 | ---@return boolean
|
16 | 7 | local function directory_contains_file_matching(directory, patterns)
|
| 8 | + local Path = require('plenary.path') |
17 | 9 | for _, pattern in ipairs(patterns) do
|
18 | 10 | for _, file in ipairs(vim.fn.glob(Path:new(directory, pattern).filename, true, true)) do
|
19 | 11 | if Path:new(file):exists() then
|
|
28 | 20 | ---If a *.cabal is present, this is *.
|
29 | 21 | ---Otherwise, we assume the package name is the same as the directory name.
|
30 | 22 | ---@param package_root string The package root directory.
|
31 |
| ----@return string package_name The assumed package name. |
| 23 | +---@return string | nil package_name The assumed package name. |
32 | 24 | local function get_package_name(package_root)
|
| 25 | + local ok, nio = pcall(require, 'nio') |
| 26 | + if not ok then |
| 27 | + nio = require('neotest.async') |
| 28 | + end |
| 29 | + local Path = require('plenary.path') |
33 | 30 | ---@diagnostic disable-next-line -- nio.fn is private?
|
34 | 31 | for _, package_file_path in ipairs(nio.fn.glob(Path:new(package_root, '*.cabal').filename, true, true)) do
|
35 | 32 | local package_file_name = package_file_path and vim.fn.fnamemodify(package_file_path, ':t')
|
|
71 | 68 | ---@return boolean
|
72 | 69 | ---@async
|
73 | 70 | local function has_module(test_file_content, qualified_modules)
|
| 71 | + local treesitter_hs = require('neotest-haskell.treesitter') |
74 | 72 | for _, qualified_module in pairs(qualified_modules) do
|
75 | 73 | local modules = {}
|
76 | 74 | for module in qualified_module:gmatch('([^%.]+)') do
|
|
105 | 103 | ---@return TestFrameworkHandler handler
|
106 | 104 | ---@async
|
107 | 105 | function runner.select_framework(test_file_path, frameworks)
|
| 106 | + local lib = require('neotest.lib') |
| 107 | + local logger = require('neotest.logging') |
108 | 108 | local content = lib.files.read(test_file_path)
|
109 | 109 | ---@type FrameworkSpec[]
|
110 | 110 | local framework_specs = {}
|
|
138 | 138 | ---@param build_tools build_tool[] List of build tools to choose from.
|
139 | 139 | ---@return fun(neotest.Tree):neotest.RunSpec mk_command A function that builds the runner command using the selected build tool for a test tree.
|
140 | 140 | function runner.select_build_tool(handler, test_file_path, build_tools)
|
| 141 | + local lib = require('neotest.lib') |
| 142 | + local logger = require('neotest.logging') |
141 | 143 | -- A package always has a *.cabal file (or in rare cases just a package.yaml file).
|
142 | 144 | local package_root = lib.files.match_root_pattern('*.cabal', 'package.yaml')(test_file_path)
|
143 | 145 | if not package_root then
|
@@ -173,7 +175,9 @@ function runner.select_build_tool(handler, test_file_path, build_tools)
|
173 | 175 | local command = { selected_build_tool, 'test' }
|
174 | 176 | if is_multi_package_project then
|
175 | 177 | local package_name = get_package_name(package_root)
|
176 |
| - table.insert(command, package_name) |
| 178 | + if package_name then |
| 179 | + table.insert(command, package_name) |
| 180 | + end |
177 | 181 | end
|
178 | 182 | return function(pos)
|
179 | 183 | local test_opts = pos and get_test_opts(pos)
|
|
0 commit comments