|
| 1 | +import sys |
| 2 | +import subprocess |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +DIR = Path(__file__).resolve().parent |
| 8 | + |
| 9 | +expected = """\ |
| 10 | +/* |
| 11 | + This file contains docstrings for use in the Python bindings. |
| 12 | + Do not edit! They were automatically extracted by pybind11_mkdoc. |
| 13 | + */ |
| 14 | +
|
| 15 | +#define MKD_EXPAND(x) x |
| 16 | +#define MKD_COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT |
| 17 | +#define MKD_VA_SIZE(...) MKD_EXPAND(MKD_COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)) |
| 18 | +#define MKD_CAT1(a, b) a ## b |
| 19 | +#define MKD_CAT2(a, b) MKD_CAT1(a, b) |
| 20 | +#define MKD_DOC1(n1) mkd_doc_##n1 |
| 21 | +#define MKD_DOC2(n1, n2) mkd_doc_##n1##_##n2 |
| 22 | +#define MKD_DOC3(n1, n2, n3) mkd_doc_##n1##_##n2##_##n3 |
| 23 | +#define MKD_DOC4(n1, n2, n3, n4) mkd_doc_##n1##_##n2##_##n3##_##n4 |
| 24 | +#define MKD_DOC5(n1, n2, n3, n4, n5) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5 |
| 25 | +#define MKD_DOC7(n1, n2, n3, n4, n5, n6, n7) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7 |
| 26 | +#define DOC(...) MKD_EXPAND(MKD_EXPAND(MKD_CAT2(MKD_DOC, MKD_VA_SIZE(__VA_ARGS__)))(__VA_ARGS__)) |
| 27 | +
|
| 28 | +#if defined(__GNUG__) |
| 29 | +#pragma GCC diagnostic push |
| 30 | +#pragma GCC diagnostic ignored "-Wunused-variable" |
| 31 | +#endif |
| 32 | +
|
| 33 | +
|
| 34 | +static const char *mkd_doc_RootLevelSymbol = |
| 35 | +R"doc(Root-level symbol. Magna fermentum iaculis eu non diam phasellus |
| 36 | +vestibulum.)doc"; |
| 37 | +
|
| 38 | +static const char *mkd_doc_drake_MidLevelSymbol = |
| 39 | +R"doc(1. Begin first ordered list element. Rutrum quisque non tellus orci ac |
| 40 | +auctor. End first ordered list element. 2. Begin second ordered list |
| 41 | +element. Ipsum faucibus vitae aliquet nec. Ligula ullamcorper |
| 42 | +malesuada proin libero. End second ordered list element. 3. Begin |
| 43 | +third ordered list element. Dictum sit amet justo donec enim. Pharetra |
| 44 | +convallis posuere morbi leo urna molestie. End third ordered list |
| 45 | +element. |
| 46 | +
|
| 47 | +Senectus et netus et malesuada fames ac. Tincidunt lobortis feugiat |
| 48 | +vivamus at augue eget arcu dictum varius.)doc"; |
| 49 | +
|
| 50 | +#if defined(__GNUG__) |
| 51 | +#pragma GCC diagnostic pop |
| 52 | +#endif |
| 53 | +
|
| 54 | +""" |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.parametrize( |
| 58 | + "name", |
| 59 | + ["sample_header.h", "sample header with spaces.h"], |
| 60 | + ids=["no_spaces", "spaces"], |
| 61 | +) |
| 62 | +def test_simple_header_cli(tmp_path: Path, name: str) -> None: |
| 63 | + # Run pybind11-mkdoc and put the output in a temp file |
| 64 | + tf = tmp_path / "tmp.h" |
| 65 | + header = DIR / "sample_header_docs" / name |
| 66 | + subprocess.run([sys.executable, "-m", "pybind11_mkdoc", "-o", tf, header], check=True) |
| 67 | + |
| 68 | + # Ensure the header file matches |
| 69 | + res = tf.read_text(encoding="utf-8") |
| 70 | + |
| 71 | + assert res == expected |
0 commit comments