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

ch15 スマートポインタの和訳を最新版に更新 #263

Open
wants to merge 17 commits into
base: master-ja
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
499278e
ch00 はじめにの和訳を最新版に更新
shinmili May 26, 2024
7573273
ch01 事始めの和訳を最新版に更新
shinmili May 26, 2024
cc34c09
ch02 数当てゲームのプログラミングの和訳を最新版に更新
shinmili May 26, 2024
49f93be
ch03 一般的なプログラミングの概念の和訳を最新版に更新
shinmili May 26, 2024
005ab57
ch04 所有権を理解するの和訳を最新版に更新
shinmili May 26, 2024
7dce9e1
ch05 構造体を使用して関係のあるデータを構造化するの和訳を最新版に更新
shinmili May 26, 2024
0de9bcf
ch06 Enumとパターンマッチングの和訳を最新版に更新
shinmili May 26, 2024
20bed51
ch07 肥大化していくプロジェクトをパッケージ、クレート、モジュールを利用して管理するの和訳を最新版に更新
shinmili May 26, 2024
d2d9bbb
ch08 一般的なコレクションの和訳を最新版に更新
shinmili May 26, 2024
0f629e7
ch09 エラー処理の和訳を最新版に更新
shinmili May 26, 2024
4eabca9
ch10 ジェネリック型、トレイト、ライフタイムの和訳を最新版に更新
shinmili May 26, 2024
09725f3
ch11 自動テストを書くの和訳を最新版に更新
shinmili May 26, 2024
fcc533b
ch12 入出力プロジェクト: コマンドラインプログラムを構築するの和訳を最新版に更新
shinmili May 26, 2024
239347a
ch13 関数型言語の機能: イテレータとクロージャの和訳を最新版に更新
shinmili May 26, 2024
2296c28
ch14 CargoとCrates.ioについてより詳しくの和訳を最新版に更新
shinmili May 26, 2024
97d8397
ch15 スマートポインタの和訳を最新版に更新
shinmili May 26, 2024
f35ad6c
消し忘れた段落を削除
shinmili Dec 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ch11 自動テストを書くの和訳を最新版に更新
  • Loading branch information
shinmili committed May 26, 2024
commit 09725f3921c3ff5354eebbf0259d98c6defacf23

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.57s
Running target/debug/deps/adder-92948b65e88960b4
Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4)

running 1 test
test tests::it_works ... ok

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

Doc-tests adder

running 0 tests

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

13 changes: 8 additions & 5 deletions listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// ANCHOR: here
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
let result = add(2, 2);
assert_eq!(result, 4);
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
11 changes: 6 additions & 5 deletions listings/ch11-writing-automated-tests/listing-11-03/output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.72s
Running target/debug/deps/adder-92948b65e88960b4
Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4)

running 2 tests
test tests::another ... FAILED
Expand All @@ -10,13 +10,14 @@ test tests::exploration ... ok
failures:

---- tests::another stdout ----
thread 'main' panicked at 'Make this test fail', src/lib.rs:10:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'tests::another' panicked at src/lib.rs:10:9:
Make this test fail
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
tests::another

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

error: test failed, to rerun pass '--lib'
error: test failed, to rerun pass `--lib`
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ mod tests {
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "rectangle"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ impl Rectangle {
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "rectangle"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$ cargo test
Compiling rectangle v0.1.0 (file:///projects/rectangle)
Finished test [unoptimized + debuginfo] target(s) in 0.66s
Running target/debug/deps/rectangle-6584c4561e48942e
Running unittests src/lib.rs (target/debug/deps/rectangle-6584c4561e48942e)

running 1 test
test tests::larger_can_hold_smaller ... ok

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

Doc-tests rectangle

running 0 tests

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

Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ mod tests {
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running target/debug/deps/adder-92948b65e88960b4
Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4)

running 1 test
test tests::it_adds_two ... ok

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

Doc-tests adder

running 0 tests

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: here
pub fn add_two(a: i32) -> i32 {
a + 2
}
Expand All @@ -12,6 +11,3 @@ mod tests {
assert_eq!(4, add_two(2));
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$ cargo test
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running target/debug/deps/guessing_game-57d70c3acb738f4d
Running unittests src/lib.rs (target/debug/deps/guessing_game-57d70c3acb738f4d)

running 1 test
test tests::greater_than_100 ... ok
test tests::greater_than_100 - should panic ... ok

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

Doc-tests guessing_game

running 0 tests

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: here
pub struct Guess {
value: i32,
}
Expand All @@ -24,6 +23,3 @@ mod tests {
Guess::new(200);
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Guess {

// ANCHOR: here
// --snip--

impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
Expand All @@ -29,12 +30,10 @@ mod tests {
use super::*;

#[test]
//予想値は100以下でなければなりません
#[should_panic(expected = "Guess value must be less than or equal to 100")]
//100以下
#[should_panic(expected = "less than or equal to 100")]
fn greater_than_100() {
Guess::new(200);
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "silly-function"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
15 changes: 8 additions & 7 deletions listings/ch11-writing-automated-tests/listing-11-10/output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$ cargo test
Compiling silly-function v0.1.0 (file:///projects/silly-function)
Finished test [unoptimized + debuginfo] target(s) in 0.58s
Running target/debug/deps/silly_function-160869f38cff9166
Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166)

running 2 tests
test tests::this_test_will_fail ... FAILED
Expand All @@ -11,15 +11,16 @@ failures:

---- tests::this_test_will_fail stdout ----
I got the value 8
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `5`,
right: `10`', src/lib.rs:19:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9:
assertion `left == right` failed
left: 5
right: 10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
tests::this_test_will_fail

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

error: test failed, to rerun pass '--lib'
error: test failed, to rerun pass `--lib`
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
fn main() {}

// ANCHOR: here
fn prints_and_returns_10(a: i32) -> i32 {
//{}という値を得た
println!("I got the value {}", a);
10
}
Expand All @@ -22,4 +20,3 @@ mod tests {
assert_eq!(5, value);
}
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.62s
Running target/debug/deps/adder-92948b65e88960b4
Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4)

running 3 tests
test tests::add_three_and_two ... ok
test tests::add_two_and_two ... ok
test tests::one_hundred ... ok

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

Doc-tests adder

running 0 tests

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

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: here
pub fn add_two(a: i32) -> i32 {
internal_adder(a, 2)
}
Expand All @@ -16,6 +15,3 @@ mod tests {
assert_eq!(4, internal_adder(2, 2));
}
}
// ANCHOR_END: here

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
edition = "2021"

[dependencies]
Loading