Skip to content

Commit b89225e

Browse files
committed
Fix test on MacOS
1 parent ac11505 commit b89225e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/compare_to_libc.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ fn test_float() {
8282
check_fmt("% 7.4E", -120.3);
8383
check_fmt("%-10F", f64::INFINITY);
8484
check_fmt("%+010F", f64::INFINITY);
85-
check_fmt("% f", f64::NAN);
86-
check_fmt("%+f", f64::NAN);
8785
check_fmt("%.1f", 999.99);
8886
check_fmt("%.1f", 9.99);
8987
check_fmt("%.1e", 9.99);
@@ -99,6 +97,15 @@ fn test_float() {
9997
check_fmt("%.1f", 2.599);
10098
check_fmt("%.1e", 2.599);
10199
check_fmt("%.1g", 2.599);
100+
101+
// MacOS libc behaves differently from glibc for nan. glibc is the reference implementation.
102+
if cfg!(target_env = "gnu") {
103+
check_fmt("% f", f64::NAN);
104+
check_fmt("%+f", f64::NAN);
105+
} else {
106+
assert_eq!(sprintf!("% f", f64::NAN).unwrap(), " nan");
107+
assert_eq!(sprintf!("%+f", f64::NAN).unwrap(), "+nan");
108+
}
102109
}
103110

104111
#[test]

0 commit comments

Comments
 (0)