Git Product home page Git Product logo

Comments (2)

frondeus avatar frondeus commented on August 24, 2024

This is a major reason why there is still alpha version instead of regular v1.0.0 - the documentation lacks a lot :(

If you are using rust 2018 edition I'd recommend dropping whole extern crate test_case.
But no matter which edition you choose you still need to do one of two things:

Either wrap every test_case with #[cfg(test)] (highly recommended):

#[cfg(test)] // Skip this and next line if 2018 edition
extern crate test_case;

#[cfg(test)]
mod tests {
    use test_case::test_case;

    #[test_case( 2,  4 ; "when both operands are possitive")]
    #[test_case( 4,  2 ; "when operands are swapped")]
    #[test_case(-2, -4 ; "when both operands are negative")]
    fn multiplication_tests(x: i8, y: i8) {
        let actual = (x * y).abs();

        assert_eq!(8, actual)
    }
}

Second example has extern crate inside of tests module - only for 2015 ed.

#[cfg(test)]
mod tests {
    extern crate test_case;
    use self::test_case::test_case; // Remember about `self::`

    #[test_case( 2,  4 ; "when both operands are possitive")]
    #[test_case( 4,  2 ; "when operands are swapped")]
    #[test_case(-2, -4 ; "when both operands are negative")]
    fn multiplication_tests(x: i8, y: i8) {
        let actual = (x * y).abs();

        assert_eq!(8, actual)
    }
}

Or you move test_case from dev-dependencies to dependencies and skip whole #[cfg(test)] attribute.
But I do not recommend that - it makes your production build longer and executable bloated with test code. There is a good reason to use #[cfg(test)]:

extern crate test_case; // Again in 2018 ed you can skip this line.

use test_case::test_case;

#[test_case( 2,  4 ; "when both operands are possitive")]
#[test_case( 4,  2 ; "when operands are swapped")]
#[test_case(-2, -4 ; "when both operands are negative")]
fn multiplication_tests(x: i8, y: i8) {
    let actual = (x * y).abs();

    assert_eq!(8, actual)
}

Anyway - sorry for the confusion. I'll try to rewrite README. Meanwhile, if you have any questions or PRs - don't hesitate :)

from test-case.

drwilco avatar drwilco commented on August 24, 2024

No worries! I was mainly worried I was doing something wrong.

I'm finding this crate very useful!

from test-case.

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.