From 6fae05eb6fe94352dfca430e58a69dc82df9eedf Mon Sep 17 00:00:00 2001 From: ruinivist Date: Wed, 25 Mar 2026 21:37:08 +0000 Subject: [PATCH] fix: change save path log to be relative --- README.md | 23 ++++++++++++++++++++++- cmd/record.go | 10 +++++++++- cmd/root_test.go | 8 ++++---- e2e/demo/in | 2 ++ e2e/demo/out | 4 ++++ e2e/record/save-flag/out | 2 +- e2e/rewrite/basic/out | 2 +- e2e/test/basic/out | 31 +++++++++++-------------------- e2e/test/pass/out | 2 +- e2e/test/scoped/out | 4 ++-- e2e/test/setup-nested/out | 4 ++-- 11 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 e2e/demo/in create mode 100644 e2e/demo/out diff --git a/README.md b/README.md index 0dc15e2..3239463 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -a lean cli e2e testing framework written in go +# Mire + +E2E tests for CLIs. + +# Quickstart + +## Install + +- clone +- `make build` +- add `build/mire` to path + +## Using + +- `mire init` to create the the single config file, every entry is explicit in config. +- `mire record test/name/` - now test how you would test manually, try out commands to see if they work as expected +- `mire test` or `mire test specific/test` +- `mire rewrite` - to rewrite all golden outputs in case of a style change + +**Using fixtures?** +You can write you script commands in `setup.sh` at any level, anything at that and nested level will have those run before dropping you +into record. diff --git a/cmd/record.go b/cmd/record.go index 9036714..1e3ff42 100644 --- a/cmd/record.go +++ b/cmd/record.go @@ -2,6 +2,7 @@ package cmd import ( "errors" + "os" "path/filepath" "mire/internal/mire" @@ -28,7 +29,14 @@ func newRecordCommand() *cobra.Command { return err } - output.Println(createdPath) + displayPath := createdPath + if cwd, err := os.Getwd(); err == nil { + if relPath, err := filepath.Rel(cwd, createdPath); err == nil { + displayPath = relPath + } + } + + output.Printf("Saved at %s\n", displayPath) return nil }, } diff --git a/cmd/root_test.go b/cmd/root_test.go index 53fc098..5e53ec7 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -114,8 +114,8 @@ func TestRunRecord(t *testing.T) { }) createdPath := filepath.Join(wantDir, "suite", "spec") - if !strings.Contains(stdout, createdPath) { - t.Fatalf("stdout = %q, want created path", stdout) + if !strings.Contains(stdout, prefixed("Saved at e2e/suite/spec\n")) { + t.Fatalf("stdout = %q, want saved message %q", stdout, prefixed("Saved at e2e/suite/spec\n")) } if !strings.Contains(stderr, "Save recording?") { t.Fatalf("stderr = %q, want save prompt", stderr) @@ -156,8 +156,8 @@ func TestRunRecordSaveFlagSkipsPrompt(t *testing.T) { }) createdPath := filepath.Join(wantDir, "suite", "spec") - if !strings.Contains(stdout, createdPath) { - t.Fatalf("stdout = %q, want created path", stdout) + if !strings.Contains(stdout, prefixed("Saved at e2e/suite/spec\n")) { + t.Fatalf("stdout = %q, want saved message %q", stdout, prefixed("Saved at e2e/suite/spec\n")) } if strings.Contains(stderr, "Save recording?") { t.Fatalf("stderr = %q, want save prompt omitted", stderr) diff --git a/e2e/demo/in b/e2e/demo/in new file mode 100644 index 0000000..de407f5 --- /dev/null +++ b/e2e/demo/in @@ -0,0 +1,2 @@ +echo a +exit diff --git a/e2e/demo/out b/e2e/demo/out new file mode 100644 index 0000000..30ef0e9 --- /dev/null +++ b/e2e/demo/out @@ -0,0 +1,4 @@ +[?2004h$ echo a +[?2004l a +[?2004h$ exit +[?2004l exit diff --git a/e2e/record/save-flag/out b/e2e/record/save-flag/out index c6ff0e1..ca976e1 100644 --- a/e2e/record/save-flag/out +++ b/e2e/record/save-flag/out @@ -7,7 +7,7 @@ [?2004h$ exit [?2004l exit mire › Verifying recording... -mire › /home/test/e2e/suite/spec +mire › Saved at e2e/suite/spec [?2004h$ test -f e2e/suite/spec/in && test -f e2e/suite/spec/out && echo fixtures [?2004l fixtures [?2004h$ exit diff --git a/e2e/rewrite/basic/out b/e2e/rewrite/basic/out index b71f15c..131e7c8 100644 --- a/e2e/rewrite/basic/out +++ b/e2e/rewrite/basic/out @@ -7,7 +7,7 @@ [?2004h$ exit [?2004l exit mire › Verifying recording... -mire › /home/test/e2e/a +mire › Saved at e2e/a [?2004h$ echo stale > e2e/a/out [?2004l [?2004h$ mire rewrite [?2004l mire › RUN a diff --git a/e2e/test/basic/out b/e2e/test/basic/out index 986ebb4..5b7be7f 100644 --- a/e2e/test/basic/out +++ b/e2e/test/basic/out @@ -1,35 +1,26 @@ [?2004h$ mire init -[?2004l -mire › Done initialising... +[?2004l mire › Done initialising... [?2004h$ mire record --save a -[?2004l -mire › Run commands in the recorder shell, then type exit to finish. +[?2004l mire › Run commands in the recorder shell, then type exit to finish. [?2004h$ echo one -[?2004l -one +[?2004l one [?2004h$ exit -[?2004l -exit +[?2004l exit mire › Verifying recording... -mire › /home/test/e2e/a +mire › Saved at e2e/a [?2004h$ mire record --save nested/b -[?2004l -mire › Run commands in the recorder shell, then type exit to finish. +[?2004l mire › Run commands in the recorder shell, then type exit to finish. [?2004h$ echo two -[?2004l -two +[?2004l two [?2004h$ exit -[?2004l -exit +[?2004l exit mire › Verifying recording... -mire › /home/test/e2e/nested/b +mire › Saved at e2e/nested/b [?2004h$ mire test -[?2004l -mire › RUN a +[?2004l mire › RUN a mire › PASS a (12 ms) mire › RUN nested/b mire › PASS nested/b (12 ms) mire › Summary: total=2 passed=2 failed=0 [?2004h$ exit -[?2004l -exit +[?2004l exit diff --git a/e2e/test/pass/out b/e2e/test/pass/out index 10eb6b5..aedaf4c 100644 --- a/e2e/test/pass/out +++ b/e2e/test/pass/out @@ -8,6 +8,6 @@ [?2004l exit mire › Save recording? [y/N] y mire › Verifying recording... -mire › /home/test/e2e/test +mire › Saved at e2e/test [?2004h$ exit [?2004l exit diff --git a/e2e/test/scoped/out b/e2e/test/scoped/out index d6978d7..f3e7446 100644 --- a/e2e/test/scoped/out +++ b/e2e/test/scoped/out @@ -7,7 +7,7 @@ [?2004h$ exit [?2004l exit mire › Verifying recording... -mire › /home/test/e2e/a +mire › Saved at e2e/a [?2004h$ mire record --save nested/b [?2004l mire › Run commands in the recorder shell, then type exit to finish. [?2004h$ echo two @@ -15,7 +15,7 @@ [?2004h$ exit [?2004l exit mire › Verifying recording... -mire › /home/test/e2e/nested/b +mire › Saved at e2e/nested/b [?2004h$ mire test nested [?2004l mire › RUN nested/b mire › PASS nested/b (12 ms) diff --git a/e2e/test/setup-nested/out b/e2e/test/setup-nested/out index 6572b60..5917936 100644 --- a/e2e/test/setup-nested/out +++ b/e2e/test/setup-nested/out @@ -9,10 +9,10 @@ [?2004h$ exit [?2004l exit mire › Verifying recording... -mire › /home/test/e2e/suite/spec +mire › Saved at e2e/suite/spec [?2004h$ mire test suite [?2004l mire › RUN suite/spec -mire › PASS suite/spec (12 ms) +mire › PASS suite/spec (13 ms) mire › Summary: total=1 passed=1 failed=0 [?2004h$ exit [?2004l exit