trycmd icon indicating copy to clipboard operation
trycmd copied to clipboard

Escape backticks in output in trycmd files

Open kraktus opened this issue 3 years ago • 8 comments
trafficstars

Wanted to add test to https://github.com/rust-lang/cargo-bisect-rustc before switching from StructOpt to Clapv3 but it is seems tests are failing because the output contains backticks (and backslashes, same as https://github.com/assert-rs/trycmd/issues/91)

A workaround for now would be to treat the output as a binary file which from what I've read in other issues is not normalised at all, but I have not found a way to force it

kraktus avatar Apr 30 '22 22:04 kraktus

Could you help me understand how backticks are causing tests to fail and why escaping them would help?

epage avatar May 01 '22 00:05 epage

Minimal reproducible example, using the test CLI of the repo

# My .trycmd file
```
$ stdout='```Hello```' bin-fixture
```Hello```
```

The backtips in the output are considered the end of the markdown block, and the end of the output is not parsed. It looks like trycmd does not support to use more than 3 backticks in that case as block delimiter to allow the use of 3 in it.

kraktus avatar May 01 '22 09:05 kraktus

Thanks, knowing you are using markdown and running into conflicts between code fences and output is a big help!

A workaround is to write your cases with toml files rather than markdown / trycmd

The minimum solution is for us to support variable number of backticks for fences. This will allow users to manually choose more backticks to avoid this situation. For faster compile times, we aren't using a full blown markdown parser but just enough to extract a subset of fenced blocks which is why we can't offer this workaround yet.

The ideal solution is we detect the conflict and automatically increase the number of backticks for fences on the users behalf.

epage avatar May 02 '22 09:05 epage

v0.13.4 is released with the workaround

epage avatar May 02 '22 10:05 epage

Thanks for the quick fix!

kraktus avatar May 03 '22 05:05 kraktus

The minimum solution is for us to support variable number of backticks for fences.

Could the minimum solution be to grab the first and last line that starts with triple backticks?

marcospb19 avatar Sep 15 '23 20:09 marcospb19

Could the minimum solution be to grab the first and last line that starts with triple backticks?

There can be multiple code fences within a file. This also wouldn't be compatible with markdown which we are striving for.

epage avatar Sep 25 '23 21:09 epage

Oops, I just realized that trycmd files can have multiple code fences for multistep assertions.

Yeah, nevermind.

marcospb19 avatar Sep 25 '23 22:09 marcospb19