aureliojargas / clitest

Command Line Tester
MIT License
143 stars 12 forks source link

If the output begins with a dollar, it is treated as a command to be evaled rather than string output #52

Open mattmc3 opened 1 year ago

mattmc3 commented 1 year ago

I have the following tests:

$ # Works
$ echo $HOME/.config/g*
/Users/me/.config/git
$
$ # Fails!
$ echo $HOME/.config/g* | sed "s|$HOME|\$HOME|"
$HOME/.config/git
$

The first one works, but the second one fails because the output begins with a '$'. I could change the prompt symbol, but that doesn't seem viable for other output.

% echo '%oops I did it again'
%oops I did it again
%

I'm wondering if there's a feature like adding leading backslash that would allow for this sort of test??

$ # Is there something I can do here to indicate my output should start with a '$' dollar sign?
$ echo $HOME/.config/g* | sed "s|$HOME|\$HOME|"
\$HOME/.config/git
$
aureliojargas commented 1 year ago

Your specific example worked for me, because by default the prompt is identified by $ (note the extra space).

This is the contents for the foo file:

$ echo $HOME/.config/f* | sed "s|$HOME|\$HOME|"
$HOME/.config/fish
$

And then the clitest run:

$ ./clitest foo
#1      echo $HOME/.config/f* | sed "s|$HOME|\$HOME|"
OK: 1 of 1 test passed

Adding an extra space to the output, makes it break:

$ echo $HOME/.config/f* | sed "s|$HOME|\$ HOME|"
$ HOME/.config/fish
$

But this is expected, since now the output line starts with a "prompt".

I guess there's only two options here:

On a side note, the idea of using sed to tweak some special command outputs is already there in clitest own tests:

https://github.com/aureliojargas/clitest/blob/5ff7bff958f3d61b57095263989de68891952898/test.md?plain=1#L52-L53

https://github.com/aureliojargas/clitest/blob/5ff7bff958f3d61b57095263989de68891952898/test.md?plain=1#L1384-L1387