| 1 |
#!/usr/bin/env py.test |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
def test_example_showing_how_to_test_generated_code_with_gtest(gtest): |
| 5 |
"This is an example test explaining the py.test/gtest integration framework." |
| 6 |
|
| 7 |
# First we 'generate' some code |
| 8 |
cut = "x[0] = 0.0; x[1] = 2.0;" |
| 9 |
|
| 10 |
# We can make regular py.test checks as we go |
| 11 |
assert "x[0] = 0.0;" in cut |
| 12 |
|
| 13 |
# Then we wrap the generated code in C++ setup and gtest checks |
| 14 |
gtestcode = """ |
| 15 |
double x[2] = {{ 1.0, 2.0 }}; |
| 16 |
{cut} |
| 17 |
ASSERT_TRUE(x[0] == 0.0); |
| 18 |
""".format(cut=cut) |
| 19 |
|
| 20 |
# Finally we emit the C++ test, which will be run in a later pass |
| 21 |
gtest.add(gtestcode) |