File tree Expand file tree Collapse file tree 9 files changed +219
-481
lines changed
listings/ch11-writing-automated-tests
no-listing-03-introducing-a-bug
no-listing-07-custom-failure-message/src
no-listing-08-guess-with-bug/src
no-listing-09-guess-with-panic-msg-bug/src Expand file tree Collapse file tree 9 files changed +219
-481
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ mod tests {
8
8
9
9
#[ test]
10
10
fn another ( ) {
11
+ //このテストを失敗させる
11
12
panic ! ( "Make this test fail" ) ;
12
13
}
13
14
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ pub struct Guess {
6
6
impl Guess {
7
7
pub fn new ( value : i32 ) -> Guess {
8
8
if value < 1 || value > 100 {
9
+ //予想値は1から100の間でなければなりませんが、{}でした。
9
10
panic ! ( "Guess value must be between 1 and 100, got {}." , value) ;
10
11
}
11
12
Original file line number Diff line number Diff line change @@ -8,11 +8,13 @@ impl Guess {
8
8
pub fn new ( value : i32 ) -> Guess {
9
9
if value < 1 {
10
10
panic ! (
11
+ //予想値は1以上でなければなりませんが、{}でした。
11
12
"Guess value must be greater than or equal to 1, got {}." ,
12
13
value
13
14
) ;
14
15
} else if value > 100 {
15
16
panic ! (
17
+ //予想値は100以下でなければなりませんが、{}でした。
16
18
"Guess value must be less than or equal to 100, got {}." ,
17
19
value
18
20
) ;
@@ -27,6 +29,7 @@ mod tests {
27
29
use super :: * ;
28
30
29
31
#[ test]
32
+ //予想値は100以下でなければなりません
30
33
#[ should_panic( expected = "Guess value must be less than or equal to 100" ) ]
31
34
fn greater_than_100 ( ) {
32
35
Guess :: new ( 200 ) ;
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ failures:
11
11
12
12
---- tests::larger_can_hold_smaller stdout ----
13
13
thread 'main' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9
14
+ (スレッド'main'はsrc/lib.rs:28:9の'assertion failed: larger.can_hold(&smaller)'でパニックしました)
14
15
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
15
16
16
-
17
17
failures:
18
18
tests::larger_can_hold_smaller
19
19
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ mod tests {
12
12
let result = greeting ( "Carol" ) ;
13
13
assert ! (
14
14
result. contains( "Carol" ) ,
15
+ //挨拶(greeting)は名前を含んでいません。その値は`{}`でした
15
16
"Greeting did not contain name, value was `{}`" ,
16
17
result
17
18
) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub struct Guess {
7
7
impl Guess {
8
8
pub fn new ( value : i32 ) -> Guess {
9
9
if value < 1 {
10
+ //予想値は1から100の間でなければなりませんが、{}でした。
10
11
panic ! ( "Guess value must be between 1 and 100, got {}." , value) ;
11
12
}
12
13
Original file line number Diff line number Diff line change @@ -7,11 +7,13 @@ impl Guess {
7
7
// ANCHOR: here
8
8
if value < 1 {
9
9
panic ! (
10
+ //予想値は100以下でなければなりませんが、{}でした。
10
11
"Guess value must be less than or equal to 100, got {}." ,
11
12
value
12
13
) ;
13
14
} else if value > 100 {
14
15
panic ! (
16
+ //予想値は1以上でなければなりませんが、{}でした。
15
17
"Guess value must be greater than or equal to 1, got {}." ,
16
18
value
17
19
) ;
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ Rust言語の2018 Editionには、Rustをもっと扱いやすく、学びやす
47
47
-->
48
48
- 7章「肥大化していくプロジェクトをパッケージ、クレート、モジュールを利用して管理する」はほとんど書き直されました。2018 Editionにおいてモジュールシステムとパスの仕組みはより一貫性を持つようになりました。
49
49
- 10章には、新しい` impl Trait ` 構文を説明するために「引数としてのトレイト」と「トレイトを実装している型を返す」という新しい節があります。
50
- - 11章には、` ? ` 演算子を使うテストの書き方を説明する "Using ` Result<T, E> ` in Tests" という新しい節があります。
50
+ - 11章には、` ? ` 演算子を使うテストの書き方を説明する「 ` Result<T, E> ` をテストで使う」 という新しい節があります。
51
51
- 19章の「高度なライフタイム」節はなくなりました。コンパイラの改善により、この節の内容が現れることはいっそう稀になったからです。
52
52
- 付録D「マクロ」は、手続き的マクロも説明するようになり、19章の「マクロ」節に移動しました。
53
53
- 付録A「キーワード」では、2015 Editionと2018 Editionで書かれたコードを一緒に使えるようにしてくれる、生識別子という新しい機能も説明します。
You can’t perform that action at this time.
0 commit comments