commit | f1031c0cfa4e4827c7b642dcc9fa851e9881f4b1 | [log] [tgz] |
---|---|---|
author | Todd Wang <toddw@google.com> | Fri Dec 18 22:04:29 2015 -0800 |
committer | Todd Wang <toddw@google.com> | Fri Dec 18 22:04:29 2015 -0800 |
tree | 4d70f6f9b129352de0543ff0cc6d2abd47eb4ce8 | |
parent | 7656b4bb639fadfe680465529d915659fbd0f781 [diff] |
gosh: Make Cleanup pop to the top of the dir stack. Here's how I've written one of my tests: func TestFoo(t *testing.T) { sh := gosh.NewShell(gosh.Opts{Fatalf: t.Fatalf, Logf: t.Logf}) defer sh.Cleanup tmpDir := sh.MakeTempDir() sh.Pushd(tmpDir) defer sh.Popd() sh.Cmd("binary", "fails").Run() } The problem with this pattern is that if "binary" exits with a non-0 exit code, sh.Err will be non-nil after Run, but the deferred sh.Popd will then panic. It should be easy for me to fix; I can just remove the deferred sh.Popd. But the problem is that the cwd is tmpDir, which is deleted by Cleanup. Any subsequent test that calls sh.Pushd will fail, since os.Getwd will fail. My fix in this CL is pop to the top of the dir stack, so even if the user forgets to call Popd(), Cleanup will put us back in the directory where we started. This seems reasonable. Change-Id: I7592cc7baab270b041ceb5e5a75cdf46b0cbe940
This repository contains general purpose libraries used by the Vanadium project. TEST