Execute the test case teardown hooks in a LIFO (last in, first out) order.
ALso add a teardown hook to the LoadUnloadTestCase.test_dyld_library_path()
test case to have it restore the DYLD_LIBRARY_PATH environment variable.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@121802 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/load_unload/TestLoadUnload.py b/test/load_unload/TestLoadUnload.py
index 5b08e9f..98487d8 100644
--- a/test/load_unload/TestLoadUnload.py
+++ b/test/load_unload/TestLoadUnload.py
@@ -38,7 +38,7 @@
         new_dir = os.path.join(os.getcwd(), "dyld_path")
 
         # This is the function to remove the dyld_path directory after the test.
-        def remove_dyld_path():
+        def remove_dyld_dir():
             import shutil
             shutil.rmtree(new_dir)
 
@@ -51,7 +51,7 @@
         os.rename(old_dylib, new_dylib)
         if dsymName:
             os.rename(old_dSYM, new_dSYM)
-        self.addTearDownHook(remove_dyld_path)
+        self.addTearDownHook(remove_dyld_dir)
         #system(["ls", "-lR", "."])
 
         # With libd.dylib moved, a.out run should fail.
@@ -71,6 +71,7 @@
 
         # Try again with the DYLD_LIBRARY_PATH environment variable properly set.
         os.environ[dylibPath] = new_dir
+        self.addTearDownHook(lambda: os.environ.pop(dylibPath))
         self.runCmd("run")
         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
             patterns = ["frame #0.*d_function.*at d.c:%d" % self.line_d_function])