Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play nice with clang-format? #54

Open
DrChr opened this issue Oct 31, 2017 · 1 comment
Open

Play nice with clang-format? #54

DrChr opened this issue Oct 31, 2017 · 1 comment

Comments

@DrChr
Copy link

DrChr commented Oct 31, 2017

Hi,

I tried running clang-format on the test case example at the main page. Unfortunately the result wasn't so nice (see below). I tried a few different settings for clang-format, but I couldn't get it better. Any thoughts on how to improve this?

Note: I guess the problem is due to clang-format not understanding what the CASE macro really represent.

Note: I know I can wrap the test case section with // clang-format off, but then I'm back to manually formatting the white space...

Here's the result after clang-format:

const lest::test specification[] = {
    CASE("Empty string has length zero (succeed)"){
        EXPECT(0 == string().length());
EXPECT(0 == string("").length());
}
,

    CASE("Specific expected exception is reported missing (fail)") {
    EXPECT_THROWS_AS(true, std::runtime_error);
}
,
}
;

This is the original formatting:

const lest::test specification[] =
{
    CASE( "Empty string has length zero (succeed)" )
    {
        EXPECT( 0 == string(  ).length() );
        EXPECT( 0 == string("").length() );
    },

    CASE( "Text compares lexically (fail)" )
    {
        EXPECT( string("hello") > string("world") );
    },
};

Note: I can get the formatting to behave with clang-format by not using the macro CASE, as below. I can also of course replace (lest::env & lestenv) with a macro of my own like lest_TC_ARGS:

const lest::test specification[] = {
    {
        "A test case title, within extra braces",
        [](lest::env &lest_env) {
            EXPECT(0 == string().length());
            EXPECT(0 == string().length());
        },
    },
    "Another test case, now without extra braces and macro for test args",
    [] lest_TC_ARGS {
        EXPECT(0 == string().length());
        EXPECT(0 == string().length());
    },
    {
        "Again within extra braces, and using macro for test args",
        [] lest_TC_ARGS {
            EXPECT(0 == string().length());
            EXPECT(0 == string().length());
        },
    },
};
@martinmoene
Copy link
Owner

Interesting subject, which I haven't given any thought yet in relation to lest.

Your last example starts looking a bit like bandit ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants