Skip to content

Commit

Permalink
Fix tests to compile without proc-macro2 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasKalbertodt committed Dec 19, 2022
1 parent 70e55b7 commit f38decc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/test_util.rs
@@ -1,5 +1,5 @@
use crate::*;
use std::{fmt::{Debug, Display}, convert::TryFrom};
use std::fmt::{Debug, Display};


#[track_caller]
Expand Down Expand Up @@ -39,12 +39,18 @@ pub(crate) fn assert_parse_ok_eq<T: PartialEq + Debug + Display>(
}
}

// This is not ideal, but to perform this check we need `proc-macro2`. So we
// just don't do anything if that feature is not enabled.
#[cfg(not(feature = "proc-macro2"))]
pub(crate) fn assert_roundtrip<T>(_: T, _: &str) {}

#[cfg(feature = "proc-macro2")]
#[track_caller]
pub(crate) fn assert_roundtrip<T>(ours: T, input: &str)
where
T: TryFrom<proc_macro2::Literal> + fmt::Debug + PartialEq + Clone,
T: std::convert::TryFrom<proc_macro2::Literal> + fmt::Debug + PartialEq + Clone,
proc_macro2::Literal: From<T>,
<T as TryFrom<proc_macro2::Literal>>::Error: std::fmt::Display,
<T as std::convert::TryFrom<proc_macro2::Literal>>::Error: std::fmt::Display,
{
let pm_lit = input.parse::<proc_macro2::Literal>()
.expect("failed to parse input as proc_macro2::Literal");
Expand Down

0 comments on commit f38decc

Please sign in to comment.