Skip to content

Commit

Permalink
Use testing.T.Chdir for the model test
Browse files Browse the repository at this point in the history
Wow… this was the only obvious thing I could find out of 1.24 in this
project (other than synctest). Originally I planned to use the new Loop
function for benchmarking, but my benchmarks are parallel so they
already use a similar API.

(os.Root _might_ be useful for serving assets from the filesystem, but
it doesn't seem unreasonable that you'd want to involve symlinks in
setting that up.)
  • Loading branch information
ahamlinman committed Feb 19, 2025
1 parent f64a500 commit b31644b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions internal/watch/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func TestModel(t *testing.T) {
}

t.Logf("compiling model under %v", tmpdir)
defer func() {
t.Chdir(tmpdir)
t.Cleanup(func() {
if t.Failed() {
t.Logf("keeping %v due to test failure", tmpdir)
return
Expand All @@ -58,11 +59,7 @@ func TestModel(t *testing.T) {
} else {
t.Logf("failed to clean up %v: %v", tmpdir, err)
}
}()

if err := os.Chdir(tmpdir); err != nil {
t.Fatalf("failed to change to compilation directory: %v", err)
}
})

spin := exec.Command("spin", "-a", "/dev/stdin")
spin.Stdin = strings.NewReader(modelFile)
Expand Down

0 comments on commit b31644b

Please sign in to comment.