Giter Site home page Giter Site logo

Comments (10)

BurntSushi avatar BurntSushi commented on June 23, 2024

Compiler plugins can only be used on Rust nightlies. There are no immediate plans to change this. quickcheck_macros is a crate that defines a compiler plugin.

quickcheck_macros is an optional convenience. There is nothing useless about the main crate quickcheck. There are plenty of examples here: https://github.com/BurntSushi/quickcheck/tree/master/examples

from quickcheck.

russel avatar russel commented on June 23, 2024

I disagree #[quickcheck] being an optional convenience: if you are mixing example-based and property-based tests in the same file the documentation makes it appear essential to use this annotation. All the examples you point at are of free standing executables not of inputs to the standard test runner, which seems to back up my argument.

Of course QuickCheck is not useless, but the integration of the current system with the standard Rust test runner does appear to be since it relies on running nightlies. Companies will not run nightlies, they are unlikely to run beta, they will be running stable.

From your comment the problem is with the main Rust team who do not allow compiler plugins to run on stable. If this is the case then clearly the problem is there and that is what needs to be addressed.

from quickcheck.

BurntSushi avatar BurntSushi commented on June 23, 2024

Here is an example in my link:

extern crate quickcheck;

use quickcheck::{TestResult, quickcheck};

fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
    let mut rev = vec!();
    for x in xs {
        rev.insert(0, x.clone())
    }
    rev
}

fn main() {
    fn prop(xs: Vec<isize>) -> TestResult {
        if xs.len() != 1 {
            return TestResult::discard()
        }
        TestResult::from_bool(xs == reverse(&*xs))
    }
    quickcheck(prop as fn(Vec<isize>) -> TestResult);
}

Here is the same example, but using #[test]:

extern crate quickcheck;

use quickcheck::{TestResult, quickcheck};

fn reverse<T: Clone>(xs: &[T]) -> Vec<T> {
    let mut rev = vec!();
    for x in xs {
        rev.insert(0, x.clone())
    }
    rev
}

#[test]
fn prop_reverse() {
    fn prop(xs: Vec<isize>) -> TestResult {
        if xs.len() != 1 {
            return TestResult::discard()
        }
        TestResult::from_bool(xs == reverse(&*xs))
    }
    quickcheck(prop as fn(Vec<isize>) -> TestResult);
}

The #[quickcheck] annotation removes some boiler plate. That's it. The transformation is straight forward.

From your comment the problem is with the main Rust team who do not allow compiler plugins to run on stable. If this is the case then clearly the problem is there and that is what needs to be addressed.

It is being addressed. But it's going to take time and lots of work. It's still early days, but you can probably get a good idea of progress/current state from this thread: https://internals.rust-lang.org/t/the-future-of-syntax-extensions-and-macros/2889/34

from quickcheck.

BurntSushi avatar BurntSushi commented on June 23, 2024

To be clear, I use quickcheck in almost every single one of my published crates. I don't think I've ever used the #[quickcheck] annotation because I want to run things on Rust stable.

from quickcheck.

russel avatar russel commented on June 23, 2024

I was clearly overthinking – or maybe that should be underthinking – this. Apologies. This now puts me on the right road.

That thread is interesting. Benchmarking definitely is a topic for me.

I suspect an article on quickcheck in Rust would go down very well indeed in CVu or Overload (the journals of ACCU). http://accu.org

from quickcheck.

FranklinChen avatar FranklinChen commented on June 23, 2024

I was sad to lose the macro annotation, but have made do, e.g., in https://github.com/FranklinChen/type-directed-tdd-rust

Eek, just noticed my README is rather out of date.

from quickcheck.

russel avatar russel commented on June 23, 2024

I think I should (so will) take this one to the forum: all the example use a function as parameter, does this imply you cannot use a closure?

from quickcheck.

BurntSushi avatar BurntSushi commented on June 23, 2024

@russel I'm hesitant to say "cannot," but I can say, "I haven't figured out how yet." The pertinent issue is #56. I used to think I couldn't do it because of this bug in rustc, but it seems that it's not actually a bug.

from quickcheck.

russel avatar russel commented on June 23, 2024

@BurntSushi If you are having difficulties, I am unlikely to fair better. Doing some compile time code generation with macros looks like the only way to solve the closure thing for me. I posted on the forum, but it sounds as the answer is already known to be "not at the moment".

from quickcheck.

BurntSushi avatar BurntSushi commented on June 23, 2024

@russel Possibly, although fresh eyes definitely couldn't hurt!

from quickcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.