Skip to content

Commit 2dbc769

Browse files
committed
update docs
1 parent dbe8148 commit 2dbc769

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

docs/guide/best-practices/faq.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ Parameter description:
7171
- `-g, --good`: Specify a known good version (tag or commit)
7272
- `-b, --bad`: Specify a known bad version (tag or commit)
7373
- `--gitdir`: Specify the path to the xmake source repository
74-
- `-c, --command`: Specify the test command to verify if the current version is working correctly
74+
- `-c, --commands`: Specify test commands to verify if the current version is working correctly. Multiple commands can be executed, separated by semicolons
75+
- `-s, --script`: Run the given Lua script file for testing
76+
- `--`: Run an arbitrary command (specified after `--`)
77+
78+
::: tip NOTE
79+
If using a Lua script for testing, `os.exec` will automatically raise an error on failure, and git bisect will automatically mark it as a bad commit. You only need to use `raise()` to throw an error when you need custom check logic (such as checking output content).
80+
:::
7581

7682
### Example
7783

@@ -109,6 +115,37 @@ Date: Fri May 10 00:44:57 2024 +0800
109115

110116
This allows you to quickly locate the specific commit and changes that introduced the issue, making it easier to analyze and fix.
111117

118+
### Custom test scripts
119+
120+
In addition to using the `-c` parameter to execute commands, you can also use the `-s` parameter to run custom Lua scripts for more complex testing:
121+
122+
```sh
123+
$ xmake l cli.bisect -s /tmp/test.lua -g v2.9.1 -b v2.9.2 --gitdir=/Users/ruki/projects/personal/xmake
124+
```
125+
126+
In the Lua script, you need to put the test logic in the `main` function as the entry point. `os.exec` will automatically raise an error on failure, and git bisect will automatically mark it as a bad commit. If you need custom check logic (such as checking output content), you can use `raise()` to throw an error:
127+
128+
```lua
129+
-- test.lua
130+
function main()
131+
os.exec("xrepo remove --all -y")
132+
os.exec("xmake f -a arm64 -cvD -y")
133+
os.exec("xmake build")
134+
135+
-- If you need to check output content, you can use raise to throw an error
136+
local output = os.iorun("xmake run hello")
137+
if not output:find("expected output") then
138+
raise("test output mismatch")
139+
end
140+
end
141+
```
142+
143+
You can also use the `--` parameter to directly run arbitrary commands:
144+
145+
```sh
146+
$ xmake l cli.bisect -g 90846dd -b ddb86e4 --gitdir=/path/to/xmake -- xmake -rv
147+
```
148+
112149
## How to see verbose compiling warnings?
113150

114151
```sh

docs/zh/guide/best-practices/faq.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ $ xmake l cli.bisect -g <good_version> -b <bad_version> --gitdir=<xmake_repo_pat
7171
- `-g, --good`: 指定一个已知正常的版本(tag 或 commit)
7272
- `-b, --bad`: 指定一个已知有问题的版本(tag 或 commit)
7373
- `--gitdir`: 指定 xmake 源码仓库的路径
74-
- `-c, --command`: 指定测试命令,用于验证当前版本是否正常
74+
- `-c, --commands`: 指定测试命令,用于验证当前版本是否正常。可以执行多个命令,用分号分隔
75+
- `-s, --script`: 运行给定的 Lua 脚本文件进行测试
76+
- `--`: 运行任意命令(在 `--` 之后指定)
77+
78+
::: tip 提示
79+
如果使用 Lua 脚本进行测试,`os.exec` 执行失败时会自动报错,git bisect 会自动将其标记为 bad commit。只有在需要自定义检查逻辑(如检查输出内容)时,才需要使用 `raise()` 抛出错误。
80+
:::
7581

7682
### 示例
7783

@@ -109,6 +115,37 @@ Date: Fri May 10 00:44:57 2024 +0800
109115

110116
这样就能快速定位到引入问题的具体提交和修改内容,便于进一步分析和修复。
111117

118+
### 自定义测试脚本
119+
120+
除了使用 `-c` 参数执行命令外,你还可以使用 `-s` 参数运行自定义的 Lua 脚本进行更复杂的测试:
121+
122+
```sh
123+
$ xmake l cli.bisect -s /tmp/test.lua -g v2.9.1 -b v2.9.2 --gitdir=/Users/ruki/projects/personal/xmake
124+
```
125+
126+
在 Lua 脚本中,你需要将测试逻辑放在 `main` 函数中作为入口。`os.exec` 执行失败时会自动报错,git bisect 会自动将其标记为 bad commit。如果需要自定义检查逻辑(如检查输出内容),可以使用 `raise()` 抛出错误:
127+
128+
```lua
129+
-- test.lua
130+
function main()
131+
os.exec("xrepo remove --all -y")
132+
os.exec("xmake f -a arm64 -cvD -y")
133+
os.exec("xmake build")
134+
135+
-- 如果需要检查输出内容,可以使用 raise 抛出错误
136+
local output = os.iorun("xmake run hello")
137+
if not output:find("expected output") then
138+
raise("test output mismatch")
139+
end
140+
end
141+
```
142+
143+
也可以使用 `--` 参数直接运行任意命令:
144+
145+
```sh
146+
$ xmake l cli.bisect -g 90846dd -b ddb86e4 --gitdir=/path/to/xmake -- xmake -rv
147+
```
148+
112149
## 怎样看实时编译警告信息? {#see-verbose-compiling-warnings}
113150

114151
为了避免刷屏,在构建时默认是不实时输出警告信息的,如果想要查看,可以加上 `-w` 选项启用编译警告输出。

0 commit comments

Comments
 (0)