salilab / imp

The Integrative Modeling Platform
https://integrativemodeling.org
GNU General Public License v3.0
74 stars 30 forks source link

Add tests for compile-time failures (e.g. static_asserts) #1088

Closed benmwebb closed 9 months ago

benmwebb commented 10 months ago

Some operations can be checked for at compile time, e.g. with static_assert, rather than at runtime. For example, Vector3D(...) + Vector4D(...) will cause a compile time failure, while VectorKD(x,y,z) + VectorKD(a,b,c,d) will cause a runtime failure. Similarly, std::get<4>(ParticleIndexPair) will cause a compile time failure, while ParticleIndexPair[4] will cause a runtime failure. We cannot test specifically for compile time failures in Python since often we add additional checks in the SWIG wrappers, and we generally only see runtime failures there.

We want to test specifically for compile time failures so that we can safely remove redundant runtime checks. We could do this at the ctest level, e.g. https://stackoverflow.com/questions/30155619/expected-build-failure-tests-in-cmake. However, we want to make sure that the failure is specifically from static_assert, and not a missing header, wrong compiler command line options, etc. So most likely we need to run the C++ compiler in a subprocess and apply a regex to its output.