Skip to content

add implementation of unlet $FOO#2855

Closed
mattn wants to merge 7 commits intovim:masterfrom
mattn:unsetenv
Closed

add implementation of unlet $FOO#2855
mattn wants to merge 7 commits intovim:masterfrom
mattn:unsetenv

Conversation

@mattn
Copy link
Member

@mattn mattn commented May 1, 2018

  • OS compatibility
  • Error handling on some OS which doesn't work unsetenv.
  • Add tests

closes #1116

@codecov-io
Copy link

codecov-io commented May 1, 2018

Codecov Report

Merging #2855 into master will increase coverage by 0.02%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/misc1.c 84.31% <0%> (-0.06%) ⬇️
src/eval.c 81.35% <12.5%> (-0.13%) ⬇️
src/ex_cmds.c 79.38% <0%> (-0.23%) ⬇️
src/ex_docmd.c 75.95% <0%> (-0.02%) ⬇️
src/if_py_both.h 76.59% <0%> (ø) ⬆️
src/screen.c 76.59% <0%> (+0.04%) ⬆️
src/os_unix.c 54.47% <0%> (+0.04%) ⬆️
src/gui.c 49.2% <0%> (+0.1%) ⬆️
src/term.c 59.78% <0%> (+0.1%) ⬆️
src/channel.c 83.1% <0%> (+0.11%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 402c839...f50a4d8. Read the comment docs.

#ifndef _WIN32
unsetenv((char *)var);
#elif defined(HAVE_UNSETENV)
mch_setenv((char *)var, "", 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking non-existence variable should not be an error since :echo $NOT_FOUND_ENV doesn't make an error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash doesn't make it an error.

$ unset FOOOOOOOOOOOOOO

Copy link

@ZyX-I ZyX-I May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the alphabetical order.

@brammool
Copy link
Contributor

brammool commented May 2, 2018 via email

@mattn mattn mentioned this pull request May 5, 2018
@mattn
Copy link
Member Author

mattn commented May 5, 2018

Fixed some pointed in this reviews.

@mattn mattn changed the title [WIP] add implementation of unlet $FOO add implementation of unlet $FOO May 5, 2018
@k-takata
Copy link
Member

k-takata commented May 7, 2018

Many unrelated changes are shown in the diff. Maybe it's better to rebase on top of the master branch.
Could you also update the document?

variables are automatically deleted when the function
ends.

:unl[et] ${env-name} *:let-environment* *:let-$*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/let/unlet/g

ends.

:unl[et] ${env-name} *:let-environment* *:let-$*
Rermove environment variable {env-name}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Rermove/Remove/

@mattn
Copy link
Member Author

mattn commented May 7, 2018

@k-takata Thank your pointing this. Probably I was sleepy.


:unl[et] ${env-name} *:let-environment* *:let-$*
Rermove environment variable {env-name}.
:unl[et] ${env-name}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, did you totally remove the tags?
I thought they should be: *:unlet-environment* *:unlet-$*.

@brammool brammool closed this in 137374f May 13, 2018
adizero pushed a commit to adizero/vim that referenced this pull request May 19, 2018
Problem:    Cannot use :unlet for an environment variable.
Solution:   Make it work.  Use unsetenv() if available. (Ken Takata,
            closes vim#2855)
janlazo added a commit to janlazo/neovim that referenced this pull request Oct 2, 2018
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
janlazo added a commit to janlazo/neovim that referenced this pull request Oct 3, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

:unlet $FOOBAR

5 participants