[cfe-dev] clag-format: format Microsoft::VisualStudio::CppUnitTestFramework Attributes

Michael Bölling via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 24 04:58:27 PST 2017


Hello,

Is there a way to get clang-format to format
Microsoft::VisualStudio::CppUnitTestFramework
TEST_CLASS.., TEST_METHOD... Attributes "nicely"?

Currently clang-format (style llvm) "messes" up the following sections:

BEGIN_TEST_CLASS_ATTRIBUTE()
        TEST_CLASS_ATTRIBUTE
and
BEGIN_TEST_METHOD_ATTRIBUTE(tf_clang1)
        TEST_METHOD_ATTRIBUTE(L"ID", L"ID1")


What I want(and used for clang-format style=llvm)  is:

#include "stdafx.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

/**
 \class tc_clang
 Bla Bla Bla
 */
TEST_CLASS(tc_clang) {
    BEGIN_TEST_CLASS_ATTRIBUTE()
        TEST_CLASS_ATTRIBUTE(L"level", L"l1")
        TEST_CLASS_ATTRIBUTE(L"module", L"m1")
    END_TEST_CLASS_ATTRIBUTE()

public:

    /**
     \fn tf_clang1()
     Bla Bla Bla
     */

    BEGIN_TEST_METHOD_ATTRIBUTE(tf_clang1)
        TEST_METHOD_ATTRIBUTE(L"ID", L"ID1")
        TEST_METHOD_ATTRIBUTE(L"Name", L"Name1")
    END_TEST_METHOD_ATTRIBUTE()

    TEST_METHOD(tf_clang1) {

        int n = 1;
        n++;
    }

    /**
     \fn tf_clang2()
    bla bla bla
     */

    BEGIN_TEST_METHOD_ATTRIBUTE (tf_clang2)
        TEST_METHOD_ATTRIBUTE(L"ID", L"ID2")
        TEST_METHOD_ATTRIBUTE(L"Name", L"Name2")
    END_TEST_METHOD_ATTRIBUTE()
    TEST_METHOD(tf_clang2) {
        {
            int i = 1;
            i++;
        }
    }
};





What I get is

#include "stdafx.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

/**
 \class tc_clang
 Bla Bla Bla
 */
TEST_CLASS(tc_clang){
  BEGIN_TEST_CLASS_ATTRIBUTE() TEST_CLASS_ATTRIBUTE(L"level", L"l1")
      TEST_CLASS_ATTRIBUTE(L"module", L"m1") END_TEST_CLASS_ATTRIBUTE()

          public :

              /**
               \fn tf_clang1()
               Bla Bla Bla
               */

              BEGIN_TEST_METHOD_ATTRIBUTE(tf_clang1)
                  TEST_METHOD_ATTRIBUTE(L"ID", L"ID1")
                      TEST_METHOD_ATTRIBUTE(L"Name", L"Name1")
                          END_TEST_METHOD_ATTRIBUTE()

                              TEST_METHOD(tf_clang1){

                                  int n = 1;
n++;
}

/**
 \fn tf_clang2()
bla bla bla
 */

BEGIN_TEST_METHOD_ATTRIBUTE(tf_clang2)
TEST_METHOD_ATTRIBUTE(L"ID", L"ID2")
TEST_METHOD_ATTRIBUTE(L"Name", L"Name2")
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(tf_clang2) {
  {
    int i = 1;
    i++;
  }
}
}
;


Michael Boelling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171124/06daa3b1/attachment.html>


More information about the cfe-dev mailing list