Re: Test failed: Test_cmdline_complete_user_names()

2018-07-07 Fir de Conversatie Bram Moolenaar


Dominique wrote:

> Nazri Ramliy  wrote:
> 
> > On Fri, Jul 6, 2018 at 8:59 PM, Dominique Pell=C3=A9
> >  wrote:
> > >> Can you try interactively if happens when
> > >> typing the Ex command   :e ~a
> > >> where  is a single key for CTRL-A
> > >>
> > >> On which OS do you see the issue?
> > >> Is it reproducible with other user names?
> > >
> > > I made an experiment on my machine:
> > > :e ~p
> > > gives::e ~pel proxy pulse  (good!)
> > >
> > > Then I created a new user "pel2" and did:
> > > : e ~p  gives  :e ~pel pel2 proxy pulse  (good)
> > > : e ~pe gives  :e ~pel pel2   (good)
> > > : e ~pel gives  :e /home/pel/   (does not look right!)
> > >
> > > I expected  to get  :e ~pel pel2  in the last case.
> > >
> > > In your case, I suspect that you have a user name called "a"
> > > which is triggering the bug.
> > >
> > > It looks like a bug in vim found by the test.
> >
> > Yup I do have a user called "a" on the machine. This is on linux
> > (ubuntu 16.04.4).
> >
> > The bug don't appear if I comment out the entry for the user "a" in /etc/=
> passwd.
> >
> > Also I see this weird behavior:
> >
> > $ sudo vi /etc/passwd
> > :e ~a  gives /home/a/ (buggy as expected)
> >
> > now without closing the file comment out the entry for the "a" user
> > and save the file and reattempt the completion
> >
> > :e ~a nothing suggested, ":e ~a" remains.  I expect it list the
> > usernames that starts with "a".
> >
> > Now undo the changes to the file and quit vim and open it again in vim
> > but this time immediately comment out the entry for "a":
> >
> > $ sudo vi /etc/passwd
> > comment out the entry for "a"
> >
> > :e ~a gives the expected result :e ~avahi avahi-autoipd ayie
> >
> > nazri
> 
> Hi Nazri
> 
> The attached patch "fix-user-name-compl-8.1.155.patch"
> should fix the bug.  Can you try it?

Thanks.  We can simplify it by using ">= 1".  I verified with "~sys",
since "sys" and "syslog" are user names.

> It's good to see that recently added tests discover bugs.

Definitely!

-- 
Some of the well known MS-Windows errors:
EMEMORY Memory error caused by..., eh...
ELICENSEYour license has expired, give us more money!
EMOUSE  Mouse moved, reinstall Windows
EILLEGALIllegal error, you are not allowed to see this
EVIRUS  Undetectable virus found

 /// Bram Moolenaar -- b...@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///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Nazri Ramliy
On Sat, Jul 7, 2018 at 4:26 AM, Dominique Pellé
 wrote:
> The attached patch "fix-user-name-compl-8.1.155.patch"
> should fix the bug.  Can you try it?

It works! Thank you!

nazri

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Dominique Pellé
Nazri Ramliy  wrote:

> On Fri, Jul 6, 2018 at 8:59 PM, Dominique Pellé
>  wrote:
> >> Can you try interactively if happens when
> >> typing the Ex command   :e ~a
> >> where  is a single key for CTRL-A
> >>
> >> On which OS do you see the issue?
> >> Is it reproducible with other user names?
> >
> > I made an experiment on my machine:
> > :e ~p
> > gives::e ~pel proxy pulse  (good!)
> >
> > Then I created a new user "pel2" and did:
> > : e ~p  gives  :e ~pel pel2 proxy pulse  (good)
> > : e ~pe gives  :e ~pel pel2   (good)
> > : e ~pel gives  :e /home/pel/   (does not look right!)
> >
> > I expected  to get  :e ~pel pel2  in the last case.
> >
> > In your case, I suspect that you have a user name called "a"
> > which is triggering the bug.
> >
> > It looks like a bug in vim found by the test.
>
> Yup I do have a user called "a" on the machine. This is on linux
> (ubuntu 16.04.4).
>
> The bug don't appear if I comment out the entry for the user "a" in 
> /etc/passwd.
>
> Also I see this weird behavior:
>
> $ sudo vi /etc/passwd
> :e ~a  gives /home/a/ (buggy as expected)
>
> now without closing the file comment out the entry for the "a" user
> and save the file and reattempt the completion
>
> :e ~a nothing suggested, ":e ~a" remains.  I expect it list the
> usernames that starts with "a".
>
> Now undo the changes to the file and quit vim and open it again in vim
> but this time immediately comment out the entry for "a":
>
> $ sudo vi /etc/passwd
> comment out the entry for "a"
>
> :e ~a gives the expected result :e ~avahi avahi-autoipd ayie
>
> nazri

Hi Nazri

The attached patch "fix-user-name-compl-8.1.155.patch"
should fix the bug.  Can you try it?

It's good to see that recently added tests discover bugs.

