i18nsite opened a new pull request, #3283:
URL: https://github.com/apache/kvrocks/pull/3283
[English](#en) / [中文](#cn)
---
<a id="en"></a>
## Support Running Specific Test Files in x.py
### Summary
This PR enhances the `x.py test` command to support running specific Go test
files directly, making it more convenient for developers to run targeted tests
during development.
### Motivation
Previously, to run tests from a specific file, developers had to:
- Navigate to the test directory
- Use the full `go test` command with all necessary parameters
- Or run all tests with `./x.py test go`
This PR simplifies the workflow by allowing developers to specify test files
directly.
### Changes
1. **Added `find_test_file()` helper function**
- Searches for test files in `tests/gocase` directory
- Supports fuzzy matching with partial paths
2. **Enhanced `test_go()` function**
- Added optional `test_target` parameter (defaults to `'./...'`)
- Allows targeting specific test files or packages
3. **Introduced `run_test()` dispatcher**
- Replaces the previous subparser-based approach
- Handles three modes: `cpp`, `go`, and file-based execution
- Automatically detects and runs specified test files
4. **Simplified command-line interface**
- Removed nested subparsers for cleaner syntax
- Uses `REMAINDER` argument parsing for flexibility
### Usage Examples
```bash
# Run all tests in a specific file
./x.py test stream/stream_test.go
# Run specific tests matching a pattern
./x.py test stream/stream_test.go -run TestStream/XADD
# Previous commands still work
./x.py test go # Run all Go tests
./x.py test cpp # Run all C++ tests
```
### Testing
Tested with:
- `./x.py test stream/stream_test.go` - Successfully runs all tests in the
file
- `./x.py test stream/stream_test.go -run TestStream/XADD` - Successfully
runs specific test
- `./x.py test go` - Backward compatibility verified
- `./x.py test --help` - Help message updated correctly
---
<a id="cn"></a>
## 支持在 x.py 中运行指定的测试文件
### 概述
本 PR 增强了 `x.py test` 命令,使其支持直接运行指定的 Go 测试文件,让开发者在开发过程中更方便地运行针对性测试。
### 动机
以前,要运行特定文件中的测试,开发者必须:
- 导航到测试目录
- 使用完整的 `go test` 命令及所有必需参数
- 或者用 `./x.py test go` 运行所有测试
本 PR 通过允许开发者直接指定测试文件来简化工作流程。
### 变更内容
1. **添加了 `find_test_file()` 辅助函数**
- 在 `tests/gocase` 目录中搜索测试文件
- 支持使用部分路径进行模糊匹配
2. **增强了 `test_go()` 函数**
- 添加了可选的 `test_target` 参数(默认为 `'./...'`)
- 允许针对特定测试文件或包
3. **引入了 `run_test()` 调度器**
- 替换了之前基于子解析器的方法
- 处理三种模式:`cpp`、`go` 和基于文件的执行
- 自动检测并运行指定的测试文件
4. **简化了命令行界面**
- 移除了嵌套的子解析器,使语法更简洁
- 使用 `REMAINDER` 参数解析以提供更大灵活性
### 使用示例
```bash
# 运行特定文件中的所有测试
./x.py test stream/stream_test.go
# 运行匹配特定模式的测试
./x.py test stream/stream_test.go -run TestStream/XADD
# 之前的命令仍然有效
./x.py test go # 运行所有 Go 测试
./x.py test cpp # 运行所有 C++ 测试
```
### 测试
已通过以下测试:
- `./x.py test stream/stream_test.go` - 成功运行文件中的所有测试
- `./x.py test stream/stream_test.go -run TestStream/XADD` - 成功运行特定测试
- `./x.py test go` - 验证向后兼容性
- `./x.py test --help` - 帮助信息正确更新
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]