Skip to content

Commit 1ffb6fd

Browse files
authored
Merge pull request #7135 from cakebaker/numfmt_replace_run
numfmt: use `succeeds()`/`fails()` instead of `run()` in tests
2 parents 74d80ea + de18b76 commit 1ffb6fd

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

tests/by-util/test_numfmt.rs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn test_from_si() {
3232
new_ucmd!()
3333
.args(&["--from=si"])
3434
.pipe_in("1000\n1.1M\n0.1G")
35-
.run()
35+
.succeeds()
3636
.stdout_is("1000\n1100000\n100000000\n");
3737
}
3838

@@ -41,7 +41,7 @@ fn test_from_iec() {
4141
new_ucmd!()
4242
.args(&["--from=iec"])
4343
.pipe_in("1024\n1.1M\n0.1G")
44-
.run()
44+
.succeeds()
4545
.stdout_is("1024\n1153434\n107374183\n");
4646
}
4747

@@ -50,7 +50,7 @@ fn test_from_iec_i() {
5050
new_ucmd!()
5151
.args(&["--from=iec-i"])
5252
.pipe_in("1.1Mi\n0.1Gi")
53-
.run()
53+
.succeeds()
5454
.stdout_is("1153434\n107374183\n");
5555
}
5656

@@ -74,7 +74,7 @@ fn test_from_auto() {
7474
new_ucmd!()
7575
.args(&["--from=auto"])
7676
.pipe_in("1K\n1Ki")
77-
.run()
77+
.succeeds()
7878
.stdout_is("1000\n1024\n");
7979
}
8080

@@ -83,7 +83,7 @@ fn test_to_si() {
8383
new_ucmd!()
8484
.args(&["--to=si"])
8585
.pipe_in("1000\n1100000\n100000000")
86-
.run()
86+
.succeeds()
8787
.stdout_is("1.0K\n1.1M\n100M\n");
8888
}
8989

@@ -92,7 +92,7 @@ fn test_to_iec() {
9292
new_ucmd!()
9393
.args(&["--to=iec"])
9494
.pipe_in("1024\n1153434\n107374182")
95-
.run()
95+
.succeeds()
9696
.stdout_is("1.0K\n1.2M\n103M\n");
9797
}
9898

@@ -101,15 +101,15 @@ fn test_to_iec_i() {
101101
new_ucmd!()
102102
.args(&["--to=iec-i"])
103103
.pipe_in("1024\n1153434\n107374182")
104-
.run()
104+
.succeeds()
105105
.stdout_is("1.0Ki\n1.2Mi\n103Mi\n");
106106
}
107107

108108
#[test]
109109
fn test_input_from_free_arguments() {
110110
new_ucmd!()
111111
.args(&["--from=si", "1K", "1.1M", "0.1G"])
112-
.run()
112+
.succeeds()
113113
.stdout_is("1000\n1100000\n100000000\n");
114114
}
115115

@@ -118,7 +118,7 @@ fn test_padding() {
118118
new_ucmd!()
119119
.args(&["--from=si", "--padding=8"])
120120
.pipe_in("1K\n1.1M\n0.1G")
121-
.run()
121+
.succeeds()
122122
.stdout_is(" 1000\n 1100000\n100000000\n");
123123
}
124124

@@ -127,7 +127,7 @@ fn test_negative_padding() {
127127
new_ucmd!()
128128
.args(&["--from=si", "--padding=-8"])
129129
.pipe_in("1K\n1.1M\n0.1G")
130-
.run()
130+
.succeeds()
131131
.stdout_is("1000 \n1100000 \n100000000\n");
132132
}
133133

@@ -136,7 +136,7 @@ fn test_header() {
136136
new_ucmd!()
137137
.args(&["--from=si", "--header=2"])
138138
.pipe_in("header\nheader2\n1K\n1.1M\n0.1G")
139-
.run()
139+
.succeeds()
140140
.stdout_is("header\nheader2\n1000\n1100000\n100000000\n");
141141
}
142142

@@ -145,31 +145,31 @@ fn test_header_default() {
145145
new_ucmd!()
146146
.args(&["--from=si", "--header"])
147147
.pipe_in("header\n1K\n1.1M\n0.1G")
148-
.run()
148+
.succeeds()
149149
.stdout_is("header\n1000\n1100000\n100000000\n");
150150
}
151151

152152
#[test]
153153
fn test_header_error_if_non_numeric() {
154154
new_ucmd!()
155155
.args(&["--header=two"])
156-
.run()
156+
.fails()
157157
.stderr_is("numfmt: invalid header value 'two'\n");
158158
}
159159

160160
#[test]
161161
fn test_header_error_if_0() {
162162
new_ucmd!()
163163
.args(&["--header=0"])
164-
.run()
164+
.fails()
165165
.stderr_is("numfmt: invalid header value '0'\n");
166166
}
167167

168168
#[test]
169169
fn test_header_error_if_negative() {
170170
new_ucmd!()
171171
.args(&["--header=-3"])
172-
.run()
172+
.fails()
173173
.stderr_is("numfmt: invalid header value '-3'\n");
174174
}
175175

@@ -178,25 +178,28 @@ fn test_negative() {
178178
new_ucmd!()
179179
.args(&["--from=si"])
180180
.pipe_in("-1000\n-1.1M\n-0.1G")
181-
.run()
181+
.succeeds()
182182
.stdout_is("-1000\n-1100000\n-100000000\n");
183183
new_ucmd!()
184184
.args(&["--to=iec-i"])
185185
.pipe_in("-1024\n-1153434\n-107374182")
186-
.run()
186+
.succeeds()
187187
.stdout_is("-1.0Ki\n-1.2Mi\n-103Mi\n");
188188
}
189189

