Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program outputs without a terminating newline cannot be represented in Markdown code blocks #11

Open
anko opened this issue Nov 24, 2022 · 0 comments
Labels

Comments

@anko
Copy link
Owner

anko commented Nov 24, 2022

Description

Tests like the following will always fail, because process.stdout.write does not write a terminating newline, while the out block is parsed as though it had an implicit terminating newline:

<!-- !test program node -->
<!-- !test in name -->

    process.stdout.write('no newline after this')

<!-- !test out name -->

    no newline after this

There is no mention in the Markdown or CommonMark standards on how to represent a code block without a terminating newline, so even if some syntax hack works, it's off-spec behaviour and can't be relied on. The CommonMark spec is feature-frozen, and even if it weren't, previous spec discussions found newlineless code blocks unimportant, because the rendered HTML is the same either way.

Unfortunately, the difference is semantically meaningful for some tests one might want to write in txm.

Potential fix

At the moment, only Markdown code blocks (indented or fenced) are recognised as potential test inputs or outputs. If we add a dependency on an HTML parser (huge, in terms of code size), we could use embedded HTML in the form of <pre><code>no newline after this</code></pre> as an alternative for such cases.

This just seems like a heavy-handed solution, given that the problem is rare, and almost always easy to work around, by having the test print (no newline)\n, to demonstrate the lack of a newline prior to the parens.

I'll have to think about whether it's worth it, or whether to just document the deficiency and workaround; I'm leaving this issue as a reminder and reference.

@anko anko added the bug label Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant