Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbla authored Dec 7, 2019
2 parents f062553 + 7845a98 commit e8290f1
Show file tree
Hide file tree
Showing 17 changed files with 471 additions and 399 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- 1.30.0
- 1.34.0
- stable
- beta
- nightly
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickcheck"
version = "0.8.5" #:version
version = "0.9.0" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = "Automatic property based testing with shrinking."
documentation = "http://burntsushi.net/rustdoc/quickcheck/"
Expand All @@ -11,6 +11,7 @@ keywords = ["testing", "quickcheck", "property", "shrinking", "fuzz"]
categories = ["development-tools::testing"]
license = "Unlicense/MIT"
exclude = ["/.travis.yml", "/Makefile", "/ctags.rust", "/session.vim"]
edition = "2018"

[workspace]
members = ["quickcheck_macros"]
Expand All @@ -27,5 +28,5 @@ name = "quickcheck"
[dependencies]
env_logger = { version = "0.6.0", default-features = false, optional = true }
log = { version = "0.4", optional = true }
rand = "0.6.5"
rand_core = "0.4.0"
rand = "0.7"
rand_core = "0.5"
85 changes: 0 additions & 85 deletions benches/tuples.rs

This file was deleted.

6 changes: 4 additions & 2 deletions examples/btree_set_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type RangeAny<T> = (Bound<T>, Bound<T>);

