Add check_path.py test to verify existing path elements are maintained
diff --git a/.circleci/config.yml b/.circleci/config.yml
index d5ff7d6..d227e31 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -73,6 +73,7 @@
       PYTHON_BIN: "C:\\Python27amd64"
       PYTHONUNBUFFERED: "1"
       EMSDK_NOTTY: "1"
+      EMSDK_VERBOSE: "1"
     steps:
       - checkout
       - run:
diff --git a/emsdk.py b/emsdk.py
index f344830..5bae987 100644
--- a/emsdk.py
+++ b/emsdk.py
@@ -2496,6 +2496,7 @@
 # Looks at the current PATH and adds and removes entries so that the PATH reflects
 # the set of given active tools.
 def adjusted_path(tools_to_activate, system=False, user=False):
+  debug_print('adjusted_path: system=%s user=%s msys=%s' % (system, user, MSYS))
   # These directories should be added to PATH
   path_add = get_required_path(tools_to_activate)
   # These already exist.
diff --git a/scripts/check_path.py b/scripts/check_path.py
new file mode 100755
index 0000000..88952fd
--- /dev/null
+++ b/scripts/check_path.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+# Given a previous path check that the current path
+# contains all the same elements in the same order
+# with no elements removed.
+
+import os
+import sys
+
+
+old_path = sys.argv[1].split(os.pathsep)
+new_path = os.environ['PATH'].split(os.pathsep)
+
+paths_added = [p for p in new_path if p not in old_path]
+paths_preserved = [p for p in new_path if p in old_path]
+
+print('verifying path elemnts have been preserved')
+print('old: %s' % old_path)
+print('new: %s' % new_path)
+
+for p in old_path:
+  if p not in paths_preserved:
+    print('path not reserved: ' + p)
+    sys.exit(1)
+
+# Check that ordering matches too.
+if old_path != paths_preserved:
+  print('preserved paths don\'t match original path:')
+  print('old:')
+  for p in old_path:
+    print(' - ' + p)
+  print('preserved:')
+  for p in paths_preserved:
+    print(' - ' + p)
+  sys.exit(1)
diff --git a/scripts/test.bat b/scripts/test.bat
index 9dd5332..c8ef91a 100755
--- a/scripts/test.bat
+++ b/scripts/test.bat
@@ -1,7 +1,20 @@
 :: equivilent of test.sh as windows bat file
 set PATH=%PATH%;%PYTHON_BIN%
-@CALL emsdk install latest
-@CALL emsdk activate latest
-@CALL emsdk_env.bat --build=Release
-@CALL python -c "import sys; print(sys.executable)"
-@CALL emcc.bat -v
+set OLD_PATH=%PATH%
+CALL emsdk install latest
+
+:: first test with --persistent
+CALL emsdk activate latest
+CALL emsdk_env.bat --persistent
+:: Check that no path elements were removed
+CALL python scripts/check_path.py "%OLD_PATH%"
+CALL python -c "import sys; print(sys.executable)"
+CALL emcc.bat -v
+
+:: then test without --persistent
+CALL emsdk activate latest
+CALL emsdk_env.bat
+:: Check that no path elements were removed
+CALL python scripts/check_path.py "%OLD_PATH%"
+CALL python -c "import sys; print(sys.executable)"
+CALL emcc.bat -v
diff --git a/scripts/test.sh b/scripts/test.sh
index 73c0d42..523eaa8 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -5,6 +5,7 @@
 set -x
 set -e
 
+OLD_PATH=$PATH
 ./emsdk install latest
 ./emsdk activate latest
 source ./emsdk_env.sh --build=Release
@@ -12,3 +13,5 @@
 # bundled version.
 which python3
 emcc -v
+# Check that no path elements were removed
+python3 scripts/check_path.py "$OLD_PATH"