Skip to content

Commit

Permalink
fix(tasty): don't pass -p option to tasty if no paths detected
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jun 18, 2023
1 parent 083e81c commit 797e1f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Don't pass `-p` option to `tasty` if no paths to filter on are detected.
### Changed
- Treat all files with `spec` or `test` in the path as test files.

Expand Down
23 changes: 16 additions & 7 deletions lua/neotest-haskell/tasty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local util = require('neotest-haskell.util')
local position = require('neotest-haskell.position')
local results = require('neotest-haskell.results')
local hspec = require('neotest-haskell.hspec')
local logger = require('neotest.logging')

---@type TestFrameworkHandler
local tasty = {}
Expand All @@ -28,13 +29,17 @@ end

---Parses tasty --pattern filter expressions for the top-level test positions.
---@param pos neotest.Tree The position to build the --pattern filter expression from.
---@return string pattern The tasty --pattern expression.
---@return string|nil pattern The tasty --pattern expression.
local function parse_top_level_tasty_nodes(pos)
local function prepend_subpatterns(subpatterns, pos_name)
table.insert(subpatterns, format_position_name(pos_name))
return subpatterns
end
local function concat_subpatterns(subpatterns)
if not subpatterns or #subpatterns == 0 then
logger.error('Could not detect tasty top level nodes.')
return nil
end
return '$0~' .. table.concat(subpatterns, '||')
end
local parse = position.mk_top_level_node_parser(prepend_subpatterns, concat_subpatterns)
Expand All @@ -43,9 +48,13 @@ end

---Parses the tasty --filter expression from a position, starting at a child node, up to its parents.
---@param pos neotest.Tree The position of the test or namespace to get the pattern for.
---@return string pattern The tasty --pattern expression for the test.
---@return string|nil pattern The tasty --pattern expression for the test.
local function parse_tasty_tree(pos)
local function format_result(result)
if not result or result == '' then
logger.error('Could not detect any tasty patterns.')
return nil
end
return '$0~' .. result
end
local function prepend_position(result, pos_name)
Expand All @@ -67,7 +76,7 @@ end
--- ```
--- - Result: "$0 ~ /Run.My test/"
---@param pos neotest.Tree The position to build the --pattern filter expression from.
---@return string pattern The tasty pattern expression for the test or namespace (see example).
---@return string|nil pattern The tasty pattern expression for the test or namespace (see example).
local function mk_tasty_pattern(pos)
local data = pos:data()
if data.type == 'file' then
Expand All @@ -80,22 +89,22 @@ end
---@return string[] test_opts The Cabal test options for matching a tasty filter.
function tasty.get_cabal_test_opts(pos)
local pattern = mk_tasty_pattern(pos)
return {
return pattern and {
'--test-option',
'-p',
'--test-option',
pattern,
}
} or {}
end

---@param pos neotest.Tree The position.
---@return string[] test_opts The Stack test options for matching a tasty filter.
function hspec.get_stack_test_opts(pos)
local pattern = mk_tasty_pattern(pos)
return {
return pattern and {
'--ta',
'-p "' .. pattern .. '"',
}
} or {}
end

local function get_failed_name(line, lines, idx)
Expand Down

0 comments on commit 797e1f9

Please sign in to comment.