Skip to content

Commit 208542c

Browse files
authored
Merge pull request #3013 from fesily/unittest-support-test-specify-unit
unittest: support test specify unit test
2 parents fc21ee4 + ddf2788 commit 208542c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5+
* `NEW` Test CLI: `--name=<testname>` `-n=<testname>`: run specify unit test
56
* `FIX` Fixed the error that the configuration file pointed to by the `--configpath` option was not read and loaded.
67

78
## 3.13.5

test.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ DEVELOP = true
1010
--TRACE = true
1111
LOGPATH = LOGPATH or (ROOT:string() .. '/log')
1212
METAPATH = METAPATH or (ROOT:string() .. '/meta')
13+
TARGET_TEST_NAME = nil
14+
15+
if arg then
16+
for _, v in pairs(arg) do
17+
if v:sub(1, 3) == "-n=" or v:sub(1, 7) == "--name=" then
18+
TARGET_TEST_NAME = v:sub(v:find('=') + 1)
19+
end
20+
end
21+
end
1322

1423
collectgarbage 'generational'
1524

@@ -34,7 +43,11 @@ local function loadAllLibs()
3443
assert(require 'lpeglabel')
3544
end
3645

46+
---@param name string
3747
local function test(name)
48+
if TARGET_TEST_NAME and not name:match(TARGET_TEST_NAME) then
49+
return
50+
end
3851
local clock = os.clock()
3952
print(('测试[%s]...'):format(name))
4053
local originRequire = require

0 commit comments

Comments
 (0)