{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang/book/pulls/comments/87894033","pull_request_review_id":8487075,"id":87894033,"diff_hunk":"@@ -0,0 +1,290 @@\n+# Testing\n+\n+> Program testing can be a very effective way to show the presence of bugs, but\n+> it is hopelessly inadequate for showing their absence.\n+>\n+> Edsger W. Dijkstra, \"The Humble Programmer\" (1972)\n+\n+Rust is a programming language that cares a lot about correctness. But\n+correctness is a complex topic, and isn't exactly easy to get right. Rust\n+places a lot of weight on its type system to help ensure that our programs do\n+what we intend, but it cannot help with everything. As such, Rust also includes\n+support for writing software tests in the language itself.\n+\n+Testing is a skill, and we cannot hope to learn everything about how to write\n+good tests in one chapter of a book. What we can learn, however, are the\n+mechanics of Rust's testing facilities. That's what we'll focus on in this\n+chapter.\n+\n+## The `test` attribute\n+\n+At its simplest, a test in Rust is a function that's annotated with the `test`\n+attribute. Let's make a new project with Cargo called `adder`:\n+\n+```bash\n+$ cargo new adder\n+     Created library `adder` project\n+$ cd adder\n+```\n+\n+Cargo will automatically generate a simple test when you make a new project.\n+Here's the contents of `src/lib.rs`:\n+\n+```rust\n+#[cfg(test)]\n+mod tests {\n+    #[test]\n+    fn it_works() {\n+    }\n+}\n+```\n+\n+For now, let's remove the `mod` bit, and focus on just the function:\n+\n+```rust\n+#[test]\n+fn it_works() {\n+}\n+```\n+\n+Note the `#[test]`. This attribute indicates that this is a test function. It\n+currently has no body. That's good enough to pass! We can run the tests with\n+`cargo test`:\n+\n+```bash\n+$ cargo test\n+   Compiling adder v0.1.0 (file:///projects/adder)\n+    Finished debug [unoptimized + debuginfo] target(s) in 0.22 secs\n+     Running target/debug/deps/adder-ce99bcc2479f4607\n+\n+running 1 test\n+test it_works ... ok\n+\n+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n+\n+   Doc-tests adder\n+\n+running 0 tests\n+\n+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n+```\n+\n+Cargo compiled and ran our tests. There are two sets of output here: one\n+for the test we wrote, and another for documentation tests. We'll talk about\n+documentation tests later. For now, see this line:\n+\n+```text\n+test it_works ... ok\n+```\n+\n+Note the `it_works`. This comes from the name of our function:\n+\n+```rust\n+fn it_works() {\n+# }\n+```\n+\n+We also get a summary line:\n+\n+```text\n+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n+```\n+\n+## The `assert!` macro\n+\n+So why does our do-nothing test pass? Any test which doesn't `panic!` passes,\n+and any test that does `panic!` fails. Let's make our test fail:","path":"src/chXX-00-testing.md","position":96,"original_position":96,"commit_id":"bb20edadf63702c6d41c5544b017436297254674","original_commit_id":"763c24dc9d2c3119f4f664118876deff70bfa9f8","user":{"login":"carols10cents","id":193874,"avatar_url":"https://avatars.githubusercontent.com/u/193874?v=3","gravatar_id":"","url":"https://api.github.com/users/carols10cents","html_url":"https://github.com/carols10cents","followers_url":"https://api.github.com/users/carols10cents/followers","following_url":"https://api.github.com/users/carols10cents/following{/other_user}","gists_url":"https://api.github.com/users/carols10cents/gists{/gist_id}","starred_url":"https://api.github.com/users/carols10cents/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carols10cents/subscriptions","organizations_url":"https://api.github.com/users/carols10cents/orgs","repos_url":"https://api.github.com/users/carols10cents/repos","events_url":"https://api.github.com/users/carols10cents/events{/privacy}","received_events_url":"https://api.github.com/users/carols10cents/received_events","type":"User","site_admin":false},"body":"I feel like with the amount we talk about `panic` in the error handling chapter, we shouldn't have to mention it again here. It'll be in the table of contents too.","created_at":"2016-11-14T21:14:57Z","updated_at":"2016-11-14T21:14:58Z","html_url":"https://github.com/rust-lang/book/pull/288#discussion_r87894033","pull_request_url":"https://api.github.com/repos/rust-lang/book/pulls/288","_links":{"self":{"href":"https://api.github.com/repos/rust-lang/book/pulls/comments/87894033"},"html":{"href":"https://github.com/rust-lang/book/pull/288#discussion_r87894033"},"pull_request":{"href":"https://api.github.com/repos/rust-lang/book/pulls/288"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang/book/pulls/288","id":88492866,"html_url":"https://github.com/rust-lang/book/pull/288","diff_url":"https://github.com/rust-lang/book/pull/288.diff","patch_url":"https://github.com/rust-lang/book/pull/288.patch","issue_url":"https://api.github.com/repos/rust-lang/book/issues/288","number":288,"state":"open","locked":false,"title":"new chapter: testing","user":{"login":"steveklabnik","id":27786,"avatar_url":"https://avatars.githubusercontent.com/u/27786?v=3","gravatar_id":"","url":"https://api.github.com/users/steveklabnik","html_url":"https://github.com/steveklabnik","followers_url":"https://api.github.com/users/steveklabnik/followers","following_url":"https://api.github.com/users/steveklabnik/following{/other_user}","gists_url":"https://api.github.com/users/steveklabnik/gists{/gist_id}","starred_url":"https://api.github.com/users/steveklabnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steveklabnik/subscriptions","organizations_url":"https://api.github.com/users/steveklabnik/orgs","repos_url":"https://api.github.com/users/steveklabnik/repos","events_url":"https://api.github.com/users/steveklabnik/events{/privacy}","received_events_url":"https://api.github.com/users/steveklabnik/received_events","type":"User","site_admin":false},"body":"I took some content from the old testing (and documentation) chapters, but also did a lot of re-writing/editing. Whatcha think @carols10cents ?\n","created_at":"2016-10-07T19:17:05Z","updated_at":"2016-11-14T21:14:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bfc60334b29ce08c1dd79a6bd0a3ef15f4b3d72c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang/book/pulls/288/commits","review_comments_url":"https://api.github.com/repos/rust-lang/book/pulls/288/comments","review_comment_url":"https://api.github.com/repos/rust-lang/book/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang/book/issues/288/comments","statuses_url":"https://api.github.com/repos/rust-lang/book/statuses/bb20edadf63702c6d41c5544b017436297254674","head":{"label":"rust-lang:testing","ref":"testing","sha":"bb20edadf63702c6d41c5544b017436297254674","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":47854924,"name":"book","full_name":"rust-lang/book","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/book","description":"The Rust Programming Language","fork":false,"url":"https://api.github.com/repos/rust-lang/book","forks_url":"https://api.github.com/repos/rust-lang/book/forks","keys_url":"https://api.github.com/repos/rust-lang/book/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/book/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/book/teams","hooks_url":"https://api.github.com/repos/rust-lang/book/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/book/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/book/events","assignees_url":"https://api.github.com/repos/rust-lang/book/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/book/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/book/tags","blobs_url":"https://api.github.com/repos/rust-lang/book/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/book/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/book/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/book/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/book/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/book/languages","stargazers_url":"https://api.github.com/repos/rust-lang/book/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/book/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/book/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/book/subscription","commits_url":"https://api.github.com/repos/rust-lang/book/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/book/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/book/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/book/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/book/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/book/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/book/merges","archive_url":"https://api.github.com/repos/rust-lang/book/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/book/downloads","issues_url":"https://api.github.com/repos/rust-lang/book/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/book/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/book/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/book/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/book/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/book/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/book/deployments","created_at":"2015-12-11T22:49:49Z","updated_at":"2016-11-14T16:16:04Z","pushed_at":"2016-11-14T21:09:31Z","git_url":"git://github.com/rust-lang/book.git","ssh_url":"git@github.com:rust-lang/book.git","clone_url":"https://github.com/rust-lang/book.git","svn_url":"https://github.com/rust-lang/book","homepage":"http://rust-lang.github.io/book/","size":8561,"stargazers_count":359,"watchers_count":359,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":88,"mirror_url":null,"open_issues_count":29,"forks":88,"open_issues":29,"watchers":359,"default_branch":"master"}},"base":{"label":"rust-lang:master","ref":"master","sha":"986e9390e4ad990d0edf9e8dd2d4ea88ace0f508","user":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":47854924,"name":"book","full_name":"rust-lang/book","owner":{"login":"rust-lang","id":5430905,"avatar_url":"https://avatars.githubusercontent.com/u/5430905?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang","html_url":"https://github.com/rust-lang","followers_url":"https://api.github.com/users/rust-lang/followers","following_url":"https://api.github.com/users/rust-lang/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang/subscriptions","organizations_url":"https://api.github.com/users/rust-lang/orgs","repos_url":"https://api.github.com/users/rust-lang/repos","events_url":"https://api.github.com/users/rust-lang/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang/book","description":"The Rust Programming Language","fork":false,"url":"https://api.github.com/repos/rust-lang/book","forks_url":"https://api.github.com/repos/rust-lang/book/forks","keys_url":"https://api.github.com/repos/rust-lang/book/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang/book/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang/book/teams","hooks_url":"https://api.github.com/repos/rust-lang/book/hooks","issue_events_url":"https://api.github.com/repos/rust-lang/book/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang/book/events","assignees_url":"https://api.github.com/repos/rust-lang/book/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang/book/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang/book/tags","blobs_url":"https://api.github.com/repos/rust-lang/book/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang/book/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang/book/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang/book/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang/book/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang/book/languages","stargazers_url":"https://api.github.com/repos/rust-lang/book/stargazers","contributors_url":"https://api.github.com/repos/rust-lang/book/contributors","subscribers_url":"https://api.github.com/repos/rust-lang/book/subscribers","subscription_url":"https://api.github.com/repos/rust-lang/book/subscription","commits_url":"https://api.github.com/repos/rust-lang/book/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang/book/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang/book/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang/book/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang/book/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang/book/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang/book/merges","archive_url":"https://api.github.com/repos/rust-lang/book/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang/book/downloads","issues_url":"https://api.github.com/repos/rust-lang/book/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang/book/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang/book/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang/book/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang/book/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang/book/releases{/id}","deployments_url":"https://api.github.com/repos/rust-lang/book/deployments","created_at":"2015-12-11T22:49:49Z","updated_at":"2016-11-14T16:16:04Z","pushed_at":"2016-11-14T21:09:31Z","git_url":"git://github.com/rust-lang/book.git","ssh_url":"git@github.com:rust-lang/book.git","clone_url":"https://github.com/rust-lang/book.git","svn_url":"https://github.com/rust-lang/book","homepage":"http://rust-lang.github.io/book/","size":8561,"stargazers_count":359,"watchers_count":359,"language":"Shell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":88,"mirror_url":null,"open_issues_count":29,"forks":88,"open_issues":29,"watchers":359,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang/book/pulls/288"},"html":{"href":"https://github.com/rust-lang/book/pull/288"},"issue":{"href":"https://api.github.com/repos/rust-lang/book/issues/288"},"comments":{"href":"https://api.github.com/repos/rust-lang/book/issues/288/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang/book/pulls/288/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang/book/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang/book/pulls/288/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang/book/statuses/bb20edadf63702c6d41c5544b017436297254674"}}}}
{"actor":{"display_login":"carols10cents"}}