@@ -38,8 +38,11 @@ crate.
38
38
` tests ` 内の各ファイルは個別の[ 統合テスト] ( https://doc.rust-lang.org/book/ch11-03-test-organization.html#integration-tests ) です。
39
39
これはライブラリを依存クレートから呼ばれたかのようにテストできます。
40
40
41
+ <!--
41
42
The [Testing][testing] chapter elaborates on the three different testing styles:
42
43
[Unit][unit_testing], [Doc][doc_testing], and [Integration][integration_testing].
44
+ -->
45
+ [ テスト] [ testing ] の章は3つの異なるテストスタイルについて解説しています:[ 単体テスト] [ unit_testing ] 、[ ドキュメンテーションテスト] [ doc_testing ] 、そして[ 結合テスト] [ integration_testing ] です。
43
46
44
47
<!--
45
48
`cargo` naturally provides an easy way to run all of your tests!
@@ -98,44 +101,54 @@ that they don't race with each other.
98
101
-->
99
102
注意:Cargoは複数のテストを並列で実行することがありますので、それらが互いに競合しないようにしてください。
100
103
104
+ <!--
101
105
One example of this concurrency causing issues is if two tests output to a
102
106
file, such as below:
107
+ -->
108
+ 並行性が問題を引き起こす一例として、以下のように、2つのテストが1つのファイルに出力するケースがあります。
103
109
104
110
``` rust
105
111
#[cfg(test)]
106
112
mod tests {
107
113
// Import the necessary modules
114
+ // 必要なモジュールをインポートする。
108
115
use std :: fs :: OpenOptions ;
109
116
use std :: io :: Write ;
110
117
111
118
// This test writes to a file
119
+ // ファイルに書き込むテスト。
112
120
#[test]
113
121
fn test_file () {
114
122
// Opens the file ferris.txt or creates one if it doesn't exist.
123
+ // ferris.txtというファイルを開くか、存在しない場合は作成する。
115
124
let mut file = OpenOptions :: new ()
116
125
. append (true )
117
126
. create (true )
118
127
. open (" ferris.txt" )
119
128
. expect (" Failed to open ferris.txt" );
120
129
121
130
// Print "Ferris" 5 times.
131
+ // "Ferris"と5回書き込む。
122
132
for _ in 0 .. 5 {
123
133
file . write_all (" Ferris\ n" . as_bytes ())
124
134
. expect (" Could not write to ferris.txt" );
125
135
}
126
136
}
127
137
128
138
// This test tries to write to the same file
139
+ // 同じファイルに書き込むテスト。
129
140
#[test]
130
141
fn test_file_also () {
131
142
// Opens the file ferris.txt or creates one if it doesn't exist.
143
+ // ferris.txtというファイルを開くか、存在しない場合は作成する。
132
144
let mut file = OpenOptions :: new ()
133
145
. append (true )
134
146
. create (true )
135
147
. open (" ferris.txt" )
136
148
. expect (" Failed to open ferris.txt" );
137
149
138
150
// Print "Corro" 5 times.
151
+ // "Corro"と5回書き込む。
139
152
for _ in 0 .. 5 {
140
153
file . write_all (" Corro\ n" . as_bytes ())
141
154
. expect (" Could not write to ferris.txt" );
@@ -144,7 +157,10 @@ mod tests {
144
157
}
145
158
```
146
159
160
+ <!--
147
161
Although the intent is to get the following:
162
+ -->
163
+ 以下のような結果を得ようと意図しています。
148
164
``` shell
149
165
$ cat ferris.txt
150
166
Ferris
@@ -158,7 +174,10 @@ Corro
158
174
Corro
159
175
Corro
160
176
```
177
+ <!--
161
178
What actually gets put into `ferris.txt` is this:
179
+ -->
180
+ しかし、実際に` ferris.txt ` に出力されるのは、以下の通りです。
162
181
``` shell
163
182
$ cargo test test_foo
164
183
Corro
0 commit comments