From 526e31d0b02a15902158b6275f3d03caf6bcbab4 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Wed, 25 Mar 2026 21:03:13 +0000 Subject: [PATCH] test: use mire to record some e2e tests for itself --- .gitignore | 2 - e2e/init/basic/in | 5 ++ e2e/init/basic/out | 8 ++++ e2e/record/decline-save/in | 8 ++++ e2e/record/decline-save/out | 13 +++++ e2e/record/save-flag/in | 7 +++ e2e/record/save-flag/out | 14 ++++++ e2e/rewrite/basic/in | 9 ++++ e2e/rewrite/basic/out | 19 ++++++++ e2e/shell.sh | 96 +++++++++++++++++++++++++++++++++++++ e2e/smoke/help/in | 2 + e2e/smoke/help/out | 20 ++++++++ e2e/test/basic/in | 10 ++++ e2e/test/basic/out | 35 ++++++++++++++ e2e/test/pass/in | 7 +++ e2e/test/pass/out | 13 +++++ e2e/test/scoped/in | 10 ++++ e2e/test/scoped/out | 24 ++++++++++ e2e/test/setup-nested/in | 9 ++++ e2e/test/setup-nested/out | 18 +++++++ mire.toml | 18 +++++++ 21 files changed, 345 insertions(+), 2 deletions(-) create mode 100644 e2e/init/basic/in create mode 100644 e2e/init/basic/out create mode 100644 e2e/record/decline-save/in create mode 100644 e2e/record/decline-save/out create mode 100644 e2e/record/save-flag/in create mode 100644 e2e/record/save-flag/out create mode 100644 e2e/rewrite/basic/in create mode 100644 e2e/rewrite/basic/out create mode 100755 e2e/shell.sh create mode 100644 e2e/smoke/help/in create mode 100644 e2e/smoke/help/out create mode 100644 e2e/test/basic/in create mode 100644 e2e/test/basic/out create mode 100644 e2e/test/pass/in create mode 100644 e2e/test/pass/out create mode 100644 e2e/test/scoped/in create mode 100644 e2e/test/scoped/out create mode 100644 e2e/test/setup-nested/in create mode 100644 e2e/test/setup-nested/out create mode 100644 mire.toml diff --git a/.gitignore b/.gitignore index bf6bcda..ad90590 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ /build/ -/e2e/ -/mire.toml /mire \ No newline at end of file diff --git a/e2e/init/basic/in b/e2e/init/basic/in new file mode 100644 index 0000000..f16f898 --- /dev/null +++ b/e2e/init/basic/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 diff --git a/e2e/init/basic/out b/e2e/init/basic/out new file mode 100644 index 0000000..7df7e82 --- /dev/null +++ b/e2e/init/basic/out @@ -0,0 +1,8 @@ +[?2004h$ mkdir -p /tmp/project +[?2004l [?2004h$ cd /tmp/project +[?2004l [?2004h$ mire init +[?2004l mire › Done initialising... +[?2004h$ test -f mire.toml && test -x e2e/shell.sh && echo ok +[?2004l ok +[?2004h$ exit +[?2004l exit diff --git a/e2e/record/decline-save/in b/e2e/record/decline-save/in new file mode 100644 index 0000000..1b92083 --- /dev/null +++ b/e2e/record/decline-save/in @@ -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 diff --git a/e2e/record/decline-save/out b/e2e/record/decline-save/out new file mode 100644 index 0000000..4f92586 --- /dev/null +++ b/e2e/record/decline-save/out @@ -0,0 +1,13 @@ +[?2004h$ mire init +[?2004l mire › Done initialising... +[?2004h$ mire record suite/spec +[?2004l mire › Run commands in the recorder shell, then type exit to finish. +[?2004h$ echo nope +[?2004l nope +[?2004h$ exit +[?2004l exit +mire › Save recording? [y/N] n +[?2004h$ test ! -e e2e/suite/spec/in && test ! -e e2e/suite/spec/out && echo discarded +[?2004l discarded +[?2004h$ exit +[?2004l exit diff --git a/e2e/record/save-flag/in b/e2e/record/save-flag/in new file mode 100644 index 0000000..6eb2bca --- /dev/null +++ b/e2e/record/save-flag/in @@ -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 diff --git a/e2e/record/save-flag/out b/e2e/record/save-flag/out new file mode 100644 index 0000000..c6ff0e1 --- /dev/null +++ b/e2e/record/save-flag/out @@ -0,0 +1,14 @@ +[?2004h$ mire init +[?2004l mire › Done initialising... +[?2004h$ mire record --save suite/spec +[?2004l mire › Run commands in the recorder shell, then type exit to finish. +[?2004h$ echo saved +[?2004l saved +[?2004h$ exit +[?2004l exit +mire › Verifying recording... +mire › /home/test/e2e/suite/spec +[?2004h$ test -f e2e/suite/spec/in && test -f e2e/suite/spec/out && echo fixtures +[?2004l fixtures +[?2004h$ exit +[?2004l exit diff --git a/e2e/rewrite/basic/in b/e2e/rewrite/basic/in new file mode 100644 index 0000000..8aad3d9 --- /dev/null +++ b/e2e/rewrite/basic/in @@ -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 diff --git a/e2e/rewrite/basic/out b/e2e/rewrite/basic/out new file mode 100644 index 0000000..b71f15c --- /dev/null +++ b/e2e/rewrite/basic/out @@ -0,0 +1,19 @@ +[?2004h$ mire init +[?2004l mire › Done initialising... +[?2004h$ mire record --save a +[?2004l mire › Run commands in the recorder shell, then type exit to finish. +[?2004h$ echo rewrite +[?2004l rewrite +[?2004h$ exit +[?2004l exit +mire › Verifying recording... +mire › /home/test/e2e/a +[?2004h$ echo stale > e2e/a/out +[?2004l [?2004h$ mire rewrite +[?2004l mire › RUN a +mire › PASS a (12 ms) +mire › Summary: total=1 passed=1 failed=0 +[?2004h$ grep rewrite e2e/a/out >/dev/null && echo saw-rewrite +[?2004l saw-rewrite +[?2004h$ exit +[?2004l exit diff --git a/e2e/shell.sh b/e2e/shell.sh new file mode 100755 index 0000000..9ba6ba6 --- /dev/null +++ b/e2e/shell.sh @@ -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 < e2e/suite/setup.sh +mire record --save suite/spec +echo $FROM_SETUP +exit +mire test suite +exit diff --git a/e2e/test/setup-nested/out b/e2e/test/setup-nested/out new file mode 100644 index 0000000..6572b60 --- /dev/null +++ b/e2e/test/setup-nested/out @@ -0,0 +1,18 @@ +[?2004h$ mire init +[?2004l mire › 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 mire › Run commands in the recorder shell, then type exit to finish. +[?2004h$ echo $FROM_SETUP +[?2004l from_setup +[?2004h$ exit +[?2004l exit +mire › Verifying recording... +mire › /home/test/e2e/suite/spec +[?2004h$ mire test suite +[?2004l mire › RUN suite/spec +mire › PASS suite/spec (12 ms) +mire › Summary: total=1 passed=1 failed=0 +[?2004h$ exit +[?2004l exit diff --git a/mire.toml b/mire.toml new file mode 100644 index 0000000..83a0fbf --- /dev/null +++ b/mire.toml @@ -0,0 +1,18 @@ +[mire] + # which folder to strore tests in + test_dir = "e2e" + # regexes for differing lines to ignore during replay comparison + ignore_diffs = [ + "^.*PASS.*\\([0-9]+ ms\\).*$", # timing diff ms + "^.*PASS.*\\([0-9]+\\.[0-9]{2} s\\).*$", # timing diff s + ] + +[sandbox] + # home is where mire would drop you by default on record + home = "/home/test" + # read only paths from host, entry looks like "path on host:path on sanbox" + # paths on host are absolute or relative to repo root + mounts = [] + # read only host paths to expose on PATH inside the sandbox as /tmp/mire/bin/ + # paths on host can be absolute or relative to repo root + paths = [ "./build/mire" ]