Conversation
Codecov Report
@@ Coverage Diff @@
## master #2855 +/- ##
==========================================
+ Coverage 75.53% 75.55% +0.02%
==========================================
Files 92 92
Lines 134866 134878 +12
==========================================
+ Hits 101867 101911 +44
+ Misses 32999 32967 -32
Continue to review full report at Codecov.
|
| #ifndef _WIN32 | ||
| unsetenv((char *)var); | ||
| #elif defined(HAVE_UNSETENV) | ||
| mch_setenv((char *)var, "", 0); |
There was a problem hiding this comment.
Are these conditions correct?
Shouldn't be as follows?
#ifdef HAVE_UNSETENV
unsetenv((char *)var);
#elif defined(_WIN32)
mch_setenv((char *)var, "", 0);| endfor | ||
| call assert_equal(0, found) | ||
|
|
||
| unlet $MUST_NOT_BE_AN_ERROR |
There was a problem hiding this comment.
You should probably also check for unexistence of this variable first. It is also not obvious from the variable name that you check for unletting unexistent variable. If writing tests for Neovim I would check that with eq(0, exc_exec('unlet $XXX_NONEXSTENT_VAR_XXX')): variable name states that it is unexistent and surrounding code states that it is checking for no exceptions.
Though why not just use unlet $FOOBAR again?
There was a problem hiding this comment.
I'm thinking non-existence variable should not be an error since :echo $NOT_FOUND_ENV doesn't make an error.
There was a problem hiding this comment.
bash doesn't make it an error.
$ unset FOOOOOOOOOOOOOO
There was a problem hiding this comment.
@mattn I am not saying it should be an error. I am saying that variable may exist and it is good to check this is not the case first, primary to make it obvious what exactly test is checking. And/or name variable so that it is obvious that it is not supposed to exist. Or use $FOOBAR as it was just deleted.
Though bash unset FOOOO is not relevant. unlet g:xxx_nonexistent_var_xxx will throw, unlet! … won’t and this is VimL and not bash.
There was a problem hiding this comment.
As long as non-existence variable doesn't make an error with reference, I'm thinking unlet should not make error. @brammool How do you think?
| " Test for unlet $FOOBAR. | ||
|
|
||
| func Test_UnletEnv() | ||
| let envcmd = has('win32') ? 'set' : 'env' |
There was a problem hiding this comment.
And before doing that you need to check that unlet $... does not throw and skip the test if it does. Throwing in some environment is expected behaviour.
| @@ -0,0 +1,25 @@ | |||
| " Test for unlet $FOOBAR. | |||
There was a problem hiding this comment.
New file needs to be listed in a number of places. Find some commits where Bram adds new test file, I do not know the details.
There was a problem hiding this comment.
src/Makefile and src/testdir/Make_all.mak, or src/testdir/test_alot.vim should be updated.
| #elif defined(HAVE_UNSETENV) | ||
| unsetenv((char *)var); | ||
| #else | ||
| EMSG(_("E319: Sorry, the command is not available in this version")); |
There was a problem hiding this comment.
Do not copy message text over, if needed place that in globals.h near other error messages and use in two places. Though I would be against this message: command is available, specific part of command’s functionality is missing and it deserves its own message.
src/Makefile
Outdated
| test_windows_home \ | ||
| test_wordcount \ | ||
| test_writefile \ | ||
| test_unlet_env \ |
There was a problem hiding this comment.
This should be in the alphabetical order.
|
mattn commented on this pull request.
> + if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(1, found)
+
+ unlet $FOOBAR
+ let found = 0
+ for kv in split(system(envcmd), "\r*\n")
+ if kv == 'FOOBAR=test'
+ let found = 1
+ endif
+ endfor
+ call assert_equal(0, found)
+
+ unlet $MUST_NOT_BE_AN_ERROR
As long as non-existence variable doesn't make an error with
reference, I'm thinking unlet should not make error. @brammool How do
you think?
AFAIK most programs don't complain when trying to remove an environment
variable that doesn't exist. The functionality will be mainly to make
sure the environment variable does not exist, thus ignoring errors seems
right. In the few cases it should actually be an error, one can first
check that the variable does exist.
On the other hand, you can always use ":unlet! $MUST_NOT_BE_AN_ERROR".
That's consistent with unletting variables. Having to explain the
exception isn't nice.
unlet MUST_NOT_BE_AN_ERROR " error
unlet $MUST_NOT_BE_AN_ERROR " no error
That's unexpected.
…--
I still remember when I gave up Smoking, Drinking and Sex. It was the
most *horrifying* hour of my life!
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
Fixed some pointed in this reviews. |
|
Many unrelated changes are shown in the diff. Maybe it's better to rebase on top of the master branch. |
runtime/doc/eval.txt
Outdated
| variables are automatically deleted when the function | ||
| ends. | ||
|
|
||
| :unl[et] ${env-name} *:let-environment* *:let-$* |
runtime/doc/eval.txt
Outdated
| ends. | ||
|
|
||
| :unl[et] ${env-name} *:let-environment* *:let-$* | ||
| Rermove environment variable {env-name}. |
|
@k-takata Thank your pointing this. Probably I was sleepy. |
runtime/doc/eval.txt
Outdated
|
|
||
| :unl[et] ${env-name} *:let-environment* *:let-$* | ||
| Rermove environment variable {env-name}. | ||
| :unl[et] ${env-name} |
There was a problem hiding this comment.
Oh, did you totally remove the tags?
I thought they should be: *:unlet-environment* *:unlet-$*.
Problem: Cannot use :unlet for an environment variable.
Solution: Make it work. Use unsetenv() if available. (Ken Takata,
closes vim#2855)
Problem: Cannot use :unlet for an environment variable.
Solution: Make it work. Use unsetenv() if available. (Ken Takata,
closes vim/vim#2855)
vim/vim@137374f
Problem: Cannot use :unlet for an environment variable.
Solution: Make it work. Use unsetenv() if available.
(Yasuhiro Matsumoto, closes vim/vim#2855)
vim/vim@137374f
closes #1116