Skip to content

Instantly share code, notes, and snippets.

@haxscramper
Created August 28, 2020 08:33
Show Gist options
  • Save haxscramper/cb636295f6c71200925275b405b7c64c to your computer and use it in GitHub Desktop.
Save haxscramper/cb636295f6c71200925275b405b7c64c to your computer and use it in GitHub Desktop.
Automatically rebuild nimble tests when file changes
#!/usr/bin/env fish
function find-match-in-parent-dir -a "find_match"
set -l path "$PWD"
while [ '/' != "$path" ]
find "$path" -maxdepth 1 -mindepth 1 -name "$find_match"
set path (readlink -f "$path/..")
end
end
set -l nimble_conf (find-match-in-parent-dir "*.nimble")
set -l original_dir $PWD
# echo $nimble_conf
# echo
# exit 1
if [ '' != "$nimble_conf" ]
echo "Found nimble file: $nimble_conf"
cd (dirname $nimble_conf)
else
echo "No nimble file found, exiting"
quit 1
end
set -l suits (rg '^suite ' | perl -pe 's/(.*?):suite "(.*?)":/\'$1\' \'$2::\'/')
if [ 'true' != "$IN_ESHELL" ]
echo "fzf"
set -g selected_suit (printf '%s\n' $suits | cat -n | fzf -i)
set -l nimble_name (basename $nimble_conf)
kitty @ set-window-title "nimble-rebuild $nimble_name"
else
echo "ivy"
set -g selected_suit (printf '%s\n' $suits | cat -n | emacsclient_ivy)
end
if [ '' != "$selected_suit" ]
# echo "Press `q` to cancel"
# echo "Select suit number"
set -l selected (echo "$selected_suit" | awk '{print $1}')
# echo "selected $selected"
if string match -qr '^[0-9]+$' $selected;
set -l suit $suits[$selected]
fd -e nim -e nims -e sh -e nimble -e cfg |
entr -rc sh -c "time nim c -r $suit && echo -l:1 'Done tests'"
# cd $original_dir # FUCK SHELL
else if string match 'q' $selected
echo -w:1 "Cancelled `nd`"
else
echo -e:1 "Expected integer but found $selected"
end
end
@haxscramper
Copy link
Author

What it does is basically runs separate test suit each time you made change in any file in the repository. When you start it uses fzf to automatically find all unit tests in the current nimble package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment