test: use mire to record some e2e tests for itself
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
mkdir -p /tmp/project
|
||||
cd /tmp/project
|
||||
mire init
|
||||
test -f mire.toml && test -x e2e/shell.sh && echo ok
|
||||
exit
|
||||
@@ -0,0 +1,8 @@
|
||||
[?2004h$ mkdir -p /tmp/project
|
||||
[?2004l
|
||||
[?2004h$ cd /tmp/project
|
||||
[?2004l
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ test -f mire.toml && test -x e2e/shell.sh && echo ok
|
||||
@@ -0,0 +1,8 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire record suite/spec
|
||||
echo nope
|
||||
exit
|
||||
n
|
||||
test ! -e e2e/suite/spec/in && test ! -e e2e/suite/spec/out && echo discarded
|
||||
exit
|
||||
@@ -0,0 +1,13 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire record suite/spec
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo nope
|
||||
[?2004l
|
||||
nope
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Save recording? [y/N] n
|
||||
@@ -0,0 +1,7 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire record --save suite/spec
|
||||
echo saved
|
||||
exit
|
||||
test -f e2e/suite/spec/in && test -f e2e/suite/spec/out && echo fixtures
|
||||
exit
|
||||
@@ -0,0 +1,14 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire record --save suite/spec
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo saved
|
||||
[?2004l
|
||||
saved
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/suite/spec
|
||||
@@ -0,0 +1,9 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire record --save a
|
||||
echo rewrite
|
||||
exit
|
||||
echo stale > e2e/a/out
|
||||
mire rewrite
|
||||
grep rewrite e2e/a/out >/dev/null && echo saw-rewrite
|
||||
exit
|
||||
@@ -0,0 +1,19 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire record --save a
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo rewrite
|
||||
[?2004l
|
||||
rewrite
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/a
|
||||
[?2004h$ echo stale > e2e/a/out
|
||||
[?2004l
|
||||
[?2004h$ mire rewrite
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;215;255;255mRUN[0m a
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
host_home=${MIRE_HOST_HOME:?}
|
||||
host_tmp=${MIRE_HOST_TMP:?}
|
||||
path_env=${MIRE_PATH_ENV:?}
|
||||
visible_home=${MIRE_HOME:?}
|
||||
bootstrap_rc="$host_home/.mire-shell-rc"
|
||||
visible_bootstrap_rc="$visible_home/.mire-shell-rc"
|
||||
setup_scripts_dir='/tmp/mire-setup-scripts'
|
||||
visible_bin_dir='/tmp/mire/bin'
|
||||
|
||||
cat >"$bootstrap_rc" <<'EOF'
|
||||
cd "${HOME:?}"
|
||||
|
||||
for path in /tmp/mire-setup-scripts/*.sh; do
|
||||
[ -e "$path" ] || continue
|
||||
cd "${HOME:?}"
|
||||
source "$path"
|
||||
cd "${HOME:?}"
|
||||
done
|
||||
|
||||
if [ "${MIRE_COMPARE_MARKER:-0}" = "1" ]; then
|
||||
__mire_prompt_ready_original=${PROMPT_COMMAND-}
|
||||
__mire_prompt_ready() {
|
||||
printf '__MIRE_PROMPT_READY__\n'
|
||||
if [ -n "${__mire_prompt_ready_original:-}" ]; then
|
||||
PROMPT_COMMAND=$__mire_prompt_ready_original
|
||||
eval "$PROMPT_COMMAND"
|
||||
else
|
||||
unset PROMPT_COMMAND
|
||||
fi
|
||||
}
|
||||
PROMPT_COMMAND=__mire_prompt_ready
|
||||
fi
|
||||
unset MIRE_COMPARE_MARKER
|
||||
EOF
|
||||
|
||||
# the first ro-bind allows for /usr/bin etc to be mounted and accessible
|
||||
set -- \
|
||||
--ro-bind / / \
|
||||
--tmpfs /home \
|
||||
--bind "$host_home" "$visible_home" \
|
||||
--bind "$host_tmp" '/tmp' \
|
||||
--dev /dev \
|
||||
--proc /proc \
|
||||
--unshare-pid \
|
||||
--die-with-parent \
|
||||
--setenv HISTFILE '/dev/null' \
|
||||
--setenv HOME "$visible_home" \
|
||||
--setenv LANG 'C' \
|
||||
--setenv LC_ALL 'C' \
|
||||
--setenv PAGER 'cat' \
|
||||
--setenv PATH "$visible_bin_dir:$path_env" \
|
||||
--setenv PS1 '$ ' \
|
||||
--setenv TERM 'xterm-256color' \
|
||||
--setenv TMPDIR '/tmp' \
|
||||
--setenv TZ 'UTC' \
|
||||
--chdir "$visible_home"
|
||||
|
||||
set -- "$@" --dir /tmp/mire --dir "$visible_bin_dir"
|
||||
|
||||
if [ -n "${MIRE_SETUP_SCRIPTS:-}" ]; then
|
||||
i=1
|
||||
while IFS= read -r host_path || [ -n "$host_path" ]; do
|
||||
[ -n "$host_path" ] || continue
|
||||
visible_path=$(printf '%s/%03d.sh' "$setup_scripts_dir" "$i")
|
||||
set -- "$@" --ro-bind "$host_path" "$visible_path"
|
||||
i=$((i + 1))
|
||||
done <<EOF
|
||||
${MIRE_SETUP_SCRIPTS-}
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ -n "${MIRE_MOUNTS:-}" ]; then
|
||||
while IFS= read -r mount || [ -n "$mount" ]; do
|
||||
[ -n "$mount" ] || continue
|
||||
host_path=${mount%%:*}
|
||||
sandbox_path=${mount#*:}
|
||||
set -- "$@" --ro-bind "$host_path" "$sandbox_path"
|
||||
done <<EOF
|
||||
${MIRE_MOUNTS-}
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [ -n "${MIRE_PATHS:-}" ]; then
|
||||
while IFS= read -r host_path || [ -n "$host_path" ]; do
|
||||
[ -n "$host_path" ] || continue
|
||||
visible_path=$visible_bin_dir/${host_path##*/}
|
||||
set -- "$@" --ro-bind "$host_path" "$visible_path"
|
||||
done <<EOF
|
||||
${MIRE_PATHS-}
|
||||
EOF
|
||||
fi
|
||||
|
||||
exec bwrap "$@" bash --noprofile --rcfile "$visible_bootstrap_rc" -i
|
||||
@@ -0,0 +1,2 @@
|
||||
mire
|
||||
exit
|
||||
@@ -0,0 +1,20 @@
|
||||
[?2004h$ mire
|
||||
[?2004l
|
||||
A lean CLI E2E testing framework.
|
||||
|
||||
Usage:
|
||||
mire [flags]
|
||||
mire [command]
|
||||
|
||||
Available Commands:
|
||||
help Help about any command
|
||||
init Initialise mire in the current project
|
||||
record Record a new CLI scenario
|
||||
rewrite Refresh recorded CLI output fixtures
|
||||
test Replay recorded CLI scenarios
|
||||
|
||||
Flags:
|
||||
-h, --help help for mire
|
||||
|
||||
Use "mire [command] --help" for more information about a command.
|
||||
[?2004h$ exit
|
||||
@@ -0,0 +1,10 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire record --save a
|
||||
echo one
|
||||
exit
|
||||
mire record --save nested/b
|
||||
echo two
|
||||
exit
|
||||
mire test
|
||||
exit
|
||||
@@ -0,0 +1,35 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire record --save a
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo one
|
||||
[?2004l
|
||||
one
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/a
|
||||
[?2004h$ mire record --save nested/b
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo two
|
||||
[?2004l
|
||||
two
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/nested/b
|
||||
[?2004h$ mire test
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;215;255;255mRUN[0m a
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;0;215;175mPASS[0m a (12 ms)
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;215;255;255mRUN[0m nested/b
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;0;215;175mPASS[0m nested/b (12 ms)
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m [38;2;0;215;175mSummary: total=2 passed=2 failed=0[0m
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
@@ -0,0 +1,7 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire recoird tsest
|
||||
echo a
|
||||
exit
|
||||
y
|
||||
exit
|
||||
@@ -0,0 +1,13 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire recoi rd ts est
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo a
|
||||
[?2004l
|
||||
a
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Save recording? [y/N] y
|
||||
@@ -0,0 +1,10 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mire record --save a
|
||||
echo one
|
||||
exit
|
||||
mire record --save nested/b
|
||||
echo two
|
||||
exit
|
||||
mire test nested
|
||||
exit
|
||||
@@ -0,0 +1,24 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mire record --save a
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo one
|
||||
[?2004l
|
||||
one
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/a
|
||||
[?2004h$ mire record --save nested/b
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo two
|
||||
[?2004l
|
||||
two
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
@@ -0,0 +1,9 @@
|
||||
__MIRE_RUN_WITH_BREAKS___
|
||||
mire init
|
||||
mkdir -p e2e/suite
|
||||
echo export FROM_SETUP=from_setup > e2e/suite/setup.sh
|
||||
mire record --save suite/spec
|
||||
echo $FROM_SETUP
|
||||
exit
|
||||
mire test suite
|
||||
exit
|
||||
@@ -0,0 +1,18 @@
|
||||
[?2004h$ mire init
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Done initialising...
|
||||
[?2004h$ mkdir -p e2e/suite
|
||||
[?2004l
|
||||
[?2004h$ echo export FROM_SETUP=from_setup > e2e/suite/setup.sh
|
||||
[?2004l
|
||||
[?2004h$ mire record --save suite/spec
|
||||
[?2004l
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Run commands in the recorder shell, then type exit to finish.
|
||||
[?2004h$ echo $FROM_SETUP
|
||||
[?2004l
|
||||
from_setup
|
||||
[?2004h$ exit
|
||||
[?2004l
|
||||
exit
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m Verifying recording...
|
||||
[1m[3m[38;2;112;224;0mmire[0m [1m[3m[38;2;29;211;176m›[0m /home/test/e2e/suite/spec
|
||||
Reference in New Issue
Block a user