Skip to content

Commit

Permalink
Update fuzzing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and jaymell committed May 25, 2022
1 parent b493b77 commit c305b2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ assert_approx_eq = "1.0"
fnv = "1.0.5"
futures = "0.3"
criterion = "0.3"
partial-io = { version = "0.3", features = ["tokio", "quickcheck"] }
quickcheck = "0.6"
partial-io = { version = "0.5", features = ["tokio", "quickcheck1"] }
quickcheck = "1.0.3"
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread", "time"] }
tempfile = "3.2"

Expand Down
34 changes: 20 additions & 14 deletions tests/parser.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
mod support;

#[macro_use]
extern crate quickcheck;

use std::{io, pin::Pin};

use redis::Value;
use {
futures::{
ready,
task::{self, Poll},
},
partial_io::{GenWouldBlock, PartialOp, PartialWithErrors},
partial_io::{quickcheck_types::GenWouldBlock, quickcheck_types::PartialWithErrors, PartialOp},
quickcheck::{quickcheck, Gen},
tokio::io::{AsyncRead, ReadBuf},
};

use redis::Value;

mod support;
use crate::support::{block_on_all, encode_value};

#[derive(Clone, Debug)]
struct ArbitraryValue(Value);

impl ::quickcheck::Arbitrary for ArbitraryValue {
fn arbitrary<G: ::quickcheck::Gen>(g: &mut G) -> Self {
fn arbitrary(g: &mut Gen) -> Self {
let size = g.size();
ArbitraryValue(arbitrary_value(g, size))
}

fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
match self.0 {
Value::Nil | Value::Okay => Box::new(None.into_iter()),
Expand All @@ -49,19 +47,19 @@ impl ::quickcheck::Arbitrary for ArbitraryValue {
}
}

fn arbitrary_value<G: ::quickcheck::Gen>(g: &mut G, recursive_size: usize) -> Value {
fn arbitrary_value(g: &mut Gen, recursive_size: usize) -> Value {
use quickcheck::Arbitrary;
if recursive_size == 0 {
Value::Nil
} else {
match g.gen_range(0, 6) {
match u8::arbitrary(g) % 6 {
0 => Value::Nil,
1 => Value::Int(Arbitrary::arbitrary(g)),
2 => Value::Data(Arbitrary::arbitrary(g)),
3 => {
let size = {
let s = g.size();
g.gen_range(0, s)
usize::arbitrary(g) % s
};
Value::Bulk(
(0..size)
Expand All @@ -72,9 +70,17 @@ fn arbitrary_value<G: ::quickcheck::Gen>(g: &mut G, recursive_size: usize) -> Va
4 => {
let size = {
let s = g.size();
g.gen_range(0, s)
usize::arbitrary(g) % s
};
let status = g.gen_ascii_chars().take(size).collect();

let mut status = String::with_capacity(size);
for _ in 0..size {
let c = char::arbitrary(g);
if c.is_ascii_alphabetic() {
status.push(c);
}
}

if status == "OK" {
Value::Okay
} else {
Expand Down

0 comments on commit c305b2b

Please sign in to comment.