- Extract ParseVersion helper function for testing
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | ||
---|---|---|
632 | Does your use of references here pass the sanitizer lint check? IIRC this is disallowed by the linter. | |
compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp | ||
17 | I don't think this is a good idea. Sanitizer functions aren't usually tested this way. IIRC the unit tests get linked against the sanitizer library object files so you should be able to call the function you need from the linked object file. Can't you just remove the static on __sanitizer::ParseVersion(...) and call it directly? You might need to add a proto-type to lib/sanitizer_common/sanitizer_mac.h or in sanitizer_mac_test.cpp. |
Make helper non-static and forward declare it in test instead of including implementation file.
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | ||
---|---|---|
632 | ninja SanitizerLintCheck comes back good for. Is there a pattern that it rejects so I can counter-check if it's running properly? Just out of curiosity: the linter is executed when compiling sanitizer tests (e.g., check-sanitizer, check-asan), right?! I usually don't run it explicitly. | |
compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp | ||
17 | The reason this was that I tried to avoid making this helper (implementation detail) non-static just for the purpose of testing. I will remove static and forward declare in the test file. |
compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp | ||
---|---|---|
23 | Test's aren't normally declared inside the __sanitizer namespace. Maybe do something like this? // Prototypes namespace __sanitizer { void ParseVersion(const char *vers, u16 &major, u16 &minor); } using namespace __sanitizer; TEST(SanitizerMac, GetMacosAlignedVersion) { ... } | |
45 | Nit: I think it's okay to use C++ in the unit tests so you could use std::ostringstream to avoid using snprintf for simpler code. |
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | ||
---|---|---|
632 | IIRC I hit this from the old google C++ style guide once Parameters are either input to the function, output from the function, or both. Input parameters are usually values or const references, while output and input/output parameters will be pointers to non-const. https://drake.mit.edu/styleguide/cppguide.html#Output_Parameters which I think the linter script tries to enforce (at least partially). If you're passing SanitizerLintCheck then you're probably fine. If you want to check if it's working IIRC the linter doesn't like FIXME: something and instead wants something like FIXME(yln): something. |
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp | ||
---|---|---|
632 | Hmm, I can't get it to trigger at all. Investigating... | |
compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp | ||
23 | The other tests in this directory (e.g., sanitizer_linux_test.cpp, sanitizer_symbolizer_test.cpp, etc.) follow the same pattern, so I would prefer to leave this as is. | |
45 | Dreaming of std::format() ;) |
LGTM but please to make sure the linter is working correctly on your system before you land this.
compiler-rt/lib/sanitizer_common/tests/sanitizer_mac_test.cpp | ||
---|---|---|
23 | Yeah some do, some don't. E.g. sanitizer_bvgraph_test.cpp and sanitizer_bitvector_test.cpp follow the pattern I suggest and others follow what you've done in this patch. Yay for inconsistency :( I'll let you decide which you want to follow. |
clang-format not found in user's PATH; not linting file.