190190
#[test]
191191
fn test_negative_zero() {
192-
new_ucmd!().pipe_in("-0\n-0.0").run().stdout_is("0\n0.0\n");
192+
new_ucmd!()
193+
.pipe_in("-0\n-0.0")
194+
.succeeds()
195+
.stdout_is("0\n0.0\n");
193196
}
194197

195198
#[test]
196199
fn test_no_op() {
197200
new_ucmd!()
198201
.pipe_in("1024\n1234567")
199-
.run()
202+
.succeeds()
200203
.stdout_is("1024\n1234567\n");
201204
}
202205

@@ -205,15 +208,15 @@ fn test_normalize() {
205208
new_ucmd!()
206209
.args(&["--from=si", "--to=si"])
207210
.pipe_in("10000000K\n0.001K")
208-
.run()
211+
.succeeds()
209212
.stdout_is("10G\n1\n");
210213
}
211214

212215
#[test]
213216
fn test_si_to_iec() {
214217
new_ucmd!()
215218
.args(&["--from=si", "--to=iec", "15334263563K"])
216-
.run()
219+
.succeeds()
217220
.stdout_is("14T\n");
218221
}
219222

@@ -222,7 +225,7 @@ fn test_should_report_invalid_empty_number_on_empty_stdin() {
222225
new_ucmd!()
223226
.args(&["--from=auto"])
224227
.pipe_in("\n")
225-
.run()
228+
.fails()
226229
.stderr_is("numfmt: invalid number: ''\n");
227230
}
228231

@@ -231,7 +234,7 @@ fn test_should_report_invalid_empty_number_on_blank_stdin() {
231234
new_ucmd!()
232235
.args(&["--from=auto"])
233236
.pipe_in(" \t \n")
234-
.run()
237+
.fails()
235238
.stderr_is("numfmt: invalid number: ''\n");
236239
}
237240

@@ -241,7 +244,7 @@ fn test_should_report_invalid_suffix_on_stdin() {
241244
new_ucmd!()
242245
.args(&["--from=auto"])
243246
.pipe_in(format!("1{}", c as char))
244-
.run()
247+
.fails()
245248
.stderr_is(format!(
246249
"numfmt: invalid suffix in input: '1{}'\n",
247250
c as char
@@ -252,7 +255,7 @@ fn test_should_report_invalid_suffix_on_stdin() {
252255
new_ucmd!()
253256
.args(&["--from=auto"])
254257
.pipe_in("NaN")
255-
.run()
258+
.fails()
256259
.stderr_is("numfmt: invalid suffix in input: 'NaN'\n");
257260
}
258261

@@ -262,7 +265,7 @@ fn test_should_report_invalid_number_with_interior_junk() {
262265
new_ucmd!()
263266
.args(&["--from=auto"])
264267
.pipe_in("1x0K")
265-
.run()
268+
.fails()
266269
.stderr_is("numfmt: invalid number: '1x0K'\n");
267270
}
268271

@@ -271,14 +274,14 @@ fn test_should_skip_leading_space_from_stdin() {
271274
new_ucmd!()
272275
.args(&["--from=auto"])
273276
.pipe_in(" 2Ki")
274-
.run()
277+
.succeeds()
275278
.stdout_is("2048\n");
276279

277280
// multi-line
278281
new_ucmd!()
279282
.args(&["--from=auto"])
280283
.pipe_in("\t1Ki\n 2K")
281-
.run()
284+
.succeeds()
282285
.stdout_is("1024\n2000\n");
283286
}
284287

@@ -287,7 +290,7 @@ fn test_should_convert_only_first_number_in_line() {
287290
new_ucmd!()
288291
.args(&["--from=auto"])
289292
.pipe_in("1Ki 2M 3G")
290-
.run()
293+
.succeeds()
291294
.stdout_is("1024 2M 3G\n");
292295
}
293296

@@ -296,13 +299,13 @@ fn test_leading_whitespace_should_imply_padding() {
296299
new_ucmd!()
297300
.args(&["--from=auto"])
298301
.pipe_in(" 1K")
299-
.run()
302+
.succeeds()
300303
.stdout_is(" 1000\n");
301304

302305
new_ucmd!()
303306
.args(&["--from=auto"])
304307
.pipe_in(" 202Ki")
305-
.run()
308+
.succeeds()
306309
.stdout_is(" 206848\n");
307310
}
308311

@@ -311,23 +314,23 @@ fn test_should_calculate_implicit_padding_per_line() {
311314
new_ucmd!()
312315
.args(&["--from=auto"])
313316
.pipe_in(" 1Ki\n 2K")
314-
.run()
317+
.succeeds()
315318
.stdout_is(" 1024\n 2000\n");
316319
}
317320

318321
#[test]
319322
fn test_leading_whitespace_in_free_argument_should_imply_padding() {
320323
new_ucmd!()
321324
.args(&["--from=auto", " 1Ki"])
322-
.run()
325+
.succeeds()
323326
.stdout_is(" 1024\n");
324327
}
325328

326329
#[test]
327330
fn test_should_calculate_implicit_padding_per_free_argument() {
328331
new_ucmd!()
329332
.args(&["--from=auto", " 1Ki", " 2K"])
330-
.run()
333+
.succeeds()
331334
.stdout_is(" 1024\n 2000\n");
332335
}
333336

0 commit comments

Comments
 (0)