File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ The adapter comes with the following defaults:
6767
6868--- @class neotest-cpp.Config
6969--- @field executables neotest-cpp.Config.Executable
70+ --- @field is_test_file fun ( file_path : string ): boolean
7071--- @field log_level vim.log.levels
7172M .defaults = {
7273 executables = {
@@ -129,6 +130,12 @@ M.defaults = {
129130 end ,
130131 },
131132 },
133+ is_test_file = function (file_path )
134+ return vim .endswith (file_path , " .cpp" )
135+ or vim .endswith (file_path , " .cxx" )
136+ or vim .endswith (file_path , " .cc" )
137+ or vim .endswith (file_path , " .c++" )
138+ end ,
132139 log_level = vim .log .levels .INFO ,
133140}
134141}
Original file line number Diff line number Diff line change 3232--- @param file_path string
3333--- @return boolean
3434M .is_test_file = function (file_path )
35- return vim .endswith (file_path , " .cpp" )
36- or vim .endswith (file_path , " .cxx" )
37- or vim .endswith (file_path , " .cc" )
38- or vim .endswith (file_path , " .c++" )
35+ local config = require (" neotest-cpp.config" )
36+ return config .get ().is_test_file (file_path )
3937end
4038
4139--- Given a file path, parse all the tests within it.
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ local M = {}
1212
1313--- @class neotest-cpp.Config
1414--- @field executables neotest-cpp.Config.Executable
15+ --- @field is_test_file fun ( file_path : string ): boolean
1516--- @field log_level vim.log.levels
1617M .defaults = {
1718 executables = {
@@ -74,6 +75,12 @@ M.defaults = {
7475 end ,
7576 },
7677 },
78+ is_test_file = function (file_path )
79+ return vim .endswith (file_path , " .cpp" )
80+ or vim .endswith (file_path , " .cxx" )
81+ or vim .endswith (file_path , " .cc" )
82+ or vim .endswith (file_path , " .c++" )
83+ end ,
7784 log_level = vim .log .levels .INFO ,
7885}
7986
Original file line number Diff line number Diff line change @@ -36,4 +36,18 @@ T["should return false for non-C++ files"] = function()
3636 eq (is_test_file (" /path/to/file.txt" ), false )
3737end
3838
39+ T [" should respect custom is_test_file configuration" ] = function ()
40+ child .lua_func (function ()
41+ require (" neotest-cpp" ).setup ({
42+ is_test_file = function (file_path )
43+ return vim .endswith (file_path , " _test.cpp" )
44+ end ,
45+ })
46+ end )
47+
48+ eq (is_test_file (" /path/to/my_test.cpp" ), true )
49+ eq (is_test_file (" /path/to/regular.cpp" ), false )
50+ eq (is_test_file (" /path/to/test.cpp" ), false )
51+ end
52+
3953return T
You can’t perform that action at this time.
0 commit comments