[Tests] fix cleanup in nvm_supports_xz unit test
diff --git a/test/fast/Unit tests/nvm_supports_xz b/test/fast/Unit tests/nvm_supports_xz
index c7e5a36..5a9e4f7 100755
--- a/test/fast/Unit tests/nvm_supports_xz
+++ b/test/fast/Unit tests/nvm_supports_xz
@@ -1,13 +1,19 @@
 #!/bin/sh
 
-die () { echo $@ ; exit 1; }
+OLDPATH=$PATH
+TEST_PATH=../../xz-test
+
+cleanup() {
+  rm -rf $TEST_PATH/{xz,which,awk,rm,command}
+  export PATH=$OLDPATH
+}
+die () { echo $@ ; cleanup ; exit 1; }
 
 . ../../../nvm.sh
 
 OLDPATH=$PATH
-TEST_PATH=../../xz-test
 
-mkdir $TEST_PATH
+mkdir -p $TEST_PATH
 touch ../../xz-test/xz
 chmod +x ../../xz-test/xz
 
@@ -33,4 +39,4 @@
 $(nvm_supports_xz "v2.3.2") && \
   die "expected 'nvm_supports_xz v2.3.2' with a missing xz binary to exit with 1"
 
-export PATH=$OLDPATH
+cleanup