1.6 Testing : Test should pass rather than fail
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- rust
- 领域
- documentation, testing
调研方向
先从 issue 中链接的测试教程和所展示的 CLI 测试开始,然后运行 cargo test --test cli 以重现不匹配。将断言与命令报告的 stderr 进行比较,并调整示例,使测试与文档中记录的错误相匹配;当测试报告有一个通过的测试时即表示完成。
由索引模型根据 Issue 内容生成。
描述
Below test with more description can be found at
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions
use std::process::Command; // Run programs
#[test]
fn file_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("grrs")?;
cmd.arg("foobar").arg("test/file/doesnt/exist");
cmd.assert()
.failure()
.stderr(predicate::str::contains("could not read file"));
Ok(())
}
My Expectation:
grss rightly throws the exception when file does not exist. This test should capture the exception and should be pass as it has captured the right exception. But on running 'cargo test', this test is reported as failure.
Current Result:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s
IMO Expected Result
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s
Output of cargo test:
` Running tests/cli.rs (target/debug/deps/cli-5cefbff21b07bd9f)
running 1 test
test file_doesnt_exist ... FAILED
failures:
---- file_doesnt_exist stdout ----
thread 'file_doesnt_exist' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5:
Unexpected stderr, failed var.contains(could not read file)
├── var: Error: Could not read file 'test/file/doesnt/exists'
│
│ Caused by:
│ No such file or directory (os error 2)
└── var as str: Error: Could not read file 'test/file/doesnt/exists'
Caused by:
No such file or directory (os error 2)
command="/Users/admin/Kishor/SxT/repos/grrs/target/debug/grrs" "foobar" "test/file/doesnt/exists"
code=1
stdout=""
stderr=```
Error: Could not read file 'test/file/doesnt/exists'
Caused by:
No such file or directory (os error 2)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
file_doesnt_exist
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s
error: test failed, to rerun pass `--test cli`
`
- 主要语言
- Rust
- 星标
- 1.1k
- 派生
- 122
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-cli/book 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 35/100
-
documentation
难度 2/5 1-3 小时 新手友好度 45/100
-
bug
难度 5/5 一周以上 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 35/100
相似的 Issue
-
agent:iq3-xxs area: cli duplication enhancement priority: P3 ready-for-agent
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
bytecodealliance/rustix#1703 ·
维护者通常 3 天内回复
-
bug discussion
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
farion1231/cc-switch#8298 ·
维护者通常 1 天内回复