Skip to content

Commit

Permalink
improve scoping for defers
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Sep 25, 2024
1 parent db8576e commit 82ea788
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 4 additions & 2 deletions prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (p *Program) Main() (rtErr error) {
f.populate(p.Args)

files := map[string]any{}
for _, filename := range f.filenames {
slices.Values(f.filenames)(func(filename string) bool {
file, err := p.Open(filename)
failif(err, "loading")
defer file.Close()
Expand All @@ -112,7 +112,9 @@ func (p *Program) Main() (rtErr error) {
} else {
files[filename] = v
}
}

return true
})

input := decoder(p.Stdin, "stdin", f.rawIn)
if p.StdinIsTerminal {
Expand Down
6 changes: 2 additions & 4 deletions prog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ func TestFS(t *testing.T) {
testRun(t, "", "error", &p)
}

p.Args = []string{"-r", ".[][] | .+.", "d.txt"}
testRun(t, "", "foofoo", &p)
p.Args = []string{"-r", ".[][] | .+.", "e.txt"}
testRun(t, "", "qq ww ee rr tt yy", &p)
p.Args = []string{"-r", ".[][] | .+.", "d.txt", "e.txt"}
testRun(t, "", "foofoo qq ww ee rr tt yy", &p)
}
func TestDry(t *testing.T) {
const q = `snapshot("\(.).json"; [.])`
Expand Down

0 comments on commit 82ea788

Please sign in to comment.