You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "i18nsite (via GitHub)" <gi...@apache.org> on 2025/12/01 05:10:32 UTC

[PR] build: support running specific test files in x.py test command [kvrocks]

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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: support running specific test files in x.py test command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice closed pull request #3283: build: support running specific test files in x.py test command
URL: https://github.com/apache/kvrocks/pull/3283


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: support running specific test files in x.py test command [kvrocks]

Posted by "i18nsite (via GitHub)" <gi...@apache.org>.
i18nsite commented on PR #3283:
URL: https://github.com/apache/kvrocks/pull/3283#issuecomment-3594652195

   我的几点个人意见
   1. 现在 x.py 运行的帮助提示很不清楚,很多人可能没有看那个文档就直接运行,不知道有这种用法
   这个合并请求,让用法更加清楚
   <img width="590" height="496" alt="image" src="https://github.com/user-attachments/assets/bb61a3b6-e9fa-49c6-a935-7f23683cc22a" />
   
   2. 
   ./x.py test stream/stream_test.go
   
   这种用法
   
   比./x.py test go <BUILD_DIR> -run <PATTERN> 
   
   看起来更加直接
   
   我测试了一下`./x.py test go ./build -run TestStream`, 貌似还是运行了一堆乱七八糟的测试?没法运行某个文件的测试?
   
   ```
   
   ❯ ./x.py test go ./build -run TestStream
   $ /Users/z/.local/share/mise/installs/go/1.25.4/bin/go test -timeout=1800s -bench=. ./... -binPath=/Users/z/git/kvrocks/kvrocks/build/kvrocks -cliPath=redis-cli -workspace=/Users/z/git/kvrock
   s/kvrocks/tests/gocase/workspace -run TestStream
   PASS
   ok      github.com/apache/kvrocks/tests/gocase/integration/cli  0.015s
   PASS
   ok      github.com/apache/kvrocks/tests/gocase/integration/cli_options  0.014s
   PASS
   ok      github.com/apache/kvrocks/tests/gocase/integration/cluster      0.014s
   PASS
   ok      github.com/apache/kvrocks/tests/gocase/integration/replication  0.010s
   PASS
   ok      github.com/apache/kvrocks/tests/gocase/integration/rsid 0.009s
   
   ```
   <img width="1917" height="590" alt="image" src="https://github.com/user-attachments/assets/4132c4ff-4a1f-4990-81a8-3e60a66d5c75" />
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: support running specific test files in x.py test command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #3283:
URL: https://github.com/apache/kvrocks/pull/3283#issuecomment-3594669004

   You can use `./x.py test go <build-dir> <any-go-test-flags-here>`. Feel free to reopen if necessary.


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: support running specific test files in x.py test command [kvrocks]

Posted by "i18nsite (via GitHub)" <gi...@apache.org>.
i18nsite commented on PR #3283:
URL: https://github.com/apache/kvrocks/pull/3283#issuecomment-3594662467

   我知道,我就是感觉自己输入这么长的字符串,太累了,不方便
   
   go test -timeout=1800s -bench=. unit/type/stream/stream_test.go -binPath=/Users/z/git/kvrocks/kvrocks/build/kvrocks -cliPath=redis-cli -workspace=/Users/z/git/kvrocks/kvrocks/tests/gocase/workspace
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] build: support running specific test files in x.py test command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #3283:
URL: https://github.com/apache/kvrocks/pull/3283#issuecomment-3594660956

   Please refer to golang docs for this: https://pkg.go.dev/cmd/go#hdr-Testing_flags


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org