Git Product home page Git Product logo

Comments (6)

luke-biel avatar luke-biel commented on June 24, 2024 1

An idea for #73 that came to my mind:

#[test_case(input1 => 1.0)]
#[test_case(input2 => with assert!($.is_nan()))]
fn tested(v: X) -> f64 {
	...
}

We could provide an option to manually map assertions in some cases.
Then, if there's too much repetition and we wanna cover whole test case with our custom assert

fn assert_nan(value: f64) {
	assert!(value.is_nan())
}

#[test_case(input1 => 1.0)]
#[test_case(input2 => use assert_nan)]
fn tested(v: X) -> f64 {
	...
}

which in turn allows:

fn assert_nan(value: f64) {
	assert!(value.is_nan())
}

#[test_case(input2)]
#[test_case_use(assert_nan)]
fn tested(v: X) -> f64 {
	...
}

Still no idea how to apprach global replacement though, but this goes with the spirit of test case in my opinion.
What do you think @frondeus ?

from test-case.

frondeus avatar frondeus commented on June 24, 2024

The question is - should this setting be active for one test_case or for all test_cases

from test-case.

Ryneqq avatar Ryneqq commented on June 24, 2024

How about

#[test_case("foo" => "bar")]
#[test_case_assert_macro(assert_diff)]

to

#[test_case[assert_diff]("foo" => "bar)]

from test-case.

StragaSevera avatar StragaSevera commented on June 24, 2024

Is there any progress on this issue? I would be very glad to be able to set the assertion macro globally or locally and have the clean => syntax.

from test-case.

luke-biel avatar luke-biel commented on June 24, 2024

Unfortunately not. Life called and neither me nor @frondeus have a lot of free time, so test-case lives in suspended state.

With this issue, idea is from some time back and wasn't ever fully fleshed out (we found no real world use case to base it on). If it is something you'd like and have some time to spare, introducing it yourself is an option (I can guarantee as much that I'm reviewing PR's actively).

As for design - I wouldn't oppose global #[test_case_assertion] marker that could be applied to a global method, which would then be used in every test_case, but local option, like #[test_case::<function_xyz>("foo" => "bar")] may be easier to introduce with how test-case is currently structured.

from test-case.

luke-biel avatar luke-biel commented on June 24, 2024

I've relaxed a bit requirements on using keyword, thus users can do

    fn wrapped_pretty_assert(expected: u64) -> impl Fn(u64) {
        move |actual: u64| { pretty_assertions::assert_eq!(actual, expected) }
    }

    #[test_case(1 => using wrapped_pretty_assert(1))]
    fn pretty_assertions_usage(input: u64) -> u64 {
        input
    }

I believe this covers all initial work needed to allow custom assertions.
I'm gonna fork this issue so that #[test_case_use(assert_nan)] and global assertions can be done separately.

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.