Skip to content

Commit 41b9e65

Browse files
bors[bot]japaric
andcommitted
68: catch panics in tests r=japaric a=japaric so we can print the inputs that triggered the panic Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 0a3a5e2 + 037836a commit 41b9e65

File tree

1 file changed

+157
-66
lines changed

1 file changed

+157
-66
lines changed

test-generator/src/main.rs

Lines changed: 157 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ macro_rules! f32_f32 {
6262
6363
extern crate libm;
6464
65+
use std::panic;
66+
6567
#[test]
6668
fn {0}() {{
6769
const CASES: &[(u32, u32)] = &[
@@ -71,16 +73,23 @@ macro_rules! f32_f32 {
7173
for case in CASES {{
7274
let (inp, expected) = *case;
7375
74-
let outf = libm::{0}(f32::from_bits(inp));
75-
let outi = outf.to_bits();
76-
77-
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
78-
libm::_eqf(outi, expected)) {{
76+
if let Ok(outf) =
77+
panic::catch_unwind(|| libm::{0}(f32::from_bits(inp)))
78+
{{
79+
let outi = outf.to_bits();
80+
81+
if !((outf.is_nan() && f32::from_bits(expected).is_nan())
82+
|| libm::_eqf(outi, expected))
83+
{{
84+
panic!(
85+
\"input: {{}}, output: {{}}, expected: {{}}\",
86+
inp, outi, expected,
87+
);
88+
}}
89+
}} else {{
7990
panic!(
80-
\"input: {{}}, output: {{}}, expected: {{}}\",
81-
inp,
82-
outi,
83-
expected,
91+
\"input: {{}}, output: PANIC, expected: {{}}\",
92+
inp, expected,
8493
);
8594
}}
8695
}}
@@ -124,6 +133,8 @@ macro_rules! f32f32_f32 {
124133
125134
extern crate libm;
126135
136+
use std::panic;
137+
127138
#[test]
128139
fn {0}() {{
129140
const CASES: &[((u32, u32), u32)] = &[
@@ -133,15 +144,25 @@ macro_rules! f32f32_f32 {
133144
for case in CASES {{
134145
let ((i1, i2), expected) = *case;
135146
136-
let outf = libm::{0}(f32::from_bits(i1), f32::from_bits(i2));
137-
let outi = outf.to_bits();
138-
139-
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
140-
libm::_eqf(outi, expected)) {{
147+
if let Ok(outf) = panic::catch_unwind(|| {{
148+
libm::{0}(f32::from_bits(i1), f32::from_bits(i2))
149+
}}) {{
150+
let outi = outf.to_bits();
151+
152+
if !((outf.is_nan() && f32::from_bits(expected).is_nan())
153+
|| libm::_eqf(outi, expected))
154+
{{
155+
panic!(
156+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
157+
(i1, i2),
158+
outi,
159+
expected,
160+
);
161+
}}
162+
}} else {{
141163
panic!(
142-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
164+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
143165
(i1, i2),
144-
outi,
145166
expected,
146167
);
147168
}}
@@ -188,6 +209,8 @@ macro_rules! f32f32f32_f32 {
188209
189210
extern crate libm;
190211
212+
use std::panic;
213+
191214
#[test]
192215
fn {0}() {{
193216
const CASES: &[((u32, u32, u32), u32)] = &[
@@ -197,19 +220,29 @@ macro_rules! f32f32f32_f32 {
197220
for case in CASES {{
198221
let ((i1, i2, i3), expected) = *case;
199222
200-
let outf = libm::{0}(
201-
f32::from_bits(i1),
202-
f32::from_bits(i2),
203-
f32::from_bits(i3),
204-
);
205-
let outi = outf.to_bits();
206-
207-
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
208-
libm::_eqf(outi, expected)) {{
223+
if let Ok(outf) = panic::catch_unwind(|| {{
224+
libm::{0}(
225+
f32::from_bits(i1),
226+
f32::from_bits(i2),
227+
f32::from_bits(i3),
228+
)
229+
}}) {{
230+
let outi = outf.to_bits();
231+
232+
if !((outf.is_nan() && f32::from_bits(expected).is_nan())
233+
|| libm::_eqf(outi, expected))
234+
{{
235+
panic!(
236+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
237+
(i1, i2, i3),
238+
outi,
239+
expected,
240+
);
241+
}}
242+
}} else {{
209243
panic!(
210-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
244+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
211245
(i1, i2, i3),
212-
outi,
213246
expected,
214247
);
215248
}}
@@ -253,6 +286,8 @@ macro_rules! f32i32_f32 {
253286
254287
extern crate libm;
255288
289+
use std::panic;
290+
256291
#[test]
257292
fn {0}() {{
258293
const CASES: &[((u32, i16), u32)] = &[
@@ -262,15 +297,25 @@ macro_rules! f32i32_f32 {
262297
for case in CASES {{
263298
let ((i1, i2), expected) = *case;
264299
265-
let outf = libm::{0}(f32::from_bits(i1), i2 as i32);
266-
let outi = outf.to_bits();
267-
268-
if !((outf.is_nan() && f32::from_bits(expected).is_nan()) ||
269-
libm::_eqf(outi, expected)) {{
300+
if let Ok(outf) = panic::catch_unwind(|| {{
301+
libm::{0}(f32::from_bits(i1), i2 as i32)
302+
}}) {{
303+
let outi = outf.to_bits();
304+
305+
if !((outf.is_nan() && f32::from_bits(expected).is_nan())
306+
|| libm::_eqf(outi, expected))
307+
{{
308+
panic!(
309+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
310+
(i1, i2),
311+
outi,
312+
expected,
313+
);
314+
}}
315+
}} else {{
270316
panic!(
271-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
317+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
272318
(i1, i2),
273-
outi,
274319
expected,
275320
);
276321
}}
@@ -314,6 +359,8 @@ macro_rules! f64_f64 {
314359
315360
extern crate libm;
316361
362+
use std::panic;
363+
317364
#[test]
318365
fn {0}() {{
319366
const CASES: &[(u64, u64)] = &[
@@ -323,15 +370,25 @@ macro_rules! f64_f64 {
323370
for case in CASES {{
324371
let (inp, expected) = *case;
325372
326-
let outf = libm::{0}(f64::from_bits(inp));
327-
let outi = outf.to_bits();
328-
329-
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
330-
libm::_eq(outi, expected)) {{
373+
if let Ok(outf) = panic::catch_unwind(|| {{
374+
libm::{0}(f64::from_bits(inp))
375+
}}) {{
376+
let outi = outf.to_bits();
377+
378+
if !((outf.is_nan() && f64::from_bits(expected).is_nan())
379+
|| libm::_eq(outi, expected))
380+
{{
381+
panic!(
382+
\"input: {{}}, output: {{}}, expected: {{}}\",
383+
inp,
384+
outi,
385+
expected,
386+
);
387+
}}
388+
}} else {{
331389
panic!(
332-
\"input: {{}}, output: {{}}, expected: {{}}\",
390+
\"input: {{}}, output: PANIC, expected: {{}}\",
333391
inp,
334-
outi,
335392
expected,
336393
);
337394
}}
@@ -376,6 +433,8 @@ macro_rules! f64f64_f64 {
376433
377434
extern crate libm;
378435
436+
use std::panic;
437+
379438
#[test]
380439
fn {0}() {{
381440
const CASES: &[((u64, u64), u64)] = &[
@@ -385,15 +444,24 @@ macro_rules! f64f64_f64 {
385444
for case in CASES {{
386445
let ((i1, i2), expected) = *case;
387446
388-
let outf = libm::{0}(f64::from_bits(i1), f64::from_bits(i2));
389-
let outi = outf.to_bits();
390-
391-
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
392-
libm::_eq(outi, expected)) {{
447+
if let Ok(outf) = panic::catch_unwind(|| {{
448+
libm::{0}(f64::from_bits(i1), f64::from_bits(i2))
449+
}}) {{
450+
let outi = outf.to_bits();
451+
452+
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
453+
libm::_eq(outi, expected)) {{
454+
panic!(
455+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
456+
(i1, i2),
457+
outi,
458+
expected,
459+
);
460+
}}
461+
}} else {{
393462
panic!(
394-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
463+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
395464
(i1, i2),
396-
outi,
397465
expected,
398466
);
399467
}}
@@ -440,6 +508,8 @@ macro_rules! f64f64f64_f64 {
440508
441509
extern crate libm;
442510
511+
use std::panic;
512+
443513
#[test]
444514
fn {0}() {{
445515
const CASES: &[((u64, u64, u64), u64)] = &[
@@ -449,19 +519,29 @@ macro_rules! f64f64f64_f64 {
449519
for case in CASES {{
450520
let ((i1, i2, i3), expected) = *case;
451521
452-
let outf = libm::{0}(
453-
f64::from_bits(i1),
454-
f64::from_bits(i2),
455-
f64::from_bits(i3),
456-
);
457-
let outi = outf.to_bits();
458-
459-
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
460-
libm::_eq(outi, expected)) {{
522+
if let Ok(outf) = panic::catch_unwind(|| {{
523+
libm::{0}(
524+
f64::from_bits(i1),
525+
f64::from_bits(i2),
526+
f64::from_bits(i3),
527+
)
528+
}}) {{
529+
let outi = outf.to_bits();
530+
531+
if !((outf.is_nan() && f64::from_bits(expected).is_nan())
532+
|| libm::_eq(outi, expected))
533+
{{
534+
panic!(
535+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
536+
(i1, i2, i3),
537+
outi,
538+
expected,
539+
);
540+
}}
541+
}} else {{
461542
panic!(
462-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
543+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
463544
(i1, i2, i3),
464-
outi,
465545
expected,
466546
);
467547
}}
@@ -505,6 +585,8 @@ macro_rules! f64i32_f64 {
505585
506586
extern crate libm;
507587
588+
use std::panic;
589+
508590
#[test]
509591
fn {0}() {{
510592
const CASES: &[((u64, i16), u64)] = &[
@@ -514,15 +596,24 @@ macro_rules! f64i32_f64 {
514596
for case in CASES {{
515597
let ((i1, i2), expected) = *case;
516598
517-
let outf = libm::{0}(f64::from_bits(i1), i2 as i32);
518-
let outi = outf.to_bits();
519-
520-
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
521-
libm::_eq(outi, expected)) {{
599+
if let Ok(outf) = panic::catch_unwind(|| {{
600+
libm::{0}(f64::from_bits(i1), i2 as i32)
601+
}}) {{
602+
let outi = outf.to_bits();
603+
604+
if !((outf.is_nan() && f64::from_bits(expected).is_nan()) ||
605+
libm::_eq(outi, expected)) {{
606+
panic!(
607+
\"input: {{:?}}, output: {{}}, expected: {{}}\",
608+
(i1, i2),
609+
outi,
610+
expected,
611+
);
612+
}}
613+
}} else {{
522614
panic!(
523-
\"input: {{:?}}, output: {{}}, expected: {{}}\",
615+
\"input: {{:?}}, output: PANIC, expected: {{}}\",
524616
(i1, i2),
525-
outi,
526617
expected,
527618
);
528619
}}

0 commit comments

Comments
 (0)