Cleanup and speed up test runner

Add a -end-of-line switch to echo command to make it possible
to use `echo -end-of-line -to-file <file>` to collect env-vars
This commit is contained in:
Maxime Coste 2023-03-14 07:39:32 +11:00
parent 1322abef64
commit 019fbc5439
2 changed files with 23 additions and 26 deletions

View File

@ -1449,6 +1449,7 @@ const CommandDesc echo_cmd = {
ParameterDesc{ ParameterDesc{
{ { "markup", { {}, "parse markup" } }, { { "markup", { {}, "parse markup" } },
{ "quoting", { {arg_completer(Array{"raw", "kakoune", "shell"})}, "quote each argument separately using the given style (raw|kakoune|shell)" } }, { "quoting", { {arg_completer(Array{"raw", "kakoune", "shell"})}, "quote each argument separately using the given style (raw|kakoune|shell)" } },
{ "end-of-line", { {}, "add trailing end-of-line" } },
{ "to-file", { {filename_arg_completer<false>}, "echo contents to given filename" } }, { "to-file", { {filename_arg_completer<false>}, "echo contents to given filename" } },
{ "to-shell-script", { ArgCompleter{}, "pipe contents to given shell script" } }, { "to-shell-script", { ArgCompleter{}, "pipe contents to given shell script" } },
{ "debug", { {}, "write to debug buffer instead of status line" } } }, { "debug", { {}, "write to debug buffer instead of status line" } } },
@ -1466,6 +1467,9 @@ const CommandDesc echo_cmd = {
else else
message = join(parser, ' ', false); message = join(parser, ' ', false);
if (parser.get_switch("end-of-line"))
message.push_back('\n');
if (auto filename = parser.get_switch("to-file")) if (auto filename = parser.get_switch("to-file"))
write_to_file(*filename, message); write_to_file(*filename, message);
else if (auto command = parser.get_switch("to-shell-script")) else if (auto command = parser.get_switch("to-shell-script"))

View File

@ -14,29 +14,26 @@ main() {
exec -save-regs / %{%s%\(\K[^)]+\)<ret>a<backspace><esc>i<backspace><backspace><c-u><esc><a-;>} exec -save-regs / %{%s%\(\K[^)]+\)<ret>a<backspace><esc>i<backspace><backspace><c-u><esc><a-;>}
} catch %{ exec gg } } catch %{ exec gg }
try %{ source rc } try %{ source rc }
hook global RuntimeError .+ %{ try %{ eval -draft %{ edit cmd; exec \%H"zy; delete-buffer } }
echo -debug -- error: %val{hook_param} try %{ exec -with-maps -with-hooks %reg{z} }
eval -buffer *debug* write -force debug
quit!
}
try %{ exec -with-maps -with-hooks "%sh{cat cmd}" }
exec -with-hooks <c-l> exec -with-hooks <c-l>
' '
root=$PWD root=$PWD
tmpdir="${TMPDIR:-/tmp}" tmpdir="${TMPDIR:-/tmp}"
work=$(mktemp -d $tmpdir/kak-tests.XXXXXXXX) work=$(mktemp -d $tmpdir/kak-tests.XXXXXXXX)
session="kak-tests"
if [ -n "$XDG_RUNTIME_DIR" ]; then
session_path="${XDG_RUNTIME_DIR}/kakoune/$session"
else
session_path="${TMPDIR:-/tmp}/kakoune/${USER}/$session"
fi
trap "rm -R $work" EXIT trap "rm -R $work" EXIT
number_tests=0 number_tests=0
number_failures=0 number_failures=0
for dir in $(find "${@:-.}" -type d | sort); do for dir in $(find "${@:-.}" -type d | sort); do
cd $root/$dir; cd $root/$dir;
mkdir -p $work/$dir
for file in in cmd rc enabled; do
[ -f $file ] && cp $file $work/$dir/
done
cd $work/$dir;
indent="$(echo "$dir/" | sed -e 's|[^/]*//*| |g')" indent="$(echo "$dir/" | sed -e 's|[^/]*//*| |g')"
name=${PWD##*/} name=${PWD##*/}
if [ ! -f cmd ]; then if [ ! -f cmd ]; then
@ -47,13 +44,15 @@ main() {
continue continue
fi fi
env_vars=$(cd "${root}/${dir}" && ls -1 kak_* 2>/dev/null) env_vars=$(ls -1 kak_* 2>/dev/null)
number_tests=$(($number_tests + 1))
mkdir -p $work/$dir
cp in cmd rc $work/$dir/ 2>/dev/null
cd $work/$dir;
mkfifo ui-in ui-out mkfifo ui-in ui-out
number_tests=$(($number_tests + 1))
touch in; cp in out touch in; cp in out
session="kak-tests" rm -f "$session_path"
rm -f "$(session_path $session)"
$DEBUGGER $root/../src/kak out -n -s "$session" -ui json -e "$kak_commands" >ui-out <ui-in & $DEBUGGER $root/../src/kak out -n -s "$session" -ui json -e "$kak_commands" >ui-out <ui-in &
kakpid=$! kakpid=$!
@ -128,14 +127,6 @@ main() {
# Utility ├───────────────────────────────────────────────────────────────────── # Utility ├─────────────────────────────────────────────────────────────────────
session_path() {
if [ -n "$XDG_RUNTIME_DIR" ]; then
printf %s "${XDG_RUNTIME_DIR}/kakoune/$1"
else
printf %s "${TMPDIR:-/tmp}/kakoune/${USER}/$1"
fi
}
show_diff() { show_diff() {
diff -u $1 $2 | while IFS='' read -r line; do diff -u $1 $2 | while IFS='' read -r line; do
first_character=$(printf '%s\n' "$line" | cut -b 1) first_character=$(printf '%s\n' "$line" | cut -b 1)
@ -152,12 +143,14 @@ show_diff() {
finished_commands() { finished_commands() {
printf %s 'eval -client client0 %{ printf %s 'eval -client client0 %{
eval -buffer *debug* write -force debug eval -buffer *debug* write -force debug
nop %sh{
' '
for env_var in $env_vars; do for env_var in $env_vars; do
printf 'printf %%s\\\\n "$%s" >%s\n' "$env_var" "$env_var" case $env_var in
kak_quoted_*) printf 'echo -to-file %s -end-of-line -quoting shell -- %s\n' "$env_var" "%val{${env_var##kak_quoted_}}" ;;
kak_*) printf 'echo -to-file %s -end-of-line -- %s\n' "$env_var" "%val{${env_var##kak_}}" ;;
esac
done done
printf %s ' } printf %s '
write -force out write -force out
quit! quit!
} }