/// Mimic `RangeBounds::contains`, stabilized in Rust 1.35.
trait RangeBounds<T> {
fn contains(&self, &T) -> bool;
fn contains(&self, _: &T) -> bool;
}
impl<T: PartialOrd> RangeBounds<T> for RangeAny<T> {
fn contains(&self, item: &T) -> bool {
Expand Down Expand Up @@ -44,7 +44,9 @@ fn check_range(set: BTreeSet<i32>, range: RangeAny<i32>) -> TestResult {
TestResult::discard()
} else {
let xs: BTreeSet<_> = set.range(range).cloned().collect();
TestResult::from_bool(set.iter().all(|x| range.contains(x) == xs.contains(x)))
TestResult::from_bool(
set.iter().all(|x| range.contains(x) == xs.contains(x)),
)
}
}

Expand Down
6 changes: 2 additions & 4 deletions examples/out_of_bounds.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
extern crate quickcheck;

use quickcheck::{TestResult, quickcheck};
use quickcheck::{quickcheck, TestResult};

fn main() {
fn prop(length: usize, index: usize) -> TestResult {
let v: Vec<_> = (0..length).collect();
if index < length {
TestResult::discard()
} else {
TestResult::must_fail(move || {
v[index]
})
TestResult::must_fail(move || v[index])
}
}
quickcheck(prop as fn(usize, usize) -> TestResult);
Expand Down
2 changes: 1 addition & 1 deletion examples/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate quickcheck;
use quickcheck::quickcheck;

fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
let mut rev = vec!();
let mut rev = vec![];
for x in xs {
rev.insert(0, x.clone())
}
Expand Down
6 changes: 3 additions & 3 deletions examples/reverse_single.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate quickcheck;

use quickcheck::{TestResult, quickcheck};
use quickcheck::{quickcheck, TestResult};

fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
let mut rev = vec!();
let mut rev = vec![];
for x in xs {
rev.insert(0, x.clone())
}
Expand All @@ -13,7 +13,7 @@ fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
fn main() {
fn prop(xs: Vec<isize>) -> TestResult {
if xs.len() != 1 {
return TestResult::discard()
return TestResult::discard();
}
TestResult::from_bool(xs == reverse(&*xs))
}
Expand Down
15 changes: 8 additions & 7 deletions examples/sieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ fn sieve(n: usize) -> Vec<usize> {
return vec![];
}

let mut marked = vec![false; n+1];
let mut marked = vec![false; n + 1];
marked[0] = true;
marked[1] = true;
marked[2] = true;
for p in 2..n {
for i in (2*p..n).filter(|&n| n % p == 0) {
for i in (2 * p..n).filter(|&n| n % p == 0) {
marked[i] = true;
}
}
marked.iter()
.enumerate()
.filter_map(|(i, &m)| if m { None } else { Some(i) })
.collect()
marked
.iter()
.enumerate()
.filter_map(|(i, &m)| if m { None } else { Some(i) })
.collect()
}

fn is_prime(n: usize) -> bool {
n != 0 && n != 1 && (2..).take_while(|i| i*i <= n).all(|i| n % i != 0)
n != 0 && n != 1 && (2..).take_while(|i| i * i <= n).all(|i| n % i != 0)
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn larger_than<T: Clone + Ord>(xs: &[T], pivot: &T) -> Vec<T> {
}

fn sortk<T: Clone + Ord>(x: &T, xs: &[T]) -> Vec<T> {
let mut result : Vec<T> = sort(&*smaller_than(xs, x));
let mut result: Vec<T> = sort(&*smaller_than(xs, x));
let last_part = sort(&*larger_than(xs, x));
result.push(x.clone());
result.extend(last_part.iter().map(|x| x.clone()));
Expand All @@ -33,7 +33,7 @@ fn main() {
fn is_sorted(xs: Vec<isize>) -> bool {
for win in xs.windows(2) {
if win[0] > win[1] {
return false
return false;
}
}
true
Expand Down
4 changes: 2 additions & 2 deletions quickcheck_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickcheck_macros"
version = "0.8.0" #:version
version = "0.9.0" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = "A macro attribute for quickcheck."
documentation = "http://burntsushi.net/rustdoc/quickcheck/"
Expand All @@ -22,4 +22,4 @@ quote = "0.6.8"
syn = { version = "0.15", features = ["full"] }

[dev-dependencies]
quickcheck = { path = "..", version = "0.8.0" }
quickcheck = { path = "..", version = "0.9.0" }
2 changes: 1 addition & 1 deletion quickcheck_macros/examples/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate quickcheck_macros;
use quickcheck_macros::quickcheck;

fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
let mut rev = vec!();
let mut rev = vec![];
for x in xs {
rev.insert(0, x.clone())
}
Expand Down
27 changes: 14 additions & 13 deletions quickcheck_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{
parse::{Parse, Parser},
spanned::Spanned,
parse_quote,
spanned::Spanned,
};


#[proc_macro_attribute]
pub fn quickcheck(_args: TokenStream, input: TokenStream) -> TokenStream {
let output = match syn::Item::parse.parse(input.clone()) {
Expand All @@ -24,13 +23,11 @@ pub fn quickcheck(_args: TokenStream, input: TokenStream) -> TokenStream {
item_fn.decl.inputs.iter().for_each(|input| match *input {
syn::FnArg::Captured(syn::ArgCaptured { ref ty, .. }) => {
inputs.push(parse_quote!(_: #ty));
},
_ => {
errors.push(syn::parse::Error::new(
input.span(),
"unsupported kind of function argument",
))
},
}
_ => errors.push(syn::parse::Error::new(
input.span(),
"unsupported kind of function argument",
)),
});

if errors.is_empty() {
Expand All @@ -56,9 +53,12 @@ pub fn quickcheck(_args: TokenStream, input: TokenStream) -> TokenStream {
}
}
} else {
errors.iter().map(syn::parse::Error::to_compile_error).collect()
errors
.iter()
.map(syn::parse::Error::to_compile_error)
.collect()
}
},
}
Ok(syn::Item::Static(mut item_static)) => {
let attrs = mem::replace(&mut item_static.attrs, Vec::new());
let name = &item_static.ident;
Expand All @@ -71,10 +71,11 @@ pub fn quickcheck(_args: TokenStream, input: TokenStream) -> TokenStream {
::quickcheck::quickcheck(#name)
}
}
},
}
_ => {
let span = proc_macro2::TokenStream::from(input).span();
let msg = "#[quickcheck] is only supported on statics and functions";
let msg =
"#[quickcheck] is only supported on statics and functions";

syn::parse::Error::new(span, msg).to_compile_error()
}
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 79
use_small_heuristics = "max"
Loading

0 comments on commit e8290f1

Please sign in to comment.