Skip to content

Play nice with clang-format? #54

Description

@DrChr

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());
        },
    },
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions