[PATCH] D42034: [clang-format] In tests, expected code should be format-stable

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 01:55:03 PDT 2019


MyDeveloperDay added inline comments.
Herald added a project: LLVM.


================
Comment at: cfe/trunk/unittests/Format/FormatTest.cpp:78
     EXPECT_EQ(Expected.str(), format(Code, Style));
     if (Style.Language == FormatStyle::LK_Cpp) {
       // Objective-C++ is a superset of C++, so everything checked for C++
----------------
@ mzeren-vmw just a minor comment related to a change you made last year.

When FormatTest  fails, all we are told is that it fails on line 75,or 77 (currently in trunk its 48,49) for every failure, with so many test cases written as "foo()" or "aaaaaa()" it can often be hard to pinpoint the exact test failure.

If verifyFormat was given an additional default argument of `int line`

Then verifyFormat could be used via a macro

```
#define VERIFYFORMAT(expected,code,style)
             verifyFormat(expected,code,style,__LINE__);
```

The line numbers could then be passed as an additional failure message to gtest by passing the __LINE__ of the test location down.

```
void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
                    const FormatStyle &Style = getLLVMStyle(),int line=__LINE__) {
    EXPECT_EQ(Expected.str(), format(Expected, Style))
        << "Expected code is not stable at " << line;
    EXPECT_EQ(Expected.str(), format(Code, Style) << " at " << line;
}
```

When the test fails we'd know the exact line of the test case that failed.

Also because of this, we get 2 failures for every failure, the second will almost always fail as well if the first case does (from what I can tell), is there anyway we can query the first failed result and not bother doing the second if the first one failed?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D42034/new/

https://reviews.llvm.org/D42034





More information about the cfe-commits mailing list