From 5b360d5a8090db3b74dd2b7a1c70931a1ee62c0a Mon Sep 17 00:00:00 2001 From: fesily Date: Sat, 28 Dec 2024 14:17:46 +0800 Subject: [PATCH] unittest: support test specify unit test --- changelog.md | 1 + test.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/changelog.md b/changelog.md index bdea8e280..4909c58c1 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `NEW` Test CLI: `--name=` `-n=`: run specify unit test ## 3.13.5 `2024-12-20` diff --git a/test.lua b/test.lua index 1ede0b3ed..bd1d8cb06 100644 --- a/test.lua +++ b/test.lua @@ -10,6 +10,15 @@ DEVELOP = true --TRACE = true LOGPATH = LOGPATH or (ROOT:string() .. '/log') METAPATH = METAPATH or (ROOT:string() .. '/meta') +TARGET_TEST_NAME = nil + +if arg then + for _, v in pairs(arg) do + if v:sub(1, 3) == "-n=" or v:sub(1, 7) == "--name=" then + TARGET_TEST_NAME = v:sub(v:find('=') + 1) + end + end +end collectgarbage 'generational' @@ -34,7 +43,11 @@ local function loadAllLibs() assert(require 'lpeglabel') end +---@param name string local function test(name) + if TARGET_TEST_NAME and not name:match(TARGET_TEST_NAME) then + return + end local clock = os.clock() print(('测试[%s]...'):format(name)) local originRequire = require