11local Job = require (" plenary.job" )
22local utils = require (" cmake-tools.utils" )
3- local const = require (" cmake-tools.const" )
43
54local ctest = {
65 job = nil ,
@@ -24,7 +23,16 @@ function ctest.list_all_tests(build_dir, callback)
2423
2524 local tests = {}
2625 for _ , item in ipairs (result .tests ) do
27- table.insert (tests , item [" name" ])
26+ local labels = {}
27+ if item [" properties" ] then
28+ for _ , prop in ipairs (item [" properties" ]) do
29+ if prop [" name" ] == " LABELS" then
30+ labels = prop [" value" ] or {}
31+ break
32+ end
33+ end
34+ end
35+ table.insert (tests , { name = item [" name" ], labels = labels })
2836 end
2937 callback (tests )
3038 end )
@@ -34,12 +42,36 @@ function ctest.list_all_tests(build_dir, callback)
3442 ctest .job :start ()
3543end
3644
45+ --- Collect all labels from test objects with counts
46+ --- @param tests { name : string , labels : string[] } []
47+ --- @return { label : string , count : number } [] sorted list of labels with their test counts
48+ function ctest .get_all_labels (tests )
49+ local label_counts = {}
50+ for _ , test in ipairs (tests ) do
51+ for _ , label in ipairs (test .labels ) do
52+ label_counts [label ] = (label_counts [label ] or 0 ) + 1
53+ end
54+ end
55+
56+ local labels = {}
57+ for label , count in pairs (label_counts ) do
58+ table.insert (labels , { label = label , count = count })
59+ end
60+ table.sort (labels , function (a , b )
61+ return a .label < b .label
62+ end )
63+ return labels
64+ end
65+
3766function ctest .run (ctest_command , test_name , build_dir , env , config , opt )
3867 local cmd = ctest_command
3968 opt = opt or {}
4069
4170 local args = { " --test-dir" , utils .transform_path (build_dir ) }
42- if test_name then
71+ if opt .label then
72+ table.insert (args , " -L" )
73+ table.insert (args , opt .label )
74+ elseif test_name then
4375 table.insert (args , " -R" )
4476 table.insert (args , test_name )
4577 end
0 commit comments