realworldocaml / mdx

Execute code blocks inside your documentation
ISC License
269 stars 45 forks source link

Regression with indented special characters in shell blocks #428

Open thpani opened 1 year ago

thpani commented 1 year ago

The treatment of special characters in shell blocks ($, >) changed in #397, s.t. these characters now have special meaning, even if indented.

Unfortunately, this results in a regression against v2.1.0. Consider the following program and test that contains an indented >:

test.md

```sh
$ ./test.sh
A
...
 > D
...
E
...
H
```

test.sh

#!/bin/bash

cat <<EOF
A
 > B
 > C
 > D
E
F
G
H
EOF

In mdx 2.1.0 ocaml-mdx test test.md used to succeed, but now results in a .corrected file, because the > D receives special meaning.

Leonidas-from-XIV commented 1 year ago

Hi @thpani. I tested it and what I get out is this:

```sh
$ ./test.sh
A
 > B
 > C
 > D
E
F
G
H
```

The differences being

@@ -1,10 +1,11 @@
 ```sh
 $ ./test.sh
 A
-...
+ > B
+ > C
  > D
-...
 E
-...
+F
+G
 H
```

So it basically decides that the input and the output don't match but generates essentially the same file (modulo the ellipsis, which the .corrected files can never have). This seems to be a bug in the comparison function between input and expected output.

thpani commented 1 year ago

Hi @Leonidas-from-XIV!

Yes, that's the output I get on mdx-2.3.0. My point is that in mdx-2.1.0, the ellipses consumed the entire output, i.e., the output was consistent with the expectation (no .corrected file is generated).