Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests.md #1312

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update tests.md #1312

wants to merge 2 commits into from

Conversation

ShoreCN
Copy link
Contributor

@ShoreCN ShoreCN commented Oct 19, 2023

修复原文中的错误逻辑,此处测试用例必然失败

fix logic error
Copy link
Owner

@sunface sunface left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额?不对吧。。。

@ShoreCN
Copy link
Contributor Author

ShoreCN commented Nov 2, 2023

额?不对吧。。。

我的理解是,从这一章节的描述来看,就是先书写一个注定失败的测试用例,然后再进行逐步实现完善。
当前此第一步骤目的就是“注定失败的测试用例”。

  1. 从实际执行结果来看,这个测试用例也是失败的。
$ cargo test
   Compiling minigrep v0.1.0 (file:///projects/minigrep)
    Finished test [unoptimized + debuginfo] target(s) in 0.97s
     Running unittests src/lib.rs (target/debug/deps/minigrep-9cd200e5fac0fc94)

running 1 test
test tests::one_result ... FAILED

failures:

---- tests::one_result stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `["safe, fast, productive."]`,
 right: `[]`', src/lib.rs:44:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::one_result

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `--lib`
  1. 从语言组织表达来说,原文的“成功通过“和”居心叵测“也未呈现结果转折的含义

先添加一个简单的 search 函数实现,非常简单粗暴的返回一个空的数组,显而易见测试用例将成功通过,真是一个居心叵测的测试用例!

不知我是否有理解偏差的地方。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants