diff --git a/tests/cli_test.py b/tests/cli_test.py new file mode 100644 index 0000000..6829cd5 --- /dev/null +++ b/tests/cli_test.py @@ -0,0 +1,71 @@ +import sys +import subprocess +from pathlib import Path + +import pytest + +DIR = Path(__file__).resolve().parent + +expected = """\ +/* + This file contains docstrings for use in the Python bindings. + Do not edit! They were automatically extracted by pybind11_mkdoc. + */ + +#define MKD_EXPAND(x) x +#define MKD_COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT +#define MKD_VA_SIZE(...) MKD_EXPAND(MKD_COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)) +#define MKD_CAT1(a, b) a ## b +#define MKD_CAT2(a, b) MKD_CAT1(a, b) +#define MKD_DOC1(n1) mkd_doc_##n1 +#define MKD_DOC2(n1, n2) mkd_doc_##n1##_##n2 +#define MKD_DOC3(n1, n2, n3) mkd_doc_##n1##_##n2##_##n3 +#define MKD_DOC4(n1, n2, n3, n4) mkd_doc_##n1##_##n2##_##n3##_##n4 +#define MKD_DOC5(n1, n2, n3, n4, n5) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5 +#define MKD_DOC7(n1, n2, n3, n4, n5, n6, n7) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7 +#define DOC(...) MKD_EXPAND(MKD_EXPAND(MKD_CAT2(MKD_DOC, MKD_VA_SIZE(__VA_ARGS__)))(__VA_ARGS__)) + +#if defined(__GNUG__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + + +static const char *mkd_doc_RootLevelSymbol = +R"doc(Root-level symbol. Magna fermentum iaculis eu non diam phasellus +vestibulum.)doc"; + +static const char *mkd_doc_drake_MidLevelSymbol = +R"doc(1. Begin first ordered list element. Rutrum quisque non tellus orci ac +auctor. End first ordered list element. 2. Begin second ordered list +element. Ipsum faucibus vitae aliquet nec. Ligula ullamcorper +malesuada proin libero. End second ordered list element. 3. Begin +third ordered list element. Dictum sit amet justo donec enim. Pharetra +convallis posuere morbi leo urna molestie. End third ordered list +element. + +Senectus et netus et malesuada fames ac. Tincidunt lobortis feugiat +vivamus at augue eget arcu dictum varius.)doc"; + +#if defined(__GNUG__) +#pragma GCC diagnostic pop +#endif + +""" + + +@pytest.mark.parametrize( + "name", + ["sample_header.h", "sample header with spaces.h"], + ids=["no_spaces", "spaces"], +) +def test_simple_header_cli(tmp_path: Path, name: str) -> None: + # Run pybind11-mkdoc and put the output in a temp file + tf = tmp_path / "tmp.h" + header = DIR / "sample_header_docs" / name + subprocess.run([sys.executable, "-m", "pybind11_mkdoc", "-o", tf, header], check=True) + + # Ensure the header file matches + res = tf.read_text(encoding="utf-8") + + assert res == expected diff --git a/tests/sample_header_docs/sample header with spaces.h b/tests/sample_header_docs/sample header with spaces.h new file mode 120000 index 0000000..48dbf9b --- /dev/null +++ b/tests/sample_header_docs/sample header with spaces.h @@ -0,0 +1 @@ +sample_header.h \ No newline at end of file