Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fuzz support #1033

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change feature to "arbitrary1".
The `dep:arbitrary` feature of cargo is unstable: https://doc.rust-lang.org/cargo/reference/unstable.html#namespaced-features
LegNeato committed Mar 1, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Gumball2415 Persune
commit 2b34ab0a784c0117635eee259f42fab1c79e897f
2 changes: 1 addition & 1 deletion juniper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ default = [
"url",
"uuid",
]
arbitrary = ["dep:arbitrary", "smartstring/arbitrary"]
arbitrary1 = ["arbitrary", "smartstring/arbitrary"]
expose-test-schema = ["anyhow", "serde_json"]
graphql-parser-integration = ["graphql-parser"]
scalar-naivetime = []
22 changes: 11 additions & 11 deletions juniper/src/ast.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ pub enum Type<'a> {
NonNullList(Box<Type<'a>>, Option<usize>),
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a> arbitrary::Arbitrary<'a> for Type<'a> {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
let num_choices = 4;
@@ -57,7 +57,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Type<'a> {
/// Lists and objects variants are _spanned_, i.e. they contain a reference to
/// their position in the source file, if available.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub enum InputValue<S = DefaultScalarValue> {
Null,
Scalar(S),
@@ -75,7 +75,7 @@ pub struct VariableDefinition<'a, S> {
pub directives: Option<Vec<Spanning<Directive<'a, S>>>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for VariableDefinition<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -99,7 +99,7 @@ pub struct Arguments<'a, S> {
pub items: Vec<(Spanning<&'a str>, Spanning<InputValue<S>>)>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for Arguments<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -116,7 +116,7 @@ pub struct VariableDefinitions<'a, S> {
pub items: Vec<(Spanning<&'a str>, VariableDefinition<'a, S>)>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for VariableDefinitions<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -137,7 +137,7 @@ pub struct Field<'a, S> {
pub selection_set: Option<Vec<Selection<'a, S>>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for Field<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -166,7 +166,7 @@ pub struct FragmentSpread<'a, S> {
pub directives: Option<Vec<Spanning<Directive<'a, S>>>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for FragmentSpread<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -187,7 +187,7 @@ pub struct InlineFragment<'a, S> {
pub selection_set: Vec<Selection<'a, S>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for InlineFragment<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -228,7 +228,7 @@ pub enum Selection<'a, S = DefaultScalarValue> {
InlineFragment(Spanning<InlineFragment<'a, S>>),
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for Selection<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -253,7 +253,7 @@ pub struct Directive<'a, S> {
pub arguments: Option<Spanning<Arguments<'a, S>>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for Directive<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -266,7 +266,7 @@ where
}

#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
#[allow(missing_docs)]
pub enum OperationType {
Query,
4 changes: 2 additions & 2 deletions juniper/src/parser/lexer.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ pub struct Lexer<'a> {
///
/// This is only used for tagging how the lexer has interpreted a value literal
#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
#[allow(missing_docs)]
pub enum ScalarToken<'a> {
String(&'a str),
@@ -31,7 +31,7 @@ pub enum ScalarToken<'a> {

/// A single token in the input source
#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
#[allow(missing_docs)]
pub enum Token<'a> {
Name(&'a str),
4 changes: 2 additions & 2 deletions juniper/src/parser/utils.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use std::fmt;

/// A reference to a line and column in an input source file
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct SourcePosition {
index: usize,
line: usize,
@@ -15,7 +15,7 @@ pub struct SourcePosition {
/// character pointed by the `start` field and ending just before the `end`
/// marker.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct Spanning<T> {
/// The wrapped item
pub item: T,
32 changes: 16 additions & 16 deletions juniper/src/schema/meta.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ use crate::{

/// Whether an item is deprecated, with context.
#[derive(Debug, PartialEq, Hash, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub enum DeprecationStatus {
/// The field/variant is not deprecated.
Current,
@@ -55,7 +55,7 @@ pub struct ScalarMeta<'a, S> {
pub(crate) parse_fn: for<'b> fn(ScalarToken<'b>) -> Result<S, ParseError<'b>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for ScalarMeta<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -114,7 +114,7 @@ where

/// List type metadata
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct ListMeta<'a> {
#[doc(hidden)]
pub of_type: Type<'a>,
@@ -125,15 +125,15 @@ pub struct ListMeta<'a> {

/// Nullable type metadata
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct NullableMeta<'a> {
#[doc(hidden)]
pub of_type: Type<'a>,
}

/// Object type metadata
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct ObjectMeta<'a, S> {
#[doc(hidden)]
pub name: Cow<'a, str>,
@@ -146,7 +146,7 @@ pub struct ObjectMeta<'a, S> {
}

/// Enum type metadata
//#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
//#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct EnumMeta<'a, S> {
#[doc(hidden)]
pub name: Cow<'a, str>,
@@ -157,7 +157,7 @@ pub struct EnumMeta<'a, S> {
pub(crate) try_parse_fn: for<'b> fn(&'b InputValue<S>) -> Result<(), FieldError<S>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for EnumMeta<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -198,7 +198,7 @@ where

/// Interface type metadata
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct InterfaceMeta<'a, S> {
#[doc(hidden)]
pub name: Cow<'a, str>,
@@ -210,7 +210,7 @@ pub struct InterfaceMeta<'a, S> {

/// Union type metadata
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct UnionMeta<'a> {
#[doc(hidden)]
pub name: Cow<'a, str>,
@@ -221,7 +221,7 @@ pub struct UnionMeta<'a> {
}

/// Input object metadata
//#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
//#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct InputObjectMeta<'a, S> {
#[doc(hidden)]
pub name: Cow<'a, str>,
@@ -232,7 +232,7 @@ pub struct InputObjectMeta<'a, S> {
pub(crate) try_parse_fn: for<'b> fn(&'b InputValue<S>) -> Result<(), FieldError<S>>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for InputObjectMeta<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -276,7 +276,7 @@ where
/// After a type's `meta` method has been called but before it has returned, a placeholder type
/// is inserted into a registry to indicate existence.
#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct PlaceholderMeta<'a> {
#[doc(hidden)]
pub of_type: Type<'a>,
@@ -305,7 +305,7 @@ pub enum MetaType<'a, S = DefaultScalarValue> {
Placeholder(PlaceholderMeta<'a>),
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S> arbitrary::Arbitrary<'a> for MetaType<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -331,7 +331,7 @@ where

/// Metadata for a field
#[derive(Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct Field<'a, S> {
#[doc(hidden)]
pub name: smartstring::alias::String,
@@ -355,7 +355,7 @@ impl<'a, S> Field<'a, S> {

/// Metadata for an argument to a field
#[derive(Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct Argument<'a, S> {
#[doc(hidden)]
pub name: String,
@@ -377,7 +377,7 @@ impl<'a, S> Argument<'a, S> {

/// Metadata for a single value in an enum
#[derive(Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct EnumValue {
/// The name of the enum value
///
10 changes: 5 additions & 5 deletions juniper/src/schema/model.rs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ pub struct RootNode<
pub schema: SchemaType<'a, S>,
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, QueryT, MutationT, SubscriptionT, S> arbitrary::Arbitrary<'a>
for RootNode<'a, QueryT, MutationT, SubscriptionT, S>
where
@@ -97,7 +97,7 @@ pub struct SchemaType<'a, S> {

impl<'a, S> Context for SchemaType<'a, S> {}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S: 'a> arbitrary::Arbitrary<'a> for SchemaType<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -147,7 +147,7 @@ pub enum TypeType<'a, S: 'a> {
List(Box<TypeType<'a, S>>, Option<usize>),
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, S: 'a> arbitrary::Arbitrary<'a> for TypeType<'a, S>
where
S: arbitrary::Arbitrary<'a>,
@@ -173,7 +173,7 @@ where
}

#[derive(Debug)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct DirectiveType<'a, S> {
pub name: String,
pub description: Option<String>,
@@ -183,7 +183,7 @@ pub struct DirectiveType<'a, S> {
}

#[derive(Clone, PartialEq, Eq, Debug, GraphQLEnum)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
#[graphql(name = "__DirectiveLocation", internal)]
pub enum DirectiveLocation {
Query,
2 changes: 1 addition & 1 deletion juniper/src/types/name.rs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ fn is_ascii_digit(c: char) -> bool {
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
pub struct Name(String);

impl Name {
4 changes: 2 additions & 2 deletions juniper/src/types/scalars.rs
Original file line number Diff line number Diff line change
@@ -408,7 +408,7 @@ impl<T> Default for EmptyMutation<T> {
}
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, T> arbitrary::Arbitrary<'a> for EmptyMutation<T>
where
T: arbitrary::Arbitrary<'a>,
@@ -478,7 +478,7 @@ impl<T> Default for EmptySubscription<T> {
}
}

#[cfg(feature = "arbitrary")]
#[cfg(feature = "arbitrary1")]
impl<'a, T> arbitrary::Arbitrary<'a> for EmptySubscription<T>
where
T: arbitrary::Arbitrary<'a>,
2 changes: 1 addition & 1 deletion juniper/src/value/scalar.rs
Original file line number Diff line number Diff line change
@@ -407,7 +407,7 @@ pub trait ScalarValue:
///
/// [0]: https://spec.graphql.org/June2018
#[derive(Clone, Debug, PartialEq, Serialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "arbitrary1", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
pub enum DefaultScalarValue {
/// [`Int` scalar][0] as a signed 32‐bit numeric non‐fractional value.