Closed
Description
Hey, thanks for this project! I'm using it quite a bit in zoxide to pass generated code through linters / formatters, and it's made my life a lot easier.
However, I do feel that errors could be formatted in a better way. I often have large amounts of text being compared in stdin
/ stdout
. For example, here is some code that passes fish
shell code through fishindent
to check for proper formatting:
Command::new("fish")
.env("HOME", tempdir)
.args(&["--command", "fish_indent", "--private"])
.write_stdin(source.to_string())
.assert()
.success()
.stdout(source)
.stderr("");
(expand me) This is what the output looks like.
running 1 test
test shell::tests::fish_fishindent::cmd_1::hook_1::echo_1::resolve_symlinks_1 ... FAILED
failures:
---- shell::tests::fish_fishindent::cmd_1::hook_1::echo_1::resolve_symlinks_1 stdout ----
-------------- TEST START --------------
thread 'shell::tests::fish_fishindent::cmd_1::hook_1::echo_1::resolve_symlinks_1' panicked at 'Unexpected stdout, failed var - original <= 0
├── original: # =============================================================================
#
# Utility functions for zoxide.
#
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd
builtin pwd -L
end
# A copy of fish's internal cd function. This makes it possible to use
# `alias cd=z` without causing an infinite loop.
if ! builtin functions -q __zoxide_cd_internal
if builtin functions -q cd
builtin functions -c cd __zoxide_cd_internal
else
alias __zoxide_cd_internal="builtin cd"
end
end
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd
__zoxide_cd_internal $argv
and builtin commandline -f repaint
end
# =============================================================================
#
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
if test "$__zoxide_hooked" != 1
set __zoxide_hooked 1
function __zoxide_hook
test -z "$fish_private_mode"
and command zoxide add -- (__zoxide_pwd)
end
end
# =============================================================================
#
# When using zoxide with --no-aliases, alias these internal functions as
# desired.
#
# Jump to a directory using only keywords.
function __zoxide_z
set argc (count $argv)
if test $argc -eq 0
__zoxide_cd $HOME
else if test "$argv" = -
__zoxide_cd -
else if begin
test $argc -eq 1; and test -d $argv[1]
end
__zoxide_cd $argv[1]
else
set -l __zoxide_result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
and __zoxide_cd $__zoxide_result
end
end
# Jump to a directory using interactive search.
function __zoxide_zi
set -l __zoxide_result (command zoxide query -i -- $argv)
and __zoxide_cd $__zoxide_result
end
# =============================================================================
#
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
# -- not configured --
# =============================================================================
#
# To initialize zoxide, add this to your configuration (usually
# ~/.config/fish/config.fish):
#
# zoxide init fish | source
├── actual distance: 1
├── diff: # =============================================================================
#
# Utility functions for zoxide.
#
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd
builtin pwd -L
end
# A copy of fish's internal cd function. This makes it possible to use
# `alias cd=z` without causing an infinite loop.
if ! builtin functions -q __zoxide_cd_internal
if builtin functions -q cd
builtin functions -c cd __zoxide_cd_internal
else
alias __zoxide_cd_internal="builtin cd"
end
end
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd
__zoxide_cd_internal $argv
and builtin commandline -f repaint
end
# =============================================================================
#
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
if test "$__zoxide_hooked" != 1
set __zoxide_hooked 1
function __zoxide_hook
test -z "$fish_private_mode"
and command zoxide add -- (__zoxide_pwd)
end
end
# =============================================================================
#
# When using zoxide with --no-aliases, alias these internal functions as
# desired.
#
# Jump to a directory using only keywords.
function __zoxide_z
set argc (count $argv)
if test $argc -eq 0
__zoxide_cd $HOME
else if test "$argv" = -
__zoxide_cd -
else if begin
test $argc -eq 1; and test -d $argv[1]
end
__zoxide_cd $argv[1]
else
set -l __zoxide_result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
and __zoxide_cd $__zoxide_result
end
end
# Jump to a directory using interactive search.
function __zoxide_zi
set -l __zoxide_result (command zoxide query -i -- $argv)
and __zoxide_cd $__zoxide_result
end
# =============================================================================
#
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
# -- not configured --
# =============================================================================
#
# To initialize zoxide, add this to your configuration (usually
# ~/.config/fish/config.fish):
#
# zoxide init fish | source
└── var as str: # =============================================================================
#
# Utility functions for zoxide.
#
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
function __zoxide_pwd
builtin pwd -L
end
# A copy of fish's internal cd function. This makes it possible to use
# `alias cd=z` without causing an infinite loop.
if ! builtin functions -q __zoxide_cd_internal
if builtin functions -q cd
builtin functions -c cd __zoxide_cd_internal
else
alias __zoxide_cd_internal="builtin cd"
end
end
# cd + custom logic based on the value of _ZO_ECHO.
function __zoxide_cd
__zoxide_cd_internal $argv
and builtin commandline -f repaint
end
# =============================================================================
#
# Hook configuration for zoxide.
#
# Initialize hook to add new entries to the database.
if test "$__zoxide_hooked" != 1
set __zoxide_hooked 1
function __zoxide_hook
test -z "$fish_private_mode"
and command zoxide add -- (__zoxide_pwd)
end
end
# =============================================================================
#
# When using zoxide with --no-aliases, alias these internal functions as
# desired.
#
# Jump to a directory using only keywords.
function __zoxide_z
set argc (count $argv)
if test $argc -eq 0
__zoxide_cd $HOME
else if test "$argv" = -
__zoxide_cd -
else if begin
test $argc -eq 1; and test -d $argv[1]
end
__zoxide_cd $argv[1]
else
set -l __zoxide_result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
and __zoxide_cd $__zoxide_result
end
end
# Jump to a directory using interactive search.
function __zoxide_zi
set -l __zoxide_result (command zoxide query -i -- $argv)
and __zoxide_cd $__zoxide_result
end
# =============================================================================
#
# Convenient aliases for zoxide. Disable these using --no-aliases.
#
# -- not configured --
# =============================================================================
#
# To initialize zoxide, add this to your configuration (usually
# ~/.config/fish/config.fish):
#
# zoxide init fish | source
command=`"fish" "--command" "fish_indent" "--private"`
stdin=`"# =============================================================================\n#\n# Utility functions for zoxide.\n#\n\n# pwd based on the value of _ZO_RESOLVE_SYMLINKS.\nfunction __zoxide_pwd\n builtin pwd -L\nend\n\n# A copy of fish\'s internal cd function. This makes it possible to use\n# `alias cd=z` without causing an infinite loop.\nif ! builtin functions -q __zoxide_cd_internal\n if builtin functions -q cd\n builtin functions -c cd __zoxide_cd_internal\n else\n alias __zoxide_cd_internal=\"builtin cd\"\n end\nend\n\n# cd + custom logic based on the value of _ZO_ECHO.\nfunction __zoxide_cd\n __zoxide_cd_internal $argv\n and builtin commandline -f repaint\nend\n\n# =============================================================================\n#\n# Hook configuration for zoxide.\n#\n\n# Initialize hook to add new entries to the database.\nif test \"$__zoxide_hooked\" != 1\n set __zoxide_hooked 1\n function __zoxide_hook\n test -z \"$fish_private_mode\"\n and command zoxide add -- (__zoxide_pwd)\n end\nend\n\n# =============================================================================\n#\n# When using zoxide with --no-aliases, alias these internal functions as\n# desired.\n#\n\n# Jump to a directory using only keywords.\nfunction __zoxide_z\n set argc (count $argv)\n if test $argc -eq 0\n __zoxide_cd $HOME\n else if test \"$argv\" = -\n __zoxide_cd -\n else if begin\n test $argc -eq 1; and test -d $argv[1]\n end\n __zoxide_cd $argv[1]\n else\n set -l __zoxide_result (command zoxide query --exclude (__zoxide_pwd) -- $argv)\n and __zoxide_cd $__zoxide_result\n end\nend\n\n# Jump to a directory using interactive search.\nfunction __zoxide_zi\n set -l __zoxide_result (command zoxide query -i -- $argv)\n and __zoxide_cd $__zoxide_result\nend\n\n# =============================================================================\n#\n# Convenient aliases for zoxide. Disable these using --no-aliases.\n#\n\n# -- not configured --\n\n# =============================================================================\n#\n# To initialize zoxide, add this to your configuration (usually\n# ~/.config/fish/config.fish):\n#\n# zoxide init fish | source"`
code=0
stdout=```"# =============================================================================\n#\n# Utility functions for zoxide.\n#\n\n# pwd based on the value of _ZO_RESOLVE_SYMLINKS.\nfunction __zoxide_pwd\n builtin pwd -L\nend\n\n# A copy of fish\'s internal cd function. This makes it possible to use\n# `alias cd=z` without causing an infinite loop.\nif ! builtin functions -q __zoxide_cd_internal\n if builtin functions -q cd\n builtin functions -c cd __zoxide_cd_internal\n else\n alias __zoxide_cd_internal=\"builtin cd\"\n end\nend\n\n# cd + custom logic based on the value of _ZO_ECHO.\nfunction __zoxide_cd\n __zoxide_cd_internal $argv\n and builtin commandline -f repaint\nend\n\n# =============================================================================\n#\n# Hook configuration for zoxide.\n#\n\n# Initialize hook to add new entries to the database.\nif test \"$__zoxide_hooked\" != 1\n set __zoxide_hooked 1\n function __zoxide_hook\n test -z \"$fish_private_mode\"\n and command zoxide add -- (__zoxide_pwd)\n end\nend\n\n# =============================================================================\n#\n# When using zoxide with --no-aliases, alias these internal functions as\n# desired.\n#\n\n# Jump to a directory using only keywords.\nfunction __zoxide_z\n set argc (count $argv)\n if test $argc -eq 0\n __zoxide_cd $HOME\n else if test \"$argv\" = -\n __zoxide_cd -\n else if begin\n test $argc -eq 1; and test -d $argv[1]\n end\n __zoxide_cd $argv[1]\n else\n set -l __zoxide_result (command zoxide query --exclude (__zoxide_pwd) -- $argv)\n and __zoxide_cd $__zoxide_result\n end\nend\n\n# Jump to a directory using interactive search.\nfunction __zoxide_zi\n set -l __zoxide_result (command zoxide query -i -- $argv)\n and __zoxide_cd $__zoxide_result\nend\n\n# =============================================================================\n#\n# Convenient aliases for zoxide. Disable these using --no-aliases.\n#\n\n# -- not configured --\n\n# =============================================================================\n#\n# To initialize zoxide, add this to your configuration (usually\n# ~/.config/fish/config.fish):\n#\n# zoxide init fish | source\n"```
stderr=```""```
', /home/ajeetdsouza/.cargo/registry/src/github.colasdn.workers.dev-1ecc6299db9ec823/assert_cmd-1.0.3/src/assert.rs:341:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
shell::tests::fish_fishindent::cmd_1::hook_1::echo_1::resolve_symlinks_1
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 448 filtered out; finished in 0.05s
error: test failed, to rerun pass '--bin zoxide'
On closer inspection, I found the problem - there was a missing newline at the end of my generated code. There are a couple of things that we can do to make this better, though.
- When
stdout
/stderr
/stdin
exceed, say, 256 characters, print them on a new line and indent them. For example:
stdin:
some input
is here
this is multiline
stdout:
some output
foo bar
this is also multiline
stderr: (empty)
- Use ANSI codes to colorize and make the
stdin:
/stdout:
/stderr:
fields bold and colorized, so that they can be easily spotted in a wall of text. - (This might be more involved) Print a multi-line colorized diff for
stdout
andstderr
, rather than just the raw text.
Metadata
Metadata
Assignees
Labels
No labels