英文:
How do I run the clang-format (libFormat) unit tests?
问题
I'm trying to fix some bugs in clang-format, which means changing code in libFormat.
There is a whole set of google-test unit tests in unittests/Format/FormatTest.cpp
.
However, I can't figure out how to build and run just the target that runs those tests.
Specifically, if I change a test in unittests/Format/FormatTest.cpp
so that it fails, I want the test that I can run to see it fail.
I can see the failure if I build and run all tests with ninja check-all
but that takes a very long time. I can't seem to figure out how to just run the lib-format unit tests so I don't have to wait all day for the others.
I've looked at the documentation, and I'm sure there is something to do with llvm-lit
, and I've tried reading the cmake stuff to figure it out, but I now feel like I just gave myself a frontal lobotomy.
Surely, this is a common thing, but I can't seem to find anything in the documentation, or with google that provides much help.
英文:
I'm trying to fix some bugs in clang-format, which means changing code in libFormat.
There is a whole set of google-test unit tests in unittests/Format/FormatTest.cpp
.
However, I can't figure out how to build and run just the target that runs those tests.
Specifically, if I change a test in unittests/Format/FormatTest.cpp
so that it fails, I want the test that I can run to see it fail.
I can see the failure if I build and run all tests with ninja check-all
but that takes a very long time. I can't seem to figure out how to just run the lib-format unit tests so I don't have to wait all day for the others.
I've looked at the documentation, and I'm sure there is something to do with llvm-lit
, and I've tried reading the cmake stuff to figure it out, but I now feel like I just gave myself a frontal lobotomy.
Surely, this is a common thing, but I can't seem to find anything in the documentation, or with google that provides much help.
答案1
得分: 2
So, FormatTest 实际上是使用 GTest 而不是通常的 llvm-lit 编写的。我确信有更好的方法,但我一直都只使用以下方法,这是我想出来的,我对 CMake 的了解也非常有限。
一旦我对 FormatTest 或 TokenAnnotatorTest 进行了更改,我运行
ninja -C build FormatTests
,这将在 build/tools/clang/unittests/Format/FormatTests
创建一个 GTest 测试二进制文件。运行此可执行文件将运行测试,但它只会使用一个 CPU 核心,因此速度会非常慢。
为了解决这个问题,我使用以下项目:https://github.com/google/gtest-parallel。这只是一个我放在某个地方的 Python 脚本,我这样运行它:python ~/src/gtest-parallel/gtest_parallel.py build/tools/clang/unittests/Format/FormatTests
。
我同意这应该更好地记录下来,特别是如果还有我不知道的更好的方法。
英文:
So, FormatTest is actually written using GTest instead of using the usual llvm-lit. I'm sure there's a better way, but I've gotten by just fine with the following method, which is something I came up with with also really limited CMake knowledge.
Once I've made a change to FormatTest or TokenAnnotatorTest, etc, I run
ninja -C build FormatTests
which creates a GTest test binary at build/tools/clang/unittests/Format/FormatTests
. Running this executable will run the tests, but it will only use one CPU core so it will be painfully slow.
To remedy this, I use the following project: https://github.com/google/gtest-parallel. It's just a python script I've stashed somewhere, and I run it like: python ~/src/gtest-parallel/gtest_parallel.py build/tools/clang/unittests/Format/FormatTests
.
I agree that this should definitely be documented better, especially if there's a better way I also don't know of.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论