patch 9.1.1051: tests: no support for env variables when running Vim in terminal

Problem:  tests: no support for env variables when running Vim in
          terminal
Solution: support the "env" argument in RunVimInTerminal(),
          close swapfiles properly in test_termcodes,
          use CheckFeature in test_termencoding

Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/term_util.vim b/src/testdir/term_util.vim
index 1a06db7..67b21cb 100644
--- a/src/testdir/term_util.vim
+++ b/src/testdir/term_util.vim
@@ -57,6 +57,7 @@
 " "wait_for_ruler" - if zero then don't wait for ruler to show
 " "no_clean" - if non-zero then remove "--clean" from the command
 " "cmd"  - run any other command, e.g. "xxd" (used in xxd test)
+" "env"  - additional environment variables, e.g. $TERM variable
 func RunVimInTerminal(arguments, options)
   " If Vim doesn't exit a swap file remains, causing other tests to fail.
   " Remove it here.
@@ -109,6 +110,10 @@
 
   " Accept other options whose name starts with 'term_'.
   call extend(options, filter(copy(a:options), 'v:key =~# "^term_"'))
+  " Accept the env dict
+  if !empty(get(a:options, 'env', {}))
+    let options.env = get(a:options, 'env')
+  endif
 
   let buf = term_start(cmd, options)