frondeus / test-case

Rust procedural macro attribute for adding test cases easily
MIT License
610 stars 38 forks source link

Uppercase and lowercase generated test function collide #108

Open ssipos90 opened 1 year ago

ssipos90 commented 1 year ago

Hello,

If you write tests like this, the generated function names will collide (_a_expects):

    #[test_case('a')]
    #[test_case('A')]
    fn test (_: char) {
    }

I worked around it by adding an extra argument in front:

    #[test_case(1, 'a')]
    #[test_case(2, 'A')]
    fn test (_: u32, _: char) {
    }

Maybe it would be easy to suffix the index of the test case to the generated name (_a_expects_{}).

Thanks.

luke-biel commented 1 year ago

For now in such cases we provide way to comment test cases. Comments replace usual test name generation. There's more info on wiki https://github.com/frondeus/test-case/wiki/Test-Names. There was a proposal to allow setting test names manually, but there wasn't enough need for that at the moment and it died, as comments suffice in most cases. As for indexing, maybe it would be nice to append them, but I need to sleep on the idea.

AugustoFKL commented 7 months ago

The solution provided on #19 should resolve this problem, but I'm not sure about a scenario like:

    #[test_case('a')]
    #[test_case('a')]
    fn test (_: u32, _: char) {
    }

Should it be accepted? From a library perspective, I don't see a reason for us to block it, but it would make tracing a bit more difficult.

frondeus commented 7 months ago

Hmm in that particular case:

Two tests cases with the same name would be translated to two functions with the same name. And that would cause an error, right?

The question is - if the error message would be clear enough to the user of test case. If not then probably we should check the uniqueness in our side

On Wed, Jan 24, 2024, 04:36 Augusto Fotino @.***> wrote:

The solution provided on #19 https://github.com/frondeus/test-case/issues/19 should resolve this problem, but I'm not sure about a scenario like:

#[test_case('a')]
#[test_case('a')]
fn test (_: u32, _: char) {
}

Should it be accepted? From a library perspective, I don't see a reason for us to block it, but it would make tracing a bit more difficult.

— Reply to this email directly, view it on GitHub https://github.com/frondeus/test-case/issues/108#issuecomment-1907299113, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI4UANBUEQA66CWEPWUV4DYQB6TTAVCNFSM6AAAAAASSVKG42VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBXGI4TSMJRGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AugustoFKL commented 7 months ago

I see

I am studying a way to refine the proposal I did on #19, but if we are considering that tests with the same name shouild not be accepted, then it makes things easier.