Thanks!
Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index fec3a8e37..40a349517 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3764,7 +3764,7 @@ set_one_cmd_context(
 	 * A full match ~user will be replaced by user's home
 	 * directory i.e. something like ~user -> /home/user/ */
 	if (*p == NUL && p > xp->xp_pattern + 1
-   && match_user(xp->xp_pattern + 1) == 1)
+   && (match_user(xp->xp_pattern + 1) & 1))
 	{
 		xp->xp_context = EXPAND_USER;
 		++xp->xp_pattern;
diff --git a/src/misc1.c b/src/misc1.c
index 5242ca572..c102636a4 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -4826,22 +4826,23 @@ get_users(expand_T *xp UNUSED, int idx)
  * 0 if name does not match any user name.
  * 1 if name partially matches the beginning of a user name.
  * 2 is name fully matches a user name.
+ * 3 is name fully matches a user name and partially matches another.
  */
 int match_user(char_u* name)
 {
 int i;
 int n = (int)STRLEN(name);
-int result = 0;
+int match = 0;
 
 init_users();
 for (i = 0; i < ga_users.ga_len; i++)
 {
 	if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
-	return 2; /* full match */
-	if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
-	result = 1; /* partial match */
+	match |= 2; /* full match */
+	else if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
+	match |= 1; /* partial match */
 }
-return result;
+return match;
 }
 #endif
 


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Nazri Ramliy
On Fri, Jul 6, 2018 at 8:59 PM, Dominique Pellé
 wrote:
>> Can you try interactively if happens when
>> typing the Ex command   :e ~a
>> where  is a single key for CTRL-A
>>
>> On which OS do you see the issue?
>> Is it reproducible with other user names?
>
> I made an experiment on my machine:
> :e ~p
> gives::e ~pel proxy pulse  (good!)
>
> Then I created a new user "pel2" and did:
> : e ~p  gives  :e ~pel pel2 proxy pulse  (good)
> : e ~pe gives  :e ~pel pel2   (good)
> : e ~pel gives  :e /home/pel/   (does not look right!)
>
> I expected  to get  :e ~pel pel2  in the last case.
>
> In your case, I suspect that you have a user name called "a"
> which is triggering the bug.
>
> It looks like a bug in vim found by the test.

Yup I do have a user called "a" on the machine. This is on linux
(ubuntu 16.04.4).

The bug don't appear if I comment out the entry for the user "a" in /etc/passwd.

Also I see this weird behavior:

$ sudo vi /etc/passwd
:e ~a  gives /home/a/ (buggy as expected)

now without closing the file comment out the entry for the "a" user
and save the file and reattempt the completion

:e ~a nothing suggested, ":e ~a" remains.  I expect it list the
usernames that starts with "a".

Now undo the changes to the file and quit vim and open it again in vim
but this time immediately comment out the entry for "a":

$ sudo vi /etc/passwd
comment out the entry for "a"

:e ~a gives the expected result :e ~avahi avahi-autoipd ayie

nazri

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Dominique Pellé
Dominique Pellé  wrote:

> Nazri Ramliy  wrote:
>
>
> > On Fri, Jul 6, 2018 at 1:42 AM, Dominique Pellé
> >  wrote:
> > >
> > > No, that is not what the test is doing.  The \ expands
> > > all completions.  So I would expect the test to pass if multiple
> > > usernames start with a letter.
> >
> > Ah right, I didn't read the test carefully.
> >
> > > On my machine, typing :e ~p   I get multiple user names:
> > >   :e ~pel proxy pulse
> > >
> > > Could you copy paste the message when the test fails?
> > > The call to assert_match() should print the actual string
> > > vs the expected regexp.
> >
> > Here's the message:
> >
> > From test_cmdline.vim:
> > Found errors in Test_cmdline_complete_user_names():
> > function RunTheTest[40]..Test_cmdline_complete_user_names line 8:
> > Pattern '^"e \\~.*\\' does not match '"e /home/a/'
>
> I don't understand what's happening here.
> It looks like the test is fine but found a bug in
> completion since I would expect  :e ~a
> to show   :e ~ayie  (and possibly other user names
> starting with a if any).
>
> Can you try interactively if happens when
> typing the Ex command   :e ~a
> where  is a single key for CTRL-A
>
> On which OS do you see the issue?
> Is it reproducible with other user names?
>
> Thanks
> Dominique

I made an experiment on my machine:
:e ~p
gives::e ~pel proxy pulse  (good!)

Then I created a new user "pel2" and did:
: e ~p  gives  :e ~pel pel2 proxy pulse  (good)
: e ~pe gives  :e ~pel pel2   (good)
: e ~pel gives  :e /home/pel/   (does not look right!)

I expected  to get  :e ~pel pel2  in the last case.

In your case, I suspect that you have a user name called "a"
which is triggering the bug.

It looks like a bug in vim found by the test.

Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Dominique Pellé
Nazri Ramliy  wrote:


> On Fri, Jul 6, 2018 at 1:42 AM, Dominique Pellé
>  wrote:
> >
> > No, that is not what the test is doing.  The \ expands
> > all completions.  So I would expect the test to pass if multiple
> > usernames start with a letter.
>
> Ah right, I didn't read the test carefully.
>
> > On my machine, typing :e ~p   I get multiple user names:
> >   :e ~pel proxy pulse
> >
> > Could you copy paste the message when the test fails?
> > The call to assert_match() should print the actual string
> > vs the expected regexp.
>
> Here's the message:
>
> From test_cmdline.vim:
> Found errors in Test_cmdline_complete_user_names():
> function RunTheTest[40]..Test_cmdline_complete_user_names line 8:
> Pattern '^"e \\~.*\\' does not match '"e /home/a/'

I don't understand what's happening here.
It looks like the test is fine but found a bug in
completion since I would expect  :e ~a
to show   :e ~ayie  (and possibly other user names
starting with a if any).

Can you try interactively if happens when
typing the Ex command   :e ~a
where  is a single key for CTRL-A

On which OS do you see the issue?
Is it reproducible with other user names?

Thanks
Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-06 Fir de Conversatie Nazri Ramliy
On Fri, Jul 6, 2018 at 1:42 AM, Dominique Pellé
 wrote:
>
> No, that is not what the test is doing.  The \ expands
> all completions.  So I would expect the test to pass if multiple
> usernames start with a letter.

Ah right, I didn't read the test carefully.

> On my machine, typing :e ~p   I get multiple user names:
>   :e ~pel proxy pulse
>
> Could you copy paste the message when the test fails?
> The call to assert_match() should print the actual string
> vs the expected regexp.

Here's the message:

>From test_cmdline.vim:
Found errors in Test_cmdline_complete_user_names():
function RunTheTest[40]..Test_cmdline_complete_user_names line 8:
Pattern '^"e \\~.*\\' does not match '"e /home/a/'

nazri

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test failed: Test_cmdline_complete_user_names()

2018-07-05 Fir de Conversatie Dominique Pellé
Nazri Ramliy  wrote:

> Hi,
>
> The test Test_cmdline_complete_user_names() failed on my machine because it
> assumes that the current username's first letter is unique, which not the case
> on my machine:
>
>   if has('unix') && executable('whoami')
> let whoami = systemlist('whoami')[0]
> let first_letter = whoami[0]
> if len(first_letter) > 0
>   " Trying completion of  :e ~x  where x is the first letter of
>   " the user name should complete to at least the user name.
>   call feedkeys(':e ~' . first_letter . "\\\"\", 'tx')
>   call assert_match('^"e \~.*\<' . whoami . '\>', @:)
> endif
>   endif
>
> If the current username is "foo" and there exist another username "f", then 
> the
> test would fail because "':e ~' . first_letter" would expand to "/home/f"
> instead of what the test expects which is "/home/foo".

No, that is not what the test is doing.  The \ expands
all completions.  So I would expect the test to pass if multiple
usernames start with a letter.

On my machine, typing :e ~p   I get multiple user names:
  :e ~pel proxy pulse

Could you copy paste the message when the test fails?
The call to assert_match() should print the actual string
vs the expected regexp.

Dominique

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Test failed: Test_cmdline_complete_user_names()

2018-07-05 Fir de Conversatie Nazri Ramliy
Hi,

The test Test_cmdline_complete_user_names() failed on my machine because it
assumes that the current username's first letter is unique, which not the case
on my machine:

  if has('unix') && executable('whoami')
let whoami = systemlist('whoami')[0]
let first_letter = whoami[0]
if len(first_letter) > 0
  " Trying completion of  :e ~x  where x is the first letter of
  " the user name should complete to at least the user name.
  call feedkeys(':e ~' . first_letter . "\\\"\", 'tx')
  call assert_match('^"e \~.*\<' . whoami . '\>', @:)
endif
  endif

If the current username is "foo" and there exist another username "f", then the
test would fail because "':e ~' . first_letter" would expand to "/home/f"
instead of what the test expects which is "/home/foo".

Perhaps taking most of the username would be a better approach? Although it can
still fail on a system where there are two usernames where the only difference
between them is the last letter, for example "foo" and "foa".

$ git diff src/testdir/test_cmdline.vim
diff --git src/testdir/test_cmdline.vim src/testdir/test_cmdline.vim
index 26d33d838..5874f72cd 100644
--- src/testdir/test_cmdline.vim
+++ src/testdir/test_cmdline.vim
@@ -394,11 +394,11 @@ endfunc
 func Test_cmdline_complete_user_names()
   if has('unix') && executable('whoami')
 let whoami = systemlist('whoami')[0]
-let first_letter = whoami[0]
-if len(first_letter) > 0
+let a_letter_short = whoami[0:-2]
+if len(a_letter_short) > 0
   " Trying completion of  :e ~x  where x is the first letter of
   " the user name should complete to at least the user name.
-  call feedkeys(':e ~' . first_letter . "\\\"\", 'tx')
+  call feedkeys(':e ~' . a_letter_short . "\\\"\", 'tx')
   call assert_match('^"e \~.*\<' . whoami . '\>', @:)
 endif
   endif

Nazri

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.