-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an assertCompileFails() unittest method to check that a given C++ code snippet fails to compile due to a static_assert, and use it to test compile time checks for std::get(IMP::Array) and VectorD. Closes #1088.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import IMP.test | ||
|
||
|
||
class Tests(IMP.test.TestCase): | ||
|
||
def test_vectord_mismatch(self): | ||
"""Test combination of VectorD of different dimensions""" | ||
# Should be a compile-time error to combine VectorD of different sizes | ||
self.assertCompileFails( | ||
includes=['IMP/algebra/VectorD.h'], | ||
body=""" | ||
IMP::algebra::Vector3D v1(1,2,3); | ||
IMP::algebra::Vector4D v3(7,8,9,10); | ||
v1 -= v3;""") | ||
|
||
|
||
if __name__ == '__main__': | ||
IMP.test.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import IMP.test | ||
|
||
|
||
class Tests(IMP.test.TestCase): | ||
|
||
def test_get_array(self): | ||
"""Test std::get<IMP::Array>""" | ||
# Should be a compile-time error to access an out of range element | ||
self.assertCompileFails( | ||
includes=['IMP/base_types.h'], | ||
body=""" | ||
IMP::ParticleIndexPair pp(IMP::ParticleIndex(1), IMP::ParticleIndex(3)); | ||
IMP::ParticleIndex p = std::get<2>(pp);""") | ||
|
||
|
||
if __name__ == '__main__': | ||
IMP.test.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters