Skip to content

Commit

Permalink
dorothy, dorothy-warnings: fix empty file being reported
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Oct 25, 2024
1 parent 154b1f2 commit 1530fbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,13 @@ function dorothy_() (
echo-style --h1='Dorothy Tests'
source "$DOROTHY/sources/ripgrep.bash"

# run relevant debugs
__print_lines '' 'debug-terminal-stdin:'
debug-terminal-stdin || :
__print_lines '' 'debug-terminal-tty:'
debug-terminal-tty || :
__print_lines ''

# able to test on bash v3?
local bash has_macos_bash_v3='no'
bash="$(type -P bash)"
Expand All @@ -1916,7 +1923,7 @@ function dorothy_() (
local commands filepath filename failures=() scan_paths=(
"$DOROTHY/commands/"
"$DOROTHY/commands.beta/"
"$DOROTHY/commands.deprecated/"
# "$DOROTHY/commands.deprecated/" <-- don't run deprecated tests, as that will cause deprecated warnings, which cases dorothy-warnings test to fail
)
if test -d "$DOROTHY/user"; then
if test -d "$DOROTHY/user/commands"; then
Expand Down
13 changes: 8 additions & 5 deletions commands/dorothy-warnings
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,30 @@ function dorothy_warnings() (
# =====================================
# Act

local file="$DOROTHY/state/warnings.txt"

function dorothy_warnings_check {
[[ -s "$DOROTHY/state/warnings.txt" ]]
[[ -s $file ]]
return
}
function dorothy_warnings_clear {
: >"$DOROTHY/state/warnings.txt"
: >"$file"
}
function dorothy_warnings_list {
echo-style --stderr \
--notice1='Dorothy has encountered warnings:' --newline \
--="$(echo-file -- "$DOROTHY/state/warnings.txt")" --newline \
--="$(echo-file -- "$file")" --newline \
--notice1='For help with these warnings, see: ' --code-notice1='https://github.com/bevry/dorothy/issues/185' --newline \
--notice1='To clear these warnings, run: ' --code-notice1='dorothy-warnings clear'
}
function dorothy_warnings_warn {
if [[ -N "$DOROTHY/state/warnings.txt" ]]; then
# -s and -N as if we have cleared the file, that is a new modification, so we need to check if it is actually non-empty AND modified
if [[ -s $file && -N $file ]]; then
dorothy_warnings_list
fi
}
function dorothy_warnings_add {
echo-style "${option_args[@]}" >>"$DOROTHY/state/warnings.txt"
echo-style "${option_args[@]}" >>"$file"
}

case "$action" in
Expand Down

0 comments on commit 1530fbb

Please sign in to comment.