binpash / try

Inspect a command's effects before modifying your live system
MIT License
5.21k stars 68 forks source link

stdstream support #168

Closed ezrizhu closed 2 months ago

ezrizhu commented 4 months ago

symlinks /dev/std{in,out,err} to /proc/self/fd/{0,1,2} and cleanup after tests included

ezrizhu commented 4 months ago

Nice! Could we add one more test that actually uses these streams, rather than just testing that the devices exist?

Here's a simple test script that reads a number x from stdin and outputs 2x on stdout and 3x on stderr:

read x
echo $((x * 2))
echo $((x * 3)) >&2

We should be able to run echo 5 | try $SCRIPT and get 10 on stdout and 15 on stderr. Similarly, we should be able to run echo 5 >FILE; try $SCRIPT <FILE (NB redir is in our shell, not in try's arg) and get the same result.

That example would also pass outside of this PR since it seems like sh does not need /dev/std{in,out,err} for those streams. @mgree

mgree commented 4 months ago

That example would also pass outside of this PR since it seems like sh does not need /dev/std{in,out,err} for those streams. @mgree

Oh! Good point lol. Then we should write a test that uses those devices appropriately.