From 66bf1092a58fb50279d263ba9e831435ace8e844 Mon Sep 17 00:00:00 2001 From: Ivan Nejgebauer Date: Fri, 8 Jul 2016 13:48:46 +0200 Subject: [PATCH] Add test for std::net::lookup_host() duplicates --- src/libstd/sys/common/net.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 26925b12f93d6..8b7af17f92b85 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -601,3 +601,22 @@ impl fmt::Debug for UdpSocket { .finish() } } + +#[cfg(test)] +mod tests { + use prelude::v1::*; + + use super::*; + use collections::HashMap; + + #[test] + fn no_lookup_host_duplicates() { + let mut addrs = HashMap::new(); + let lh = match lookup_host("localhost") { + Ok(lh) => lh, + Err(e) => panic!("couldn't resolve `localhost': {}", e) + }; + let _na = lh.map(|sa| *addrs.entry(sa).or_insert(0) += 1).count(); + assert!(addrs.values().filter(|&&v| v > 1).count() == 0); + } +}