git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [GSoC] microporject test_path_is_*
@ 2019-03-26 21:07 Mooga
  2019-03-26 22:06 ` Elijah Newren
  0 siblings, 1 reply; 9+ messages in thread
From: Mooga @ 2019-03-26 21:07 UTC (permalink / raw)
  To: git

Hi, 
I am still a bit confused about the task itself 

it’s just text replacing for example: 
t1400-update-ref.sh , line 194 -> `test_path_is_missing`  has to be ‘test_path_is_file’ 

Thanks



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-26 21:07 [GSoC] microporject test_path_is_* Mooga
@ 2019-03-26 22:06 ` Elijah Newren
  2019-03-27 10:09   ` Ævar Arnfjörð Bjarmason
  2019-03-27 11:28   ` Mooga
  0 siblings, 2 replies; 9+ messages in thread
From: Elijah Newren @ 2019-03-26 22:06 UTC (permalink / raw)
  To: Mooga; +Cc: Git Mailing List

Hi,

On Tue, Mar 26, 2019 at 2:10 PM Mooga <contact@m-mooga.com> wrote:
>
> Hi,
> I am still a bit confused about the task itself
>
> it’s just text replacing for example:
> t1400-update-ref.sh , line 194 -> `test_path_is_missing`  has to be ‘test_path_is_file’
>
> Thanks

There are several places in the code that use test with -e or -f or -d
(or -h or...) in order to check for the presence of a
file/directory/symlink/etc.  For example,
   test -f path1/file1
This could be made more clear and produce nicer error messages if it
were instead
   test_path_is_file path1/file1

There are likewise several that use one of
   ! test -e path/to/filename
or
   ! test -f path/to/filename
or
  test ! -f path/to/filename
which could be replaced by
  test_path_is_missing path/to/filename

This GSoC microproject is just about picking one testfile that has
some of these constructs, and fixing the cases found within that
testfile.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-26 22:06 ` Elijah Newren
@ 2019-03-27 10:09   ` Ævar Arnfjörð Bjarmason
  2019-03-27 10:49     ` SZEDER Gábor
  2019-03-27 11:28   ` Mooga
  1 sibling, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-03-27 10:09 UTC (permalink / raw)
  To: Elijah Newren; +Cc: Mooga, Git Mailing List


On Tue, Mar 26 2019, Elijah Newren wrote:

> Hi,
>
> On Tue, Mar 26, 2019 at 2:10 PM Mooga <contact@m-mooga.com> wrote:
>>
>> Hi,
>> I am still a bit confused about the task itself
>>
>> it’s just text replacing for example:
>> t1400-update-ref.sh , line 194 -> `test_path_is_missing`  has to be ‘test_path_is_file’
>>
>> Thanks
>
> There are several places in the code that use test with -e or -f or -d
> (or -h or...) in order to check for the presence of a
> file/directory/symlink/etc.  For example,
>    test -f path1/file1
> This could be made more clear and produce nicer error messages if it
> were instead
>    test_path_is_file path1/file1

See also the recent thread I started
https://public-inbox.org/git/87sgwav8cp.fsf@evledraar.gmail.com/ asking
if these wrappers were useless now. The consensus was to keep them (a
bunch of use-cases I didn't know about). Useful if you're poking at them
and wondering why we're using this / what it gives us.

> There are likewise several that use one of
>    ! test -e path/to/filename
> or
>    ! test -f path/to/filename
> or
>   test ! -f path/to/filename
> which could be replaced by
>   test_path_is_missing path/to/filename

Interesting that for some we use the 'test_is_there/test_is_not_there'
pattern and for others 'test_is_there [!]'. E.g
test_path_exist/test_path_is_missing v.s. test_i18ngrep.

> This GSoC microproject is just about picking one testfile that has
> some of these constructs, and fixing the cases found within that
> testfile.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-27 10:09   ` Ævar Arnfjörð Bjarmason
@ 2019-03-27 10:49     ` SZEDER Gábor
  2019-03-27 11:21       ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2019-03-27 10:49 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Elijah Newren, Mooga, Git Mailing List

On Wed, Mar 27, 2019 at 11:09:18AM +0100, Ævar Arnfjörð Bjarmason wrote:
> > There are likewise several that use one of
> >    ! test -e path/to/filename
> > or
> >    ! test -f path/to/filename
> > or
> >   test ! -f path/to/filename
> > which could be replaced by
> >   test_path_is_missing path/to/filename
> 
> Interesting that for some we use the 'test_is_there/test_is_not_there'
> pattern and for others 'test_is_there [!]'. E.g
> test_path_exist/test_path_is_missing v.s. test_i18ngrep.

It's unclear what the '!' should negate in case of 'test_path_is_file
! file'.  What if 'file' does exists, but it's not a file but a
directory, socket, fifo, or symlink?  'test ! -f file' returns success
in these cases as well.

OTOH, it's quite clear what the negation should mean in case of
'test_i18ngrep'.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-27 10:49     ` SZEDER Gábor
@ 2019-03-27 11:21       ` Ævar Arnfjörð Bjarmason
  2019-03-27 12:14         ` SZEDER Gábor
  0 siblings, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-03-27 11:21 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Elijah Newren, Mooga, Git Mailing List


On Wed, Mar 27 2019, SZEDER Gábor wrote:

> On Wed, Mar 27, 2019 at 11:09:18AM +0100, Ævar Arnfjörð Bjarmason wrote:
>> > There are likewise several that use one of
>> >    ! test -e path/to/filename
>> > or
>> >    ! test -f path/to/filename
>> > or
>> >   test ! -f path/to/filename
>> > which could be replaced by
>> >   test_path_is_missing path/to/filename
>>
>> Interesting that for some we use the 'test_is_there/test_is_not_there'
>> pattern and for others 'test_is_there [!]'. E.g
>> test_path_exist/test_path_is_missing v.s. test_i18ngrep.
>
> It's unclear what the '!' should negate in case of 'test_path_is_file
> ! file'.  What if 'file' does exists, but it's not a file but a
> directory, socket, fifo, or symlink?  'test ! -f file' returns success
> in these cases as well.
>
> OTOH, it's quite clear what the negation should mean in case of
> 'test_i18ngrep'.

*Should* we make it better? Yeah sure, maybe. I'm just pointing out for
context to someone poking at this for the first time that now we
sometimes do "! foo <arg>" v.s. "foo <arg>" as "foo_is <arg>" and
"foo_not <arg>" and other times "foo [!] <arg>".

So yeah, maybe we should improve things to disambiguate the cases you
mentioned, but right now e.g. "test_path_exists" and
"test_path_is_missing" are just "test -e" and "! test -e", respectively.

The same caveats you've mentioned also apply to "test_i18ngrep" b.t.w.,
there we squash the 3x standard exit codes of grep[1] into a boolean,
and thus e.g. ignore the difference between <file> not matching an
<file> being a directory or whatever.

1. http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-26 22:06 ` Elijah Newren
  2019-03-27 10:09   ` Ævar Arnfjörð Bjarmason
@ 2019-03-27 11:28   ` Mooga
  1 sibling, 0 replies; 9+ messages in thread
From: Mooga @ 2019-03-27 11:28 UTC (permalink / raw)
  To: Elijah Newren; +Cc: git


So for example  that is git diff

diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index 286bba35d8..fc82965a0f 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -66,7 +66,7 @@ test_expect_success '"add" worktree' '
test_expect_success '"add" worktree with lock' '
        git rev-parse HEAD >expect &&
        git worktree add --detach --lock here-with-lock master &&
-       test -f .git/worktrees/here-with-lock/locked
+       test_path_is_file .git/worktrees/here-with-lock/locked



On 26.03.19, 23:07, "Elijah Newren" <git-owner@vger.kernel.org on behalf of newren@gmail.com> wrote:

    Hi,
    
    On Tue, Mar 26, 2019 at 2:10 PM Mooga <contact@m-mooga.com> wrote:
    >
    > Hi,
    > I am still a bit confused about the task itself
    >
    > it’s just text replacing for example:
    > t1400-update-ref.sh , line 194 -> `test_path_is_missing`  has to be ‘test_path_is_file’
    >
    > Thanks
    
    There are several places in the code that use test with -e or -f or -d
    (or -h or...) in order to check for the presence of a
    file/directory/symlink/etc.  For example,
       test -f path1/file1
    This could be made more clear and produce nicer error messages if it
    were instead
       test_path_is_file path1/file1
    
    There are likewise several that use one of
       ! test -e path/to/filename
    or
       ! test -f path/to/filename
    or
      test ! -f path/to/filename
    which could be replaced by
      test_path_is_missing path/to/filename
    
    This GSoC microproject is just about picking one testfile that has
    some of these constructs, and fixing the cases found within that
    testfile.
    



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-27 11:21       ` Ævar Arnfjörð Bjarmason
@ 2019-03-27 12:14         ` SZEDER Gábor
  2019-03-27 14:10           ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2019-03-27 12:14 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Elijah Newren, Mooga, Git Mailing List

On Wed, Mar 27, 2019 at 12:21:55PM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> On Wed, Mar 27 2019, SZEDER Gábor wrote:
> 
> > On Wed, Mar 27, 2019 at 11:09:18AM +0100, Ævar Arnfjörð Bjarmason wrote:
> >> > There are likewise several that use one of
> >> >    ! test -e path/to/filename
> >> > or
> >> >    ! test -f path/to/filename
> >> > or
> >> >   test ! -f path/to/filename
> >> > which could be replaced by
> >> >   test_path_is_missing path/to/filename
> >>
> >> Interesting that for some we use the 'test_is_there/test_is_not_there'
> >> pattern and for others 'test_is_there [!]'. E.g
> >> test_path_exist/test_path_is_missing v.s. test_i18ngrep.
> >
> > It's unclear what the '!' should negate in case of 'test_path_is_file
> > ! file'.  What if 'file' does exists, but it's not a file but a
> > directory, socket, fifo, or symlink?  'test ! -f file' returns success
> > in these cases as well.
> >
> > OTOH, it's quite clear what the negation should mean in case of
> > 'test_i18ngrep'.
> 
> *Should* we make it better? Yeah sure, maybe. I'm just pointing out for
> context to someone poking at this for the first time that now we
> sometimes do "! foo <arg>" v.s. "foo <arg>" as "foo_is <arg>" and
> "foo_not <arg>" and other times "foo [!] <arg>".
> 
> So yeah, maybe we should improve things to disambiguate the cases you
> mentioned, but right now e.g. "test_path_exists" and
> "test_path_is_missing" are just "test -e" and "! test -e", respectively.

I'm not sure why 'test_path_exists' exists, as I don't readily see a
valid reason why a test should only be interested in whether the path
exists, but but not whether it's a file or a directory.  Luckily it
haven't caught on, and it's only used twice in the whole test suite.

However, as shown above, the existend of 'test_path_is_missing' is
very much justified.

> The same caveats you've mentioned also apply to "test_i18ngrep" b.t.w.,
> there we squash the 3x standard exit codes of grep[1] into a boolean,
> and thus e.g. ignore the difference between <file> not matching an
> <file> being a directory or whatever.

I'm not sure I understand, 'test_i18ngrep' handles the missing file or
not a file cases reasonably well:

  expecting success: 
          test_i18ngrep ! foo nonexistent-file
  
  error: bug in the test script: test_i18ngrep requires a file to read as the last parameter

or

  expecting success: 
          mkdir dir &&
          test_i18ngrep ! foo dir
  
  error: bug in the test script: test_i18ngrep requires a file to read as the last parameter


> 
> 1. http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-27 12:14         ` SZEDER Gábor
@ 2019-03-27 14:10           ` Ævar Arnfjörð Bjarmason
  2019-03-28  9:58             ` SZEDER Gábor
  0 siblings, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2019-03-27 14:10 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Elijah Newren, Mooga, Git Mailing List


On Wed, Mar 27 2019, SZEDER Gábor wrote:

> On Wed, Mar 27, 2019 at 12:21:55PM +0100, Ævar Arnfjörð Bjarmason wrote:
>>
>> On Wed, Mar 27 2019, SZEDER Gábor wrote:
>>
>> > On Wed, Mar 27, 2019 at 11:09:18AM +0100, Ævar Arnfjörð Bjarmason wrote:
>> >> > There are likewise several that use one of
>> >> >    ! test -e path/to/filename
>> >> > or
>> >> >    ! test -f path/to/filename
>> >> > or
>> >> >   test ! -f path/to/filename
>> >> > which could be replaced by
>> >> >   test_path_is_missing path/to/filename
>> >>
>> >> Interesting that for some we use the 'test_is_there/test_is_not_there'
>> >> pattern and for others 'test_is_there [!]'. E.g
>> >> test_path_exist/test_path_is_missing v.s. test_i18ngrep.
>> >
>> > It's unclear what the '!' should negate in case of 'test_path_is_file
>> > ! file'.  What if 'file' does exists, but it's not a file but a
>> > directory, socket, fifo, or symlink?  'test ! -f file' returns success
>> > in these cases as well.
>> >
>> > OTOH, it's quite clear what the negation should mean in case of
>> > 'test_i18ngrep'.
>>
>> *Should* we make it better? Yeah sure, maybe. I'm just pointing out for
>> context to someone poking at this for the first time that now we
>> sometimes do "! foo <arg>" v.s. "foo <arg>" as "foo_is <arg>" and
>> "foo_not <arg>" and other times "foo [!] <arg>".
>>
>> So yeah, maybe we should improve things to disambiguate the cases you
>> mentioned, but right now e.g. "test_path_exists" and
>> "test_path_is_missing" are just "test -e" and "! test -e", respectively.
>
> I'm not sure why 'test_path_exists' exists, as I don't readily see a
> valid reason why a test should only be interested in whether the path
> exists, but but not whether it's a file or a directory.

In the general case the same reason we use "test -e". While the test
would pass in all sorts of unexpected cases, those probably aren't
plausible and we're just e.g. checking "did the thing create a file
it'll create in XYZ mode?"....

> Luckily it
> haven't caught on, and it's only used twice in the whole test suite.

Well, we have some >100 "test -e" though ... :)

> However, as shown above, the existend of 'test_path_is_missing' is
> very much justified.
>
>> The same caveats you've mentioned also apply to "test_i18ngrep" b.t.w.,
>> there we squash the 3x standard exit codes of grep[1] into a boolean,
>> and thus e.g. ignore the difference between <file> not matching an
>> <file> being a directory or whatever.
>
> I'm not sure I understand, 'test_i18ngrep' handles the missing file or
> not a file cases reasonably well:
>
>   expecting success:
>           test_i18ngrep ! foo nonexistent-file
>
>   error: bug in the test script: test_i18ngrep requires a file to read as the last parameter
>
> or
>
>   expecting success:
>           mkdir dir &&
>           test_i18ngrep ! foo dir
>
>   error: bug in the test script: test_i18ngrep requires a file to read as the last parameter

Yeah you're right, I didn't read it carefully enough and it does handle
*that* particular case, but e.g. a grep of "file" where we can't read it
due to a permission error is the same as "didn't contain the string".

I'm not saying that's a bad thing, but the opposite. We assume a certain
base level of sanity, e.g. we do "test_must_fail <cmd>" only for git,
but "! <cmd>" for everything else, even though e.g. the system "grep"
may be segfaulting.

>>
>> 1. http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [GSoC] microporject test_path_is_*
  2019-03-27 14:10           ` Ævar Arnfjörð Bjarmason
@ 2019-03-28  9:58             ` SZEDER Gábor
  0 siblings, 0 replies; 9+ messages in thread
From: SZEDER Gábor @ 2019-03-28  9:58 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Elijah Newren, Mooga, Git Mailing List

On Wed, Mar 27, 2019 at 03:10:42PM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> On Wed, Mar 27 2019, SZEDER Gábor wrote:
> 
> > On Wed, Mar 27, 2019 at 12:21:55PM +0100, Ævar Arnfjörð Bjarmason wrote:
> >>
> >> On Wed, Mar 27 2019, SZEDER Gábor wrote:
> >>
> >> > On Wed, Mar 27, 2019 at 11:09:18AM +0100, Ævar Arnfjörð Bjarmason wrote:
> >> >> > There are likewise several that use one of
> >> >> >    ! test -e path/to/filename
> >> >> > or
> >> >> >    ! test -f path/to/filename
> >> >> > or
> >> >> >   test ! -f path/to/filename
> >> >> > which could be replaced by
> >> >> >   test_path_is_missing path/to/filename
> >> >>
> >> >> Interesting that for some we use the 'test_is_there/test_is_not_there'
> >> >> pattern and for others 'test_is_there [!]'. E.g
> >> >> test_path_exist/test_path_is_missing v.s. test_i18ngrep.
> >> >
> >> > It's unclear what the '!' should negate in case of 'test_path_is_file
> >> > ! file'.  What if 'file' does exists, but it's not a file but a
> >> > directory, socket, fifo, or symlink?  'test ! -f file' returns success
> >> > in these cases as well.
> >> >
> >> > OTOH, it's quite clear what the negation should mean in case of
> >> > 'test_i18ngrep'.
> >>
> >> *Should* we make it better? Yeah sure, maybe. I'm just pointing out for
> >> context to someone poking at this for the first time that now we
> >> sometimes do "! foo <arg>" v.s. "foo <arg>" as "foo_is <arg>" and
> >> "foo_not <arg>" and other times "foo [!] <arg>".
> >>
> >> So yeah, maybe we should improve things to disambiguate the cases you
> >> mentioned, but right now e.g. "test_path_exists" and
> >> "test_path_is_missing" are just "test -e" and "! test -e", respectively.
> >
> > I'm not sure why 'test_path_exists' exists, as I don't readily see a
> > valid reason why a test should only be interested in whether the path
> > exists, but but not whether it's a file or a directory.
> 
> In the general case the same reason we use "test -e". While the test
> would pass in all sorts of unexpected cases, those probably aren't
> plausible and we're just e.g. checking "did the thing create a file
> it'll create in XYZ mode?"....

When I look at a test using 'test -e' I can't readily tell what that
reason might have been, i.e. whether there really was a compelling
reason for using 'test -e' instead of 'test -(f|d|...), or the dev
writing the test was just "meh, we could let it slide".

> > Luckily it
> > haven't caught on, and it's only used twice in the whole test suite.
> 
> Well, we have some >100 "test -e" though ... :)

Hopefully they will be turned into 'test_path_is_file' or
'test_path_is_dir' instead of 'test_path_exists'...  eventually, maybe
a decade or two worth of GSOC microprojects later... :)

> > However, as shown above, the existend of 'test_path_is_missing' is
> > very much justified.
> >
> >> The same caveats you've mentioned also apply to "test_i18ngrep" b.t.w.,
> >> there we squash the 3x standard exit codes of grep[1] into a boolean,
> >> and thus e.g. ignore the difference between <file> not matching an
> >> <file> being a directory or whatever.
> >
> > I'm not sure I understand, 'test_i18ngrep' handles the missing file or
> > not a file cases reasonably well:
> >
> >   expecting success:
> >           test_i18ngrep ! foo nonexistent-file
> >
> >   error: bug in the test script: test_i18ngrep requires a file to read as the last parameter
> >
> > or
> >
> >   expecting success:
> >           mkdir dir &&
> >           test_i18ngrep ! foo dir
> >
> >   error: bug in the test script: test_i18ngrep requires a file to read as the last parameter
> 
> Yeah you're right, I didn't read it carefully enough and it does handle
> *that* particular case, but e.g. a grep of "file" where we can't read it
> due to a permission error is the same as "didn't contain the string".
> 
> I'm not saying that's a bad thing, but the opposite. We assume a certain
> base level of sanity, e.g. we do "test_must_fail <cmd>" only for git,
> but "! <cmd>" for everything else, even though e.g. the system "grep"
> may be segfaulting.

That's kind of the point: this is not about the sanity of the system,
but rather about the sanity of the developers :)

'test_i18ngrep' does handle that particular case, because,
unfortunately, paths do get misspelled (or downright forgotten!) every
now and then, but 'test_expect_failure', '! cmd', a pipe downstream,
or some other circumstances can still hide those errors.  I fixed
several issues with bogus filenames in the past.

However, since we assume that the system we are testing on is sane,
there is indeed not much point in preparing for cases that could only
go wrong if the system was not sane, e.g. the lack of permissions to
read a just written file.  I don't recall that we had any such
permission-related issues in the past (but I didn't actually check).
Having said that, I agree that checking whether 'grep' exited with 2
would have been more robust.


And these are the cases where using test helper functions that know
about the negation like 'test_path_is_missing', 'test_must_be_empty',
or 'test_i18ngrep !' instead of '! test -(f|d|s|...)' etc. starts to
pay off, as they can protect us from our own mistakes.  Case in point:
the last remaining '! test -s' in our test suite is definitely wrong.

So I think if such a helper function is available, then we should use
it, and we might want to consider adding even more, e.g. we have a
couple of instances of '! test_cmp', '! has_cr'.  And these functions
don't have to be perfect and catch every case that could possibly go
wrong, they just need to do a reasonably good job at catching those
cases that would be our own fault if they were to go wrong.


> >> 1. http://pubs.opengroup.org/onlinepubs/009695399/utilities/grep.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-03-28  9:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-26 21:07 [GSoC] microporject test_path_is_* Mooga
2019-03-26 22:06 ` Elijah Newren
2019-03-27 10:09   ` Ævar Arnfjörð Bjarmason
2019-03-27 10:49     ` SZEDER Gábor
2019-03-27 11:21       ` Ævar Arnfjörð Bjarmason
2019-03-27 12:14         ` SZEDER Gábor
2019-03-27 14:10           ` Ævar Arnfjörð Bjarmason
2019-03-28  9:58             ` SZEDER Gábor
2019-03-27 11:28   ` Mooga

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).