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
2 files changed
tree: 4d70f6f9b129352de0543ff0cc6d2abd47eb4ce8
  1. cmd/
  2. cmdline/
  3. dbutil/
  4. envvar/
  5. gosh/
  6. host/
  7. ibe/
  8. metadata/
  9. netconfig/
  10. netstate/
  11. set/
  12. textutil/
  13. timing/
  14. toposort/
  15. vlog/
  16. .gitignore
  17. .godepcop
  18. AUTHORS
  19. CONTRIBUTING.md
  20. CONTRIBUTORS
  21. LICENSE
  22. PATENTS
  23. README.md
  24. VERSION
README.md

This repository contains general purpose libraries used by the Vanadium project. TEST