Skip to content

Commit

Permalink
streamline dry run test
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Sep 21, 2024
1 parent 9c2df4a commit 5fcc34f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
21 changes: 14 additions & 7 deletions prog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,32 @@ func TestFS(t *testing.T) {
func TestDry(t *testing.T) {
const q = `snapshot("\(.).json"; [.])`
p := Program{}
files := func() string {
ls := func() string {
rt := must(fs.Glob(p.FS, "*"))
return strings.Join(rt, " ")
}
cat := func(filename string) string {
data, err := fs.ReadFile(p.FS, filename)
if err != nil {
return "error"
}
return string(data)
}

for range 3 {
p.Args = []string{"--dry-run", q}
testRun(t, `false`, `false false.json`, &p)
assertEqual(t, files(), "")
assertEqual(t, fileText(p.FS, "false.json"), "error")
assertEqual(t, ls(), "")
assertEqual(t, cat("false.json"), "error")

p.Args = []string{q}
testRun(t, `false`, `false`, &p)
assertEqual(t, files(), "false.json")
assertEqual(t, fileText(p.FS, "false.json"), "[false]")
assertEqual(t, ls(), "false.json")
assertEqual(t, cat("false.json"), "[false]")

p.Args = []string{"-t", q}
testRun(t, `false`, `false`, &p)
assertEqual(t, files(), "false.json")
assertEqual(t, fileText(p.FS, "false.json"), "[\n\tfalse\n]")
assertEqual(t, ls(), "false.json")
assertEqual(t, cat("false.json"), "[\n\tfalse\n]")
}
}
9 changes: 0 additions & 9 deletions util_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jqx

import (
"io/fs"
"testing"
)

Expand All @@ -12,11 +11,3 @@ func assertEqual[T comparable](t *testing.T, got T, want T) {
t.Error("want", want)
}
}

func fileText(fsys fs.FS, filename string) string {
data, err := fs.ReadFile(fsys, filename)
if err != nil {
return "error"
}
return string(data)
}

0 comments on commit 5fcc34f

Please sign in to comment.