Skip to content

Commit

Permalink
Cfg'ed tests to match their feature requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnScience committed Aug 9, 2024
1 parent 5ed6a91 commit 82668ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ macro_rules! test_stream {
assert_eq!($stream.byte_offset(), 0);
$test
}
#[cfg(feature = "std")]
{
let mut bytes = $data.as_bytes();
let de = Deserializer::from_reader(&mut bytes);
Expand Down
13 changes: 10 additions & 3 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ use serde::de::{self, IgnoredAny, IntoDeserializer};
use serde::ser::{self, SerializeMap, SerializeSeq, Serializer};
use serde::{Deserialize, Serialize};
use serde_bytes::{ByteBuf, Bytes};
#[cfg(feature = "std")]
use serde_json::from_reader;
#[cfg(feature = "raw_value")]
use serde_json::value::RawValue;
use serde_json::{
from_reader, from_slice, from_str, from_value, json, to_string, to_string_pretty, to_value,
to_vec, Deserializer, Number, Value,
from_slice, from_str, from_value, json, to_string, to_string_pretty, to_value, to_vec,
Deserializer, Number, Value,
};
use std::collections::BTreeMap;
#[cfg(feature = "raw_value")]
Expand All @@ -39,6 +41,7 @@ use std::fmt::{self, Debug};
use std::hash::BuildHasher;
#[cfg(feature = "raw_value")]
use std::hash::{Hash, Hasher};
#[cfg(feature = "std")]
use std::io;
use std::iter;
use std::marker::PhantomData;
Expand Down Expand Up @@ -1622,7 +1625,7 @@ fn test_serialize_map_with_no_len() {
assert_eq!(s, expected);
}

#[cfg(not(miri))]
#[cfg(all(not(miri), feature = "std"))]
#[test]
fn test_deserialize_from_stream() {
use serde_json::to_writer;
Expand Down Expand Up @@ -2146,15 +2149,18 @@ fn test_partialeq_bool() {
assert_ne!(v, 0);
}

#[cfg(feature = "std")]
struct FailReader(io::ErrorKind);

#[cfg(feature = "std")]
impl io::Read for FailReader {
fn read(&mut self, _: &mut [u8]) -> io::Result<usize> {
Err(io::Error::new(self.0, "oh no!"))
}
}

#[test]
#[cfg(feature = "std")]
fn test_category() {
assert!(from_str::<String>("123").unwrap_err().is_data());

Expand Down Expand Up @@ -2195,6 +2201,7 @@ fn test_category() {
#[test]
// Clippy false positive: https://github.com/Manishearth/rust-clippy/issues/292
#[allow(clippy::needless_lifetimes)]
#[cfg(feature = "std")]
fn test_into_io_error() {
fn io_error<'de, T: Deserialize<'de> + Debug>(j: &'static str) -> io::Error {
from_str::<T>(j).unwrap_err().into()
Expand Down

0 comments on commit 82668ae

Please sign in to comment.