1010 TEST_WORKERS=4 lua bin/test.lua -- spawn 4 parallel workers (main spawns, then workers run slice)
1111 lua bin/test.lua --lua=C:\path\to\lua.exe
1212 set LUA_BIN=C:\path\to\lua.exe && lua bin/test.lua
13+ lua bin/test.lua --only=slug1,slug2 -- run only tests with these slugs
14+ lua bin/test.lua --ignore=slug1,slug2 -- skip tests with these slugs
1315]]
1416
15- -- Parse --lua=path and env LUA_BIN / LUA for Lua binary used when spawning workers
17+ -- Parse command-line arguments
1618local luaBin = os.getenv (" LUA_BIN" ) or os.getenv (" LUA" ) or " lua"
19+ local onlySlugs = {}
20+ local ignoreSlugs = {}
21+
1722for _ , a in ipairs (arg ) do
18- local path = a :match (" ^%-%-(lua)=(.+)$" )
19- if path then
20- luaBin = path
21- break
23+ local luaPath = a :match (" ^%-%-lua=(.+)$" )
24+ if luaPath then
25+ luaBin = luaPath
26+ end
27+
28+ local only = a :match (" ^%-%-only=(.+)$" )
29+ if only then
30+ for slug in only :gmatch (" [^,]+" ) do
31+ local trimmed = slug :gsub (" ^%s+" , " " ):gsub (" %s+$" , " " )
32+ if trimmed ~= " " then
33+ table.insert (onlySlugs , trimmed )
34+ end
35+ end
36+ end
37+
38+ local ignore = a :match (" ^%-%-ignore=(.+)$" )
39+ if ignore then
40+ for slug in ignore :gmatch (" [^,]+" ) do
41+ local trimmed = slug :gsub (" ^%s+" , " " ):gsub (" %s+$" , " " )
42+ if trimmed ~= " " then
43+ table.insert (ignoreSlugs , trimmed )
44+ end
45+ end
2246 end
2347end
2448
@@ -85,6 +109,40 @@ require("init")
85109-- Load test framework
86110local Test = require (" test" )
87111
112+ -- Apply slug filters from command-line arguments or environment variables
113+ local onlySlugsEnv = os.getenv (" TEST_ONLY_SLUGS" )
114+ local ignoreSlugsEnv = os.getenv (" TEST_IGNORE_SLUGS" )
115+
116+ if onlySlugsEnv and onlySlugsEnv ~= " " then
117+ for slug in onlySlugsEnv :gmatch (" [^,]+" ) do
118+ local trimmed = slug :gsub (" ^%s+" , " " ):gsub (" %s+$" , " " )
119+ if trimmed ~= " " then
120+ table.insert (Test .onlySlugs , trimmed )
121+ end
122+ end
123+ elseif # onlySlugs > 0 then
124+ Test .onlySlugs = onlySlugs
125+ end
126+
127+ if ignoreSlugsEnv and ignoreSlugsEnv ~= " " then
128+ for slug in ignoreSlugsEnv :gmatch (" [^,]+" ) do
129+ local trimmed = slug :gsub (" ^%s+" , " " ):gsub (" %s+$" , " " )
130+ if trimmed ~= " " then
131+ table.insert (Test .ignoreSlugs , trimmed )
132+ end
133+ end
134+ elseif # ignoreSlugs > 0 then
135+ Test .ignoreSlugs = ignoreSlugs
136+ end
137+
138+ -- Debug output for slug filters
139+ if # Test .onlySlugs > 0 then
140+ print (" Only running tests with slugs: " .. table.concat (Test .onlySlugs , " , " ))
141+ end
142+ if # Test .ignoreSlugs > 0 then
143+ print (" Ignoring tests with slugs: " .. table.concat (Test .ignoreSlugs , " , " ))
144+ end
145+
88146-- Cross-platform: list immediate subdirectories (no find on Windows)
89147local function discoverTestDirs (testsRoot )
90148 local dirs = {}
@@ -100,7 +158,8 @@ local function discoverTestDirs(testsRoot)
100158 for line in handle :lines () do
101159 local trimmed = line :gsub (" ^%s+" , " " ):gsub (" %s+$" , " " ):gsub (" \r " , " " )
102160 if trimmed ~= " " then
103- local full = pathForShell .. sep .. trimmed
161+ -- find returns full paths; dir /b returns names only
162+ local full = isAbsolute (trimmed ) and trimmed or (pathForShell .. sep .. trimmed )
104163 table.insert (dirs , full )
105164 end
106165 end
@@ -151,7 +210,8 @@ local workerId = os.getenv("TEST_WORKER") -- set when we are a worker
151210-- Main process: spawn N workers in parallel when TEST_WORKERS > 1 and we are not already a worker
152211if totalWorkers > 1 and workerId == nil then
153212 local scriptFull = projectRoot .. " bin" .. sep .. " test.lua"
154- local resultDir = (os.getenv (" TEMP" ) or os.getenv (" TMP" ) or " ." ) .. sep .. " deltachess_test_" .. tostring (math.random (100000 , 999999 ))
213+ local tmpBase = os.getenv (" TEMP" ) or os.getenv (" TMP" ) or (isWindows and " ." or " /tmp" )
214+ local resultDir = tmpBase .. sep .. " deltachess_test_" .. tostring (math.random (100000 , 999999 ))
155215 if isWindows then
156216 os.execute (" mkdir " .. escapeshellarg (resultDir ) .. " 2>nul" )
157217 else
@@ -207,6 +267,12 @@ if totalWorkers > 1 and workerId == nil then
207267 if luaBin ~= " lua" then
208268 line = line .. ' set "LUA_BIN=' .. batStr (luaBin ) .. ' "\r\n '
209269 end
270+ if # onlySlugs > 0 then
271+ line = line .. ' set "TEST_ONLY_SLUGS=' .. batStr (table.concat (onlySlugs , " ," )) .. ' "\r\n '
272+ end
273+ if # ignoreSlugs > 0 then
274+ line = line .. ' set "TEST_IGNORE_SLUGS=' .. batStr (table.concat (ignoreSlugs , " ," )) .. ' "\r\n '
275+ end
210276 line = line .. ' cd /d "' .. batStr (projectRoot :gsub (" /" , sep )) .. ' "\r\n '
211277 .. ' "' .. batStr (luaBin :gsub (" /" , sep )) .. ' " "' .. batStr (scriptFull :gsub (" /" , sep )) .. ' "\r\n '
212278 local f = io.open (batPath , " wb" )
@@ -228,6 +294,12 @@ if totalWorkers > 1 and workerId == nil then
228294 if luaBin ~= " lua" then
229295 shContent = shContent .. " export LUA_BIN=\" " .. forShDoubleQuotedValue (luaBin ) .. " \"\n "
230296 end
297+ if # onlySlugs > 0 then
298+ shContent = shContent .. " export TEST_ONLY_SLUGS=\" " .. forShDoubleQuotedValue (table.concat (onlySlugs , " ," )) .. " \"\n "
299+ end
300+ if # ignoreSlugs > 0 then
301+ shContent = shContent .. " export TEST_IGNORE_SLUGS=\" " .. forShDoubleQuotedValue (table.concat (ignoreSlugs , " ," )) .. " \"\n "
302+ end
231303 shContent = shContent .. " cd \" " .. forShDoubleQuotedValue (projectRoot ) .. " \" && exec \" "
232304 .. forShDoubleQuotedValue (luaBin ) .. " \" \" " .. forShDoubleQuotedValue (scriptFull ) .. " \"\n "
233305 local f = io.open (shPath , " wb" )
0 commit comments