Format C/C++ code in the tests#1006
Conversation
|
Autoformatting seems like a good idea to me. I don't have any particular preference between the LLVM style and the Google style. The GNU style looks pretty weird to me and is very different to the way our Rust code is styled, so I'd prefer not that. We should probably enforce the style, either via a CI check like we currently have for our Rust code, or plausibly via a test, which has the advantage that it's harder for a new contributor to miss. |
There are things that I prefer in Google style over LLVM and vice versa, so I have no strong opinion on these two. I don't like GNU style, but it's a huge OSS community, therefore I included it.
Which we probably should call |
|
I welcome the suggested change and I don't have any style preference ;) |
|
Looking deeper into it, I slightly prefer Google version, so went for it. Open questions:
|
Given the time difference, I'd be in favour of running it all in a single process - not just the rust test, but also a single invocation of Running a separate clang-format for each file takes 0.94 seconds on my laptop. time bash -c 'for i in *.c *.h *.cc; do clang-format --dry-run $i; done'Running all in one process takes only 0.11 seconds. time bash -c 'clang-format --dry-run *.c *.h *.cc'
I think just running it by default makes sense. If we didn't run it by default, but then did run it in CI, then sometimes people would send a PR and have it fail CI. Better if they know before they send their PR that there's stuff that needs fixing. Having a way to turn it off seems reasonable though. e.g. setting
I'd be fine with that. The other option would be to have the test print out a command that you can run that would fix the formatting. e.g. something like If you wanted to submit the formatting changes of the existing tests in this PR and do the formatting test in a separate PR, that would be fine by me. |
This is not fully representative of how this test works because you run all files serially. The test runs them with all CPU threads, so it's way faster, but obviously it will always be slower than a single invocation.
That was my initial idea but went ahead and repurposed the PR, unless you think it'd be beneficial for the review to split it up. |
That's true, however generally you'd be running the entire test suite, so even if we only use a single thread for checking formatting, it'll run in parallel with other tests. In any case, the speed of either approach probably uses sufficiently little CPU / time that it doesn't matter, so I'd say go with whatever approach is easiest.
That's fine. Whatever is easiest. |
There was a problem hiding this comment.
I just noticed that the test is in the top level of the tests directory. That means that it'll get compiled and linked separately, which does incur some extra cost. It would work as a unit test. The tricky part would be figuring out where to put it, since it doesn't belong in any existing module. One option would be to create a tests module. i.e. wild/src/tests as opposed to wild/tests where it is now. It'd also be fine to make it a submodule of integration_tests.
There was a problem hiding this comment.
I thought that was the expected solution.
One option would be to create a
testsmodule. i.e.wild/src/testsas opposed towild/testswhere it is now. It'd also be fine to make it a submodule ofintegration_tests.
wild/src/tests seems a bit out of place considering this formats only the files for integration tests. Went for a submodule of integration tests, but let me know (or feel free to do it yourself) if that doesn't suit you.
437a3a4 to
d9d9427
Compare
19061ef to
709df0e
Compare
1c84f03 to
0559e36
Compare
0559e36 to
4cb9890
Compare
Different commits show some of different styles (there are more styles), what do you think about this